diff options
author | Mathias Fröhlich <[email protected]> | 2018-11-17 07:13:11 +0100 |
---|---|---|
committer | Mathias Fröhlich <[email protected]> | 2018-11-21 06:27:19 +0100 |
commit | 0a7020b4e60ef69e0e4b38aee31bfce385e594d8 (patch) | |
tree | 64e68add5e2e22579c6ef715707c1dd99c1ecde1 /src/mesa/drivers | |
parent | 2da7b0a2fbf0dbc5e89f19622cf3bbfa346ed0f1 (diff) |
mesa: Factor out struct gl_vertex_format.
Factor out struct gl_vertex_format from array attributes.
The data type is supposed to describe the type of a vertex
element. At this current stage the data type is only used
with the VAO, but actually is useful in various other places.
Due to the bitfields being used, special care needs to be
taken for the glGet code paths.
v2: Change unsigned char -> GLubyte.
Use struct assignment for struct gl_vertex_format.
Reviewed-by: Brian Paul <[email protected]>
Reviewed-by: Marek Olšák <[email protected]>
Signed-off-by: Mathias Fröhlich <[email protected]>
Diffstat (limited to 'src/mesa/drivers')
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_context.h | 2 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_draw.c | 14 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_draw_upload.c | 60 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/genX_state_upload.c | 14 | ||||
-rw-r--r-- | src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c | 10 |
5 files changed, 51 insertions, 49 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h index 7fd15669eb9..e5d57dd8df1 100644 --- a/src/mesa/drivers/dri/i965/brw_context.h +++ b/src/mesa/drivers/dri/i965/brw_context.h @@ -1493,7 +1493,7 @@ gl_clip_plane *brw_select_clip_planes(struct gl_context *ctx); /* brw_draw_upload.c */ unsigned brw_get_vertex_surface_type(struct brw_context *brw, - const struct gl_array_attributes *glattr); + const struct gl_vertex_format *glformat); static inline unsigned brw_get_index_type(unsigned index_size) diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c index 19ee3962d74..b818a0d77a3 100644 --- a/src/mesa/drivers/dri/i965/brw_draw.c +++ b/src/mesa/drivers/dri/i965/brw_draw.c @@ -303,16 +303,16 @@ brw_merge_inputs(struct brw_context *brw) * 2_10_10_10_REV vertex formats. Set appropriate workaround flags. */ while (mask) { - const struct gl_array_attributes *glattrib; + const struct gl_vertex_format *glformat; uint8_t wa_flags = 0; i = u_bit_scan64(&mask); - glattrib = brw->vb.inputs[i].glattrib; + glformat = &brw->vb.inputs[i].glattrib->Format; - switch (glattrib->Type) { + switch (glformat->Type) { case GL_FIXED: - wa_flags = glattrib->Size; + wa_flags = glformat->Size; break; case GL_INT_2_10_10_10_REV: @@ -320,12 +320,12 @@ brw_merge_inputs(struct brw_context *brw) /* fallthough */ case GL_UNSIGNED_INT_2_10_10_10_REV: - if (glattrib->Format == GL_BGRA) + if (glformat->Format == GL_BGRA) wa_flags |= BRW_ATTRIB_WA_BGRA; - if (glattrib->Normalized) + if (glformat->Normalized) wa_flags |= BRW_ATTRIB_WA_NORMALIZE; - else if (!glattrib->Integer) + else if (!glformat->Integer) wa_flags |= BRW_ATTRIB_WA_SCALE; break; diff --git a/src/mesa/drivers/dri/i965/brw_draw_upload.c b/src/mesa/drivers/dri/i965/brw_draw_upload.c index dc3022bc417..dfbc45fe938 100644 --- a/src/mesa/drivers/dri/i965/brw_draw_upload.c +++ b/src/mesa/drivers/dri/i965/brw_draw_upload.c @@ -249,21 +249,21 @@ double_types(int size, GLboolean doubles) */ unsigned brw_get_vertex_surface_type(struct brw_context *brw, - const struct gl_array_attributes *glattrib) + const struct gl_vertex_format *glformat) { - int size = glattrib->Size; + int size = glformat->Size; const struct gen_device_info *devinfo = &brw->screen->devinfo; const bool is_ivybridge_or_older = devinfo->gen <= 7 && !devinfo->is_baytrail && !devinfo->is_haswell; if (unlikely(INTEL_DEBUG & DEBUG_VERTS)) fprintf(stderr, "type %s size %d normalized %d\n", - _mesa_enum_to_string(glattrib->Type), - glattrib->Size, glattrib->Normalized); + _mesa_enum_to_string(glformat->Type), + glformat->Size, glformat->Normalized); - if (glattrib->Integer) { - assert(glattrib->Format == GL_RGBA); /* sanity check */ - switch (glattrib->Type) { + if (glformat->Integer) { + assert(glformat->Format == GL_RGBA); /* sanity check */ + switch (glformat->Type) { case GL_INT: return int_types_direct[size]; case GL_SHORT: if (is_ivybridge_or_older && size == 3) @@ -288,11 +288,11 @@ brw_get_vertex_surface_type(struct brw_context *brw, return ubyte_types_direct[size]; default: unreachable("not reached"); } - } else if (glattrib->Type == GL_UNSIGNED_INT_10F_11F_11F_REV) { + } else if (glformat->Type == GL_UNSIGNED_INT_10F_11F_11F_REV) { return ISL_FORMAT_R11G11B10_FLOAT; - } else if (glattrib->Normalized) { - switch (glattrib->Type) { - case GL_DOUBLE: return double_types(size, glattrib->Doubles); + } else if (glformat->Normalized) { + switch (glformat->Type) { + case GL_DOUBLE: return double_types(size, glformat->Doubles); case GL_FLOAT: return float_types[size]; case GL_HALF_FLOAT: case GL_HALF_FLOAT_OES: @@ -306,7 +306,7 @@ brw_get_vertex_surface_type(struct brw_context *brw, case GL_UNSIGNED_INT: return uint_types_norm[size]; case GL_UNSIGNED_SHORT: return ushort_types_norm[size]; case GL_UNSIGNED_BYTE: - if (glattrib->Format == GL_BGRA) { + if (glformat->Format == GL_BGRA) { /* See GL_EXT_vertex_array_bgra */ assert(size == 4); return ISL_FORMAT_B8G8R8A8_UNORM; @@ -330,7 +330,7 @@ brw_get_vertex_surface_type(struct brw_context *brw, case GL_INT_2_10_10_10_REV: assert(size == 4); if (devinfo->gen >= 8 || devinfo->is_haswell) { - return glattrib->Format == GL_BGRA + return glformat->Format == GL_BGRA ? ISL_FORMAT_B10G10R10A2_SNORM : ISL_FORMAT_R10G10B10A2_SNORM; } @@ -338,7 +338,7 @@ brw_get_vertex_surface_type(struct brw_context *brw, case GL_UNSIGNED_INT_2_10_10_10_REV: assert(size == 4); if (devinfo->gen >= 8 || devinfo->is_haswell) { - return glattrib->Format == GL_BGRA + return glformat->Format == GL_BGRA ? ISL_FORMAT_B10G10R10A2_UNORM : ISL_FORMAT_R10G10B10A2_UNORM; } @@ -352,26 +352,26 @@ brw_get_vertex_surface_type(struct brw_context *brw, * like to use here, so upload everything as UINT and fix * it in the shader */ - if (glattrib->Type == GL_INT_2_10_10_10_REV) { + if (glformat->Type == GL_INT_2_10_10_10_REV) { assert(size == 4); if (devinfo->gen >= 8 || devinfo->is_haswell) { - return glattrib->Format == GL_BGRA + return glformat->Format == GL_BGRA ? ISL_FORMAT_B10G10R10A2_SSCALED : ISL_FORMAT_R10G10B10A2_SSCALED; } return ISL_FORMAT_R10G10B10A2_UINT; - } else if (glattrib->Type == GL_UNSIGNED_INT_2_10_10_10_REV) { + } else if (glformat->Type == GL_UNSIGNED_INT_2_10_10_10_REV) { assert(size == 4); if (devinfo->gen >= 8 || devinfo->is_haswell) { - return glattrib->Format == GL_BGRA + return glformat->Format == GL_BGRA ? ISL_FORMAT_B10G10R10A2_USCALED : ISL_FORMAT_R10G10B10A2_USCALED; } return ISL_FORMAT_R10G10B10A2_UINT; } - assert(glattrib->Format == GL_RGBA); /* sanity check */ - switch (glattrib->Type) { - case GL_DOUBLE: return double_types(size, glattrib->Doubles); + assert(glformat->Format == GL_RGBA); /* sanity check */ + switch (glformat->Type) { + case GL_DOUBLE: return double_types(size, glformat->Doubles); case GL_FLOAT: return float_types[size]; case GL_HALF_FLOAT: case GL_HALF_FLOAT_OES: @@ -407,6 +407,7 @@ copy_array_to_vbo_array(struct brw_context *brw, { const struct gl_vertex_buffer_binding *glbinding = element->glbinding; const struct gl_array_attributes *glattrib = element->glattrib; + const struct gl_vertex_format *glformat = &glattrib->Format; const int src_stride = glbinding->Stride; /* If the source stride is zero, we just want to upload the current @@ -414,11 +415,11 @@ copy_array_to_vbo_array(struct brw_context *brw, * to replicate it out. */ if (src_stride == 0) { - brw_upload_data(&brw->upload, glattrib->Ptr, glattrib->_ElementSize, - glattrib->_ElementSize, &buffer->bo, &buffer->offset); + brw_upload_data(&brw->upload, glattrib->Ptr, glformat->_ElementSize, + glformat->_ElementSize, &buffer->bo, &buffer->offset); buffer->stride = 0; - buffer->size = glattrib->_ElementSize; + buffer->size = glformat->_ElementSize; return; } @@ -531,13 +532,13 @@ brw_prepare_vertices(struct brw_context *brw) start = offset + glbinding->Stride * brw->baseinstance; range = (glbinding->Stride * ((brw->num_instances - 1) / glbinding->InstanceDivisor) + - glattrib->_ElementSize); + glattrib->Format._ElementSize); } } else { if (brw->vb.index_bounds_valid) { start = offset + min_index * glbinding->Stride; range = (glbinding->Stride * (max_index - min_index) + - glattrib->_ElementSize); + glattrib->Format._ElementSize); } } @@ -594,7 +595,8 @@ brw_prepare_vertices(struct brw_context *brw) else if (interleaved != glbinding->Stride || glbinding->InstanceDivisor != 0 || glattrib->Ptr < ptr || - (uintptr_t)(glattrib->Ptr - ptr) + glattrib->_ElementSize > interleaved) + (uintptr_t)(glattrib->Ptr - ptr) + + glattrib->Format._ElementSize > interleaved) { /* If our stride is different from the first attribute's stride, * or if we are using an instance divisor or if the first @@ -677,7 +679,7 @@ brw_prepare_vertices(struct brw_context *brw) const struct gl_array_attributes *glattrib = upload[i]->glattrib; if (glbinding->InstanceDivisor == 0) { copy_array_to_vbo_array(brw, upload[i], min_index, max_index, - buffer, glattrib->_ElementSize); + buffer, glattrib->Format._ElementSize); } else { /* This is an instanced attribute, since its InstanceDivisor * is not zero. Therefore, its data will be stepped after the @@ -686,7 +688,7 @@ brw_prepare_vertices(struct brw_context *brw) uint32_t instanced_attr_max_index = (brw->num_instances - 1) / glbinding->InstanceDivisor; copy_array_to_vbo_array(brw, upload[i], 0, instanced_attr_max_index, - buffer, glattrib->_ElementSize); + buffer, glattrib->Format._ElementSize); } buffer->offset -= delta * buffer->stride; buffer->size += delta * buffer->stride; diff --git a/src/mesa/drivers/dri/i965/genX_state_upload.c b/src/mesa/drivers/dri/i965/genX_state_upload.c index 5acd0922922..8e3fcbf12ec 100644 --- a/src/mesa/drivers/dri/i965/genX_state_upload.c +++ b/src/mesa/drivers/dri/i965/genX_state_upload.c @@ -620,7 +620,7 @@ genX(emit_vertices)(struct brw_context *brw) for (unsigned i = 0; i < brw->vb.nr_enabled; i++) { struct brw_vertex_element *input = brw->vb.enabled[i]; const struct gl_array_attributes *glattrib = input->glattrib; - uint32_t format = brw_get_vertex_surface_type(brw, glattrib); + uint32_t format = brw_get_vertex_surface_type(brw, &glattrib->Format); if (uploads_needed(format, input->is_dual_slot) > 1) nr_elements++; @@ -713,7 +713,7 @@ genX(emit_vertices)(struct brw_context *brw) for (i = 0; i < brw->vb.nr_enabled; i++) { const struct brw_vertex_element *input = brw->vb.enabled[i]; const struct gl_array_attributes *glattrib = input->glattrib; - uint32_t format = brw_get_vertex_surface_type(brw, glattrib); + uint32_t format = brw_get_vertex_surface_type(brw, &glattrib->Format); uint32_t comp0 = VFCOMP_STORE_SRC; uint32_t comp1 = VFCOMP_STORE_SRC; uint32_t comp2 = VFCOMP_STORE_SRC; @@ -756,16 +756,16 @@ genX(emit_vertices)(struct brw_context *brw) const struct gl_array_attributes *glattrib = input->glattrib; const int size = (GEN_GEN < 8 && is_passthru_format(format)) ? - upload_format_size(upload_format) : glattrib->Size; + upload_format_size(upload_format) : glattrib->Format.Size; switch (size) { case 0: comp0 = VFCOMP_STORE_0; case 1: comp1 = VFCOMP_STORE_0; case 2: comp2 = VFCOMP_STORE_0; case 3: - if (GEN_GEN >= 8 && glattrib->Doubles) { + if (GEN_GEN >= 8 && glattrib->Format.Doubles) { comp3 = VFCOMP_STORE_0; - } else if (glattrib->Integer) { + } else if (glattrib->Format.Integer) { comp3 = VFCOMP_STORE_1_INT; } else { comp3 = VFCOMP_STORE_1_FP; @@ -790,7 +790,7 @@ genX(emit_vertices)(struct brw_context *brw) * to be specified as VFCOMP_STORE_0 in order to output a 256-bit * vertex element." */ - if (glattrib->Doubles && !input->is_dual_slot) { + if (glattrib->Format.Doubles && !input->is_dual_slot) { /* Store vertex elements which correspond to double and dvec2 vertex * shader inputs as 128-bit vertex elements, instead of 256-bits. */ @@ -877,7 +877,7 @@ genX(emit_vertices)(struct brw_context *brw) #if GEN_GEN >= 6 if (gen6_edgeflag_input) { const struct gl_array_attributes *glattrib = gen6_edgeflag_input->glattrib; - const uint32_t format = brw_get_vertex_surface_type(brw, glattrib); + const uint32_t format = brw_get_vertex_surface_type(brw, &glattrib->Format); struct GENX(VERTEX_ELEMENT_STATE) elem_state = { .Valid = true, diff --git a/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c b/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c index 97ff07808b9..f037bd2015d 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c @@ -49,7 +49,7 @@ get_array_stride(struct gl_context *ctx, const struct tnl_vertex_array *a) if (render->mode == VBO && !_mesa_is_bufferobj(binding->BufferObj)) { const struct gl_array_attributes *attrib = a->VertexAttrib; /* Pack client buffers. */ - return align(attrib->_ElementSize, 4); + return align(attrib->Format._ElementSize, 4); } else { return binding->Stride; } @@ -86,7 +86,7 @@ vbo_init_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib, nouveau_init_array(&render->attrs[attr], attr, get_array_stride(ctx, array), - attrib->Size, attrib->Type, + attrib->Format.Size, attrib->Format.Type, imm ? binding->BufferObj : NULL, p, imm, ctx); } @@ -154,8 +154,8 @@ vbo_emit_attr(struct gl_context *ctx, const struct tnl_vertex_array *arrays, return; /* Constant attribute. */ - nouveau_init_array(a, attr, binding->Stride, attrib->Size, - attrib->Type, binding->BufferObj, p, + nouveau_init_array(a, attr, binding->Stride, attrib->Format.Size, + attrib->Format.Type, binding->BufferObj, p, GL_TRUE, ctx); EMIT_IMM(ctx, a, 0); nouveau_deinit_array(a); @@ -166,7 +166,7 @@ vbo_emit_attr(struct gl_context *ctx, const struct tnl_vertex_array *arrays, if (render->mode == VBO) { render->map[info->vbo_index] = attr; - render->vertex_size += attrib->_ElementSize; + render->vertex_size += attrib->Format._ElementSize; render->attr_count = MAX2(render->attr_count, info->vbo_index + 1); } else { |