mesa: ensure parameter list capacity before associating uniform storage
authorAndrii Simiklit <andrii.simiklit@globallogic.com>
Thu, 25 Feb 2021 12:28:24 +0000 (14:28 +0200)
committerMarge Bot <eric+marge@anholt.net>
Sun, 28 Feb 2021 05:55:50 +0000 (05:55 +0000)
We have to reserve at lease 16 program parameters in storage to
avoid its reallocation.

v2: move allocation to `st_deserialise_ir_program` and add helper for that
                     ( Eric Anholt <eric@anholt.net> )

v3 amend comments a bit

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4352
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Andrii Simiklit <andrii.simiklit@globallogic.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9282>

src/gallium/drivers/llvmpipe/ci/llvmpipe-quick_gl.txt
src/mesa/program/ir_to_mesa.cpp
src/mesa/program/ir_to_mesa.h
src/mesa/state_tracker/st_glsl_to_nir.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
src/mesa/state_tracker/st_shader_cache.c

index fb9028c..965ebe1 100644 (file)
@@ -88,7 +88,6 @@ shaders/sso-uniforms-01: skip
 shaders/sso-uniforms-02: skip
 shaders/sso-user-varying-01: skip
 shaders/sso-user-varying-02: skip
-shaders/useprogram-refcount-1: crash
 shaders/useshaderprogram-bad-program: skip
 shaders/useshaderprogram-bad-type: skip
 shaders/useshaderprogram-flushverts-1: skip
@@ -471,7 +470,6 @@ spec/arb_fragment_shader_interlock/arb_fragment_shader_interlock-image-load-stor
 spec/arb_framebuffer_no_attachments/arb_framebuffer_no_attachments-params/dsa: skip
 spec/arb_framebuffer_no_attachments/arb_framebuffer_no_attachments-query/ms2: skip
 spec/arb_framebuffer_object/fbo-blit-scaled-linear: fail
-spec/arb_framebuffer_object/fbo-drawbuffers-none gldrawpixels: crash
 spec/arb_geometry_shader4/arb_geometry_shader4-ignore-adjacent-vertices  gl_line_strip_adjacency: skip
 spec/arb_geometry_shader4/arb_geometry_shader4-ignore-adjacent-vertices  gl_lines_adjacency: skip
 spec/arb_geometry_shader4/arb_geometry_shader4-ignore-adjacent-vertices  gl_triangle_strip_adjacency: skip
index d3ea9b0..1b7ad7f 100644 (file)
@@ -2616,6 +2616,24 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
    }
 }
 
+void
+_mesa_ensure_and_associate_uniform_storage(struct gl_context *ctx,
+                              struct gl_shader_program *shader_program,
+                              struct gl_program *prog, unsigned required_space)
+{
+   /* Avoid reallocation of the program parameter list, because the uniform
+    * storage is only associated with the original parameter list.
+    */
+   _mesa_reserve_parameter_storage(prog->Parameters, required_space,
+                                   required_space);
+
+   /* This has to be done last.  Any operation the can cause
+    * prog->ParameterValues to get reallocated (e.g., anything that adds a
+    * program constant) has to happen before creating this linkage.
+    */
+   _mesa_associate_uniform_storage(ctx, shader_program, prog);
+}
+
 /*
  * On a basic block basis, tracks available PROGRAM_TEMPORARY register
  * channels for copy propagation and updates following instructions to
index 33eb801..81c05e2 100644 (file)
@@ -52,6 +52,11 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
                                 struct gl_shader_program *shader_program,
                                 struct gl_program *prog);
 
+void
+_mesa_ensure_and_associate_uniform_storage(struct gl_context *ctx,
+                             struct gl_shader_program *shader_program,
+                             struct gl_program *prog, unsigned required_space);
+
 #ifdef __cplusplus
 }
 #endif
index 2a1916c..2af4e70 100644 (file)
@@ -504,13 +504,7 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog,
     * storage is only associated with the original parameter list.
     * This should be enough for Bitmap and DrawPixels constants.
     */
-   _mesa_reserve_parameter_storage(prog->Parameters, 16, 16);
-
-   /* This has to be done last.  Any operation the can cause
-    * prog->ParameterValues to get reallocated (e.g., anything that adds a
-    * program constant) has to happen before creating this linkage.
-    */
-   _mesa_associate_uniform_storage(st->ctx, shader_program, prog);
+   _mesa_ensure_and_associate_uniform_storage(st->ctx, shader_program, prog, 16);
 
    st_set_prog_affected_state_flags(prog);
 
index 6c9edd3..b3fa53c 100644 (file)
@@ -7237,13 +7237,7 @@ get_mesa_program_tgsi(struct gl_context *ctx,
     * storage is only associated with the original parameter list.
     * This should be enough for Bitmap and DrawPixels constants.
     */
-   _mesa_reserve_parameter_storage(prog->Parameters, 8, 8);
-
-   /* This has to be done last.  Any operation the can cause
-    * prog->ParameterValues to get reallocated (e.g., anything that adds a
-    * program constant) has to happen before creating this linkage.
-    */
-   _mesa_associate_uniform_storage(ctx, shader_program, prog);
+   _mesa_ensure_and_associate_uniform_storage(ctx, shader_program, prog, 8);
    if (!shader_program->data->LinkStatus) {
       free_glsl_to_tgsi_visitor(v);
       _mesa_reference_program(ctx, &shader->Program, NULL);
index 000d1c2..1dde99c 100644 (file)
@@ -180,7 +180,12 @@ st_deserialise_ir_program(struct gl_context *ctx,
    uint8_t *buffer = (uint8_t *) prog->driver_cache_blob;
 
    st_set_prog_affected_state_flags(prog);
-   _mesa_associate_uniform_storage(ctx, shProg, prog);
+
+   /* Avoid reallocation of the program parameter list, because the uniform
+    * storage is only associated with the original parameter list.
+    * This should be enough for Bitmap and DrawPixels constants.
+    */
+   _mesa_ensure_and_associate_uniform_storage(ctx, shProg, prog, 16);
 
    assert(prog->driver_cache_blob && prog->driver_cache_blob_size > 0);