[Mesa-dev] [PATCH 16/65] i965: don't crash when there is no shader and there are uniforms

Timothy Arceri timothy.arceri at collabora.com
Fri Apr 29 13:33:15 UTC 2016


---
 src/mesa/drivers/dri/i965/brw_shader_cache.c | 35 ++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index c565e5a..e5aa022 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -118,12 +118,15 @@ upload_cached_program(struct brw_context *brw)
       intptr_t param = blob_read_intptr(&binary);
       ptrdiff_t p_offset, u_offset;
       struct gl_program_parameter_list *param_list =
-         prog->_LinkedShaders[MESA_SHADER_VERTEX]->Program->Parameters;
+         prog->_LinkedShaders[MESA_SHADER_VERTEX] ?
+            prog->_LinkedShaders[MESA_SHADER_VERTEX]->Program->Parameters :
+            NULL;
 
       p_offset = (param - parameter_values_base) / sizeof(gl_constant_value);
       u_offset = (param - uniform_data_slots_base) / sizeof(gl_constant_value);
       
-      if (p_offset >= 0 && p_offset < 4 * param_list->NumParameters) {
+      if (param_list && p_offset >= 0 &&
+          p_offset < 4 * param_list->NumParameters) {
          prog_data->param[i] =
             ((gl_constant_value *) param_list->ParameterValues) + p_offset;
       } else if (u_offset >= 0 && u_offset < prog->NumUniformDataSlots) {
@@ -182,12 +185,15 @@ upload_cached_program(struct brw_context *brw)
       intptr_t param = blob_read_intptr(&binary);
       ptrdiff_t p_offset, u_offset;
       struct gl_program_parameter_list *param_list =
-         prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program->Parameters;
+         prog->_LinkedShaders[MESA_SHADER_FRAGMENT] ?
+            prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program->Parameters :
+            NULL;
 
       p_offset = (param - parameter_values_base) / sizeof(gl_constant_value);
       u_offset = (param - uniform_data_slots_base) / sizeof(gl_constant_value);
       
-      if (p_offset >= 0 && p_offset < 4 * param_list->NumParameters) {
+      if (param_list && p_offset >= 0 &&
+          p_offset < 4 * param_list->NumParameters) {
          prog_data->param[i] =
             ((gl_constant_value *) param_list->ParameterValues) + p_offset;
       } else if (u_offset >= 0 && u_offset < prog->NumUniformDataSlots) {
@@ -288,9 +294,14 @@ write_cached_program(struct brw_context *brw)
     * together with the pointer values to correctly construct pointers to the
     * actual storage when the program data is loaded from the cache.
     */
-   blob_write_intptr(binary,
-                     (intptr_t) prog->_LinkedShaders[MESA_SHADER_VERTEX]->
-                      Program->Parameters->ParameterValues);
+   if (prog->_LinkedShaders[MESA_SHADER_VERTEX]) {
+      blob_write_intptr(binary,
+                        (intptr_t) prog->_LinkedShaders[MESA_SHADER_VERTEX]->
+                         Program->Parameters->ParameterValues);
+   } else {
+      blob_write_intptr(binary, 0);
+   }
+
    blob_write_intptr(binary, (intptr_t) prog->UniformDataSlots);
 
    nr_params = brw->vs.prog_data->base.base.nr_params;
@@ -325,9 +336,13 @@ write_cached_program(struct brw_context *brw)
    /* Include variable-length params, (don't need to rewrite UniformDataSlots
     * pointer).
     */
-   blob_write_intptr(binary,
-                     (intptr_t) prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->
-                     Program->Parameters->ParameterValues);
+   if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT]) {
+      blob_write_intptr(binary,
+                        (intptr_t) prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->
+                        Program->Parameters->ParameterValues);
+   } else {
+      blob_write_intptr(binary, 0);
+   }
 
    nr_params = brw->wm.prog_data->base.nr_params;
    blob_write_uint32(binary, nr_params);
-- 
2.5.5



More information about the mesa-dev mailing list