ddebug: handle some cases of non-TGSI shaders
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Fri, 9 Jun 2017 13:12:23 +0000 (15:12 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 5 Jul 2017 10:27:11 +0000 (12:27 +0200)
NIR shaders are not captured properly in pipelined mode currently. This
would require shader cloning, which requires linking all the Gallium
drivers against NIR. We can always do that later.

v2: avoid immediate crashes in pipelined mode

Reviewed-by: Marek Olšák <marek.olsak@amd.com> (v1)
src/gallium/drivers/ddebug/dd_context.c
src/gallium/drivers/ddebug/dd_draw.c
src/gallium/drivers/ddebug/dd_screen.c

index 1ace9e52eb77e5a286d762577958ef56186df1e6..6b1ddc9d46be72a7f223e190b64fc7758825a521 100644 (file)
@@ -314,7 +314,8 @@ DD_CSO_DELETE(vertex_elements)
       struct dd_state *hstate = state; \
    \
       pipe->delete_##name##_state(pipe, hstate->cso); \
-      tgsi_free_tokens(hstate->state.shader.tokens); \
+      if (hstate->state.shader.type == PIPE_SHADER_IR_TGSI) \
+         tgsi_free_tokens(hstate->state.shader.tokens); \
       FREE(hstate); \
    }
 
@@ -330,7 +331,8 @@ DD_CSO_DELETE(vertex_elements)
          return NULL; \
       hstate->cso = pipe->create_##name##_state(pipe, state); \
       hstate->state.shader = *state; \
-      hstate->state.shader.tokens = tgsi_dup_tokens(state->tokens); \
+      if (hstate->state.shader.type == PIPE_SHADER_IR_TGSI) \
+         hstate->state.shader.tokens = tgsi_dup_tokens(state->tokens); \
       return hstate; \
    } \
     \
index 7edf6aff840c98f0a333cbd6e9dafa2fbf878960..9c95d250d1a03b226a57bd01cc820680fbea7c48 100644 (file)
@@ -98,8 +98,13 @@ dd_num_active_viewports(struct dd_draw_state *dstate)
    else
       return 1;
 
-   tgsi_scan_shader(tokens, &info);
-   return info.writes_viewport_index ? PIPE_MAX_VIEWPORTS : 1;
+   if (tokens) {
+      tgsi_scan_shader(tokens, &info);
+      if (info.writes_viewport_index)
+         return PIPE_MAX_VIEWPORTS;
+   }
+
+   return 1;
 }
 
 #define COLOR_RESET    "\033[0m"
@@ -831,8 +836,12 @@ dd_copy_draw_state(struct dd_draw_state *dst, struct dd_draw_state *src)
 
       if (src->shaders[i]) {
          dst->shaders[i]->state.shader = src->shaders[i]->state.shader;
-         dst->shaders[i]->state.shader.tokens =
-            tgsi_dup_tokens(src->shaders[i]->state.shader.tokens);
+         if (src->shaders[i]->state.shader.tokens) {
+            dst->shaders[i]->state.shader.tokens =
+               tgsi_dup_tokens(src->shaders[i]->state.shader.tokens);
+         } else {
+            dst->shaders[i]->state.shader.ir.nir = NULL;
+         }
       } else {
          dst->shaders[i] = NULL;
       }
index 9642532bc023a13e0f0b44063bbfb29f69845750..a5d2be1402d82b94e2bfb3578267c58953df6143 100644 (file)
@@ -55,6 +55,16 @@ dd_screen_get_device_vendor(struct pipe_screen *_screen)
    return screen->get_device_vendor(screen);
 }
 
+static const void *
+dd_screen_get_compiler_options(struct pipe_screen *_screen,
+                               enum pipe_shader_ir ir,
+                               enum pipe_shader_type shader)
+{
+   struct pipe_screen *screen = dd_screen(_screen)->screen;
+
+   return screen->get_compiler_options(screen, ir, shader);
+}
+
 static struct disk_cache *
 dd_screen_get_disk_shader_cache(struct pipe_screen *_screen)
 {
@@ -411,6 +421,7 @@ ddebug_screen_create(struct pipe_screen *screen)
    SCR_INIT(fence_finish);
    SCR_INIT(get_driver_query_info);
    SCR_INIT(get_driver_query_group_info);
+   SCR_INIT(get_compiler_options);
 
 #undef SCR_INIT