panfrost: Prepare attribute for builtins at state creation time
authorBoris Brezillon <boris.brezillon@collabora.com>
Thu, 5 Mar 2020 18:40:15 +0000 (19:40 +0100)
committerBoris Brezillon <boris.brezillon@collabora.com>
Tue, 10 Mar 2020 11:47:34 +0000 (12:47 +0100)
The attribute meta slots reserved for gl_VertexID and gl_InstanceID
can be pre-filled at state creation time. Only the index needs to be
adjusted when attributes are generated.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4083>

src/gallium/drivers/panfrost/pan_attributes.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h

index ada95d181c7d2eeb4354e451426c598c102599d1..31bdd2c16f36a10e028b6b9687021f55d7390957 100644 (file)
@@ -118,8 +118,9 @@ panfrost_emit_vertex_data(struct panfrost_batch *batch)
         /* Add special gl_VertexID/gl_InstanceID buffers */
 
         panfrost_vertex_id(ctx->padded_count, &attrs[k]);
-        so->vertexid_index = k++;
-        panfrost_instance_id(ctx->padded_count, &attrs[k++]);
+        so->hw[PAN_VERTEX_ID].index = k++;
+        panfrost_instance_id(ctx->padded_count, &attrs[k]);
+        so->hw[PAN_INSTANCE_ID].index = k++;
 
         /* Upload whatever we emitted and go */
 
index fda7b3fcb3d9f605ae8a97657c5e1e6bab77c9e7..4fea5f507b35aa1d8ff439229f767d09f8635f29 100644 (file)
@@ -244,21 +244,6 @@ panfrost_stage_attributes(struct panfrost_context *ctx)
                 target[i].src_offset = src_offset;
         }
 
-        /* Let's also include vertex builtins */
-
-        struct mali_attr_meta builtin = {
-                .format = MALI_R32UI,
-                .swizzle = panfrost_get_default_swizzle(1)
-        };
-
-        /* See mali_attr_meta specification for the magic number */
-
-        builtin.index = so->vertexid_index;
-        memcpy(&target[PAN_VERTEX_ID], &builtin, 4);
-
-        builtin.index = so->vertexid_index + 1;
-        memcpy(&target[PAN_INSTANCE_ID], &builtin, 4);
-
         ctx->payloads[PIPE_SHADER_VERTEX].postfix.attribute_meta = transfer.gpu;
 }
 
@@ -724,6 +709,12 @@ panfrost_create_vertex_elements_state(
                 so->hw[i].format = panfrost_find_format(desc);
         }
 
+        /* Let's also prepare vertex builtins */
+        so->hw[PAN_VERTEX_ID].format = MALI_R32UI;
+        so->hw[PAN_VERTEX_ID].swizzle = panfrost_get_default_swizzle(1);
+        so->hw[PAN_INSTANCE_ID].format = MALI_R32UI;
+        so->hw[PAN_INSTANCE_ID].swizzle = panfrost_get_default_swizzle(1);
+
         return so;
 }
 
index b73883df3227da728e08ad7135659d2ffb01e8f1..9c26b012493dc446064786bfd50628d39e1b666b 100644 (file)
@@ -244,7 +244,6 @@ struct panfrost_shader_variants {
 
 struct panfrost_vertex_state {
         unsigned num_elements;
-        unsigned vertexid_index;
 
         struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
         struct mali_attr_meta hw[PIPE_MAX_ATTRIBS];