#include "compiler/builtin_type_macros.h"
/** @} */
-static void
-get_struct_type_field_and_pointer_sizes(size_t *s_field_size,
- size_t *s_field_ptrs)
-{
- *s_field_size = sizeof(glsl_struct_field);
- *s_field_ptrs =
- sizeof(((glsl_struct_field *)0)->type) +
- sizeof(((glsl_struct_field *)0)->name);
-}
-
union packed_type {
uint32_t u32;
struct {
} strct;
};
+static void
+encode_glsl_struct_field(blob *blob, const glsl_struct_field *struct_field)
+{
+ encode_type_to_blob(blob, struct_field->type);
+ blob_write_string(blob, struct_field->name);
+ blob_write_uint32(blob, struct_field->location);
+ blob_write_uint32(blob, struct_field->offset);
+ blob_write_uint32(blob, struct_field->xfb_buffer);
+ blob_write_uint32(blob, struct_field->xfb_stride);
+ blob_write_uint32(blob, struct_field->image_format);
+ blob_write_uint32(blob, struct_field->flags);
+}
+
+static void
+decode_glsl_struct_field_from_blob(blob_reader *blob, glsl_struct_field *struct_field)
+{
+ struct_field->type = decode_type_from_blob(blob);
+ struct_field->name = blob_read_string(blob);
+ struct_field->location = blob_read_uint32(blob);
+ struct_field->offset = blob_read_uint32(blob);
+ struct_field->xfb_buffer = blob_read_uint32(blob);
+ struct_field->xfb_stride = blob_read_uint32(blob);
+ struct_field->image_format = (pipe_format)blob_read_uint32(blob);
+ struct_field->flags = blob_read_uint32(blob);
+}
+
void
encode_type_to_blob(struct blob *blob, const glsl_type *type)
{
if (encoded.strct.length == 0xffffff)
blob_write_uint32(blob, type->length);
- size_t s_field_size, s_field_ptrs;
- get_struct_type_field_and_pointer_sizes(&s_field_size, &s_field_ptrs);
-
- for (unsigned i = 0; i < type->length; i++) {
- encode_type_to_blob(blob, type->fields.structure[i].type);
- blob_write_string(blob, type->fields.structure[i].name);
-
- /* Write the struct field skipping the pointers */
- blob_write_bytes(blob,
- ((char *)&type->fields.structure[i]) + s_field_ptrs,
- s_field_size - s_field_ptrs);
- }
+ for (unsigned i = 0; i < type->length; i++)
+ encode_glsl_struct_field(blob, &type->fields.structure[i]);
return;
case GLSL_TYPE_VOID:
break;
if (num_fields == 0xffffff)
num_fields = blob_read_uint32(blob);
- size_t s_field_size, s_field_ptrs;
- get_struct_type_field_and_pointer_sizes(&s_field_size, &s_field_ptrs);
-
glsl_struct_field *fields =
- (glsl_struct_field *) malloc(s_field_size * num_fields);
- for (unsigned i = 0; i < num_fields; i++) {
- fields[i].type = decode_type_from_blob(blob);
- fields[i].name = blob_read_string(blob);
-
- blob_copy_bytes(blob, ((uint8_t *) &fields[i]) + s_field_ptrs,
- s_field_size - s_field_ptrs);
- }
+ (glsl_struct_field *) malloc(sizeof(glsl_struct_field) * num_fields);
+ for (unsigned i = 0; i < num_fields; i++)
+ decode_glsl_struct_field_from_blob(blob, &fields[i]);
const glsl_type *t;
if (base_type == GLSL_TYPE_INTERFACE) {
* -1 otherwise.
*/
int xfb_stride;
-
- /**
- * For interface blocks, the interpolation mode (as in
- * ir_variable::interpolation). 0 otherwise.
- */
- unsigned interpolation:3;
-
- /**
- * For interface blocks, 1 if this variable uses centroid interpolation (as
- * in ir_variable::centroid). 0 otherwise.
- */
- unsigned centroid:1;
-
- /**
- * For interface blocks, 1 if this variable uses sample interpolation (as
- * in ir_variable::sample). 0 otherwise.
- */
- unsigned sample:1;
-
- /**
- * Layout of the matrix. Uses glsl_matrix_layout values.
- */
- unsigned matrix_layout:2;
-
- /**
- * For interface blocks, 1 if this variable is a per-patch input or output
- * (as in ir_variable::patch). 0 otherwise.
- */
- unsigned patch:1;
-
- /**
- * Precision qualifier
- */
- unsigned precision:2;
-
- /**
- * Memory qualifiers, applicable to buffer variables defined in shader
- * storage buffer objects (SSBOs)
- */
- unsigned memory_read_only:1;
- unsigned memory_write_only:1;
- unsigned memory_coherent:1;
- unsigned memory_volatile:1;
- unsigned memory_restrict:1;
-
/**
* Layout format, applicable to image variables only.
*/
enum pipe_format image_format;
- /**
- * Any of the xfb_* qualifiers trigger the shader to be in transform
- * feedback mode so we need to keep track of whether the buffer was
- * explicitly set or if its just been assigned the default global value.
- */
- unsigned explicit_xfb_buffer:1;
-
- unsigned implicit_sized_array:1;
+ union {
+ struct {
+ /**
+ * For interface blocks, the interpolation mode (as in
+ * ir_variable::interpolation). 0 otherwise.
+ */
+ unsigned interpolation:3;
+
+ /**
+ * For interface blocks, 1 if this variable uses centroid interpolation (as
+ * in ir_variable::centroid). 0 otherwise.
+ */
+ unsigned centroid:1;
+
+ /**
+ * For interface blocks, 1 if this variable uses sample interpolation (as
+ * in ir_variable::sample). 0 otherwise.
+ */
+ unsigned sample:1;
+
+ /**
+ * Layout of the matrix. Uses glsl_matrix_layout values.
+ */
+ unsigned matrix_layout:2;
+
+ /**
+ * For interface blocks, 1 if this variable is a per-patch input or output
+ * (as in ir_variable::patch). 0 otherwise.
+ */
+ unsigned patch:1;
+
+ /**
+ * Precision qualifier
+ */
+ unsigned precision:2;
+
+ /**
+ * Memory qualifiers, applicable to buffer variables defined in shader
+ * storage buffer objects (SSBOs)
+ */
+ unsigned memory_read_only:1;
+ unsigned memory_write_only:1;
+ unsigned memory_coherent:1;
+ unsigned memory_volatile:1;
+ unsigned memory_restrict:1;
+
+ /**
+ * Any of the xfb_* qualifiers trigger the shader to be in transform
+ * feedback mode so we need to keep track of whether the buffer was
+ * explicitly set or if its just been assigned the default global value.
+ */
+ unsigned explicit_xfb_buffer:1;
+
+ unsigned implicit_sized_array:1;
+ };
+ unsigned flags;
+ };
#ifdef __cplusplus
-#define DEFAULT_CONSTRUCTORS(_type, _precision, _name) \
+#define DEFAULT_CONSTRUCTORS(_type, _name) \
type(_type), name(_name), location(-1), offset(-1), xfb_buffer(0), \
- xfb_stride(0), interpolation(0), centroid(0), \
- sample(0), matrix_layout(GLSL_MATRIX_LAYOUT_INHERITED), patch(0), \
- precision(_precision), memory_read_only(0), \
- memory_write_only(0), memory_coherent(0), memory_volatile(0), \
- memory_restrict(0), image_format(PIPE_FORMAT_NONE), \
- explicit_xfb_buffer(0), \
- implicit_sized_array(0)
+ xfb_stride(0), image_format(PIPE_FORMAT_NONE), flags(0) \
glsl_struct_field(const struct glsl_type *_type,
int _precision,
const char *_name)
- : DEFAULT_CONSTRUCTORS(_type, _precision, _name)
+ : DEFAULT_CONSTRUCTORS(_type, _name)
{
- /* empty */
+ matrix_layout = GLSL_MATRIX_LAYOUT_INHERITED;
+ precision = _precision;
}
glsl_struct_field(const struct glsl_type *_type, const char *_name)
- : DEFAULT_CONSTRUCTORS(_type, GLSL_PRECISION_NONE, _name)
+ : DEFAULT_CONSTRUCTORS(_type, _name)
{
- /* empty */
+ matrix_layout = GLSL_MATRIX_LAYOUT_INHERITED;
+ precision = GLSL_PRECISION_NONE;
}
glsl_struct_field()
- : DEFAULT_CONSTRUCTORS(NULL, GLSL_PRECISION_NONE, NULL)
+ : DEFAULT_CONSTRUCTORS(NULL, NULL)
{
- /* empty */
+ matrix_layout = GLSL_MATRIX_LAYOUT_INHERITED;
+ precision = GLSL_PRECISION_NONE;
}
#undef DEFAULT_CONSTRUCTORS
#endif