v3d/compiler: add v3dv_prog_data_size helper
authorAlejandro Piñeiro <apinheiro@igalia.com>
Sat, 25 Jul 2020 22:52:17 +0000 (00:52 +0200)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Wed, 19 Aug 2020 20:50:21 +0000 (22:50 +0200)
Main use case is to help to implement Vulkan PipelineCache, as we are
serializing/deserializing the prog_data too.

Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6078>

src/broadcom/compiler/v3d_compiler.h
src/broadcom/compiler/vir.c

index 154b059856b55c17772b8cfbca95382a0367a188..0026dd2fef34d847fabfacb15937bb06425e4312 100644 (file)
@@ -808,6 +808,7 @@ uint64_t *v3d_compile(const struct v3d_compiler *compiler,
                       int program_id, int variant_id,
                       uint32_t *final_assembly_size);
 
+uint32_t v3d_prog_data_size(gl_shader_stage stage);
 void v3d_nir_to_vir(struct v3d_compile *c);
 
 void vir_compile_destroy(struct v3d_compile *c);
index d7e9784a10aaf28c1bac037592ba37aac0a1efbc..d81931ec27bb127c0060a22408481cebd77a2b1c 100644 (file)
@@ -1146,6 +1146,23 @@ v3d_attempt_compile(struct v3d_compile *c)
         v3d_nir_to_vir(c);
 }
 
+uint32_t
+v3d_prog_data_size(gl_shader_stage stage)
+{
+        static const int prog_data_size[] = {
+                [MESA_SHADER_VERTEX] = sizeof(struct v3d_vs_prog_data),
+                [MESA_SHADER_GEOMETRY] = sizeof(struct v3d_gs_prog_data),
+                [MESA_SHADER_FRAGMENT] = sizeof(struct v3d_fs_prog_data),
+                [MESA_SHADER_COMPUTE] = sizeof(struct v3d_compute_prog_data),
+        };
+
+        assert(stage >= 0 &&
+               stage < ARRAY_SIZE(prog_data_size) &&
+               prog_data_size[stage]);
+
+        return prog_data_size[stage];
+}
+
 uint64_t *v3d_compile(const struct v3d_compiler *compiler,
                       struct v3d_key *key,
                       struct v3d_prog_data **out_prog_data,
@@ -1189,18 +1206,7 @@ uint64_t *v3d_compile(const struct v3d_compiler *compiler,
 
         struct v3d_prog_data *prog_data;
 
-        static const int prog_data_size[] = {
-                [MESA_SHADER_VERTEX] = sizeof(struct v3d_vs_prog_data),
-                [MESA_SHADER_GEOMETRY] = sizeof(struct v3d_gs_prog_data),
-                [MESA_SHADER_FRAGMENT] = sizeof(struct v3d_fs_prog_data),
-                [MESA_SHADER_COMPUTE] = sizeof(struct v3d_compute_prog_data),
-        };
-
-        assert(c->s->info.stage >= 0 &&
-               c->s->info.stage < ARRAY_SIZE(prog_data_size) &&
-               prog_data_size[c->s->info.stage]);
-
-        prog_data = rzalloc_size(NULL, prog_data_size[c->s->info.stage]);
+        prog_data = rzalloc_size(NULL, v3d_prog_data_size(c->s->info.stage));
 
         v3d_set_prog_data(c, prog_data);