radeonsi: stop using TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
[mesa.git] / src / gallium / drivers / zink / zink_program.c
index 550c0506f423407606060fb67e5193755429f707..0bcaa4a03e797450a76b9f0976bbef1683bb127c 100644 (file)
@@ -149,12 +149,12 @@ update_shader_modules(struct zink_context *ctx, struct zink_shader *stages[ZINK_
    for (int i = 0; i < ZINK_SHADER_COUNT; ++i) {
       enum pipe_shader_type type = pipe_shader_type_from_mesa(i);
       if (dirty[i]) {
-         prog->stages[type] = CALLOC_STRUCT(zink_shader_module);
-         assert(prog->stages[type]);
-         pipe_reference_init(&prog->stages[type]->reference, 1);
-         prog->stages[type]->shader = zink_shader_compile(zink_screen(ctx->base.screen), dirty[i]);
+         prog->modules[type] = CALLOC_STRUCT(zink_shader_module);
+         assert(prog->modules[type]);
+         pipe_reference_init(&prog->modules[type]->reference, 1);
+         prog->modules[type]->shader = zink_shader_compile(zink_screen(ctx->base.screen), dirty[i]);
       } else if (stages[type]) /* reuse existing shader module */
-         zink_shader_module_reference(zink_screen(ctx->base.screen), &prog->stages[type], ctx->curr_program->stages[type]);
+         zink_shader_module_reference(zink_screen(ctx->base.screen), &prog->modules[type], ctx->curr_program->modules[type]);
       prog->shaders[type] = stages[type];
    }
    ctx->dirty_shader_stages = 0;
@@ -163,13 +163,13 @@ update_shader_modules(struct zink_context *ctx, struct zink_shader *stages[ZINK_
 static uint32_t
 hash_gfx_pipeline_state(const void *key)
 {
-   return _mesa_hash_data(key, sizeof(struct zink_gfx_pipeline_state));
+   return _mesa_hash_data(key, offsetof(struct zink_gfx_pipeline_state, hash));
 }
 
 static bool
 equals_gfx_pipeline_state(const void *a, const void *b)
 {
-   return memcmp(a, b, sizeof(struct zink_gfx_pipeline_state)) == 0;
+   return memcmp(a, b, offsetof(struct zink_gfx_pipeline_state, hash)) == 0;
 }
 
 struct zink_gfx_program *
@@ -194,7 +194,7 @@ zink_create_gfx_program(struct zink_context *ctx,
    }
 
    for (int i = 0; i < ZINK_SHADER_COUNT; ++i) {
-      if (prog->stages[i]) {
+      if (prog->modules[i]) {
          _mesa_set_add(stages[i]->programs, prog);
          zink_gfx_program_reference(screen, NULL, prog);
       }
@@ -245,8 +245,8 @@ zink_destroy_gfx_program(struct zink_screen *screen,
    for (int i = 0; i < ZINK_SHADER_COUNT; ++i) {
       if (prog->shaders[i])
          gfx_program_remove_shader(prog, prog->shaders[i]);
-      if (prog->stages[i])
-         zink_shader_module_reference(screen, &prog->stages[i], NULL);
+      if (prog->modules[i])
+         zink_shader_module_reference(screen, &prog->modules[i], NULL);
    }
 
    /* unref all used render-passes */
@@ -293,6 +293,18 @@ primitive_topology(enum pipe_prim_type mode)
    case PIPE_PRIM_TRIANGLE_FAN:
       return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN;
 
+   case PIPE_PRIM_LINE_STRIP_ADJACENCY:
+      return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY;
+
+   case PIPE_PRIM_LINES_ADJACENCY:
+      return VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY;
+
+   case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
+      return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY;
+
+   case PIPE_PRIM_TRIANGLES_ADJACENCY:
+      return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY;
+
    default:
       unreachable("unexpected enum pipe_prim_type");
    }
@@ -317,13 +329,20 @@ zink_get_gfx_pipeline(struct zink_screen *screen,
                       struct zink_gfx_pipeline_state *state,
                       enum pipe_prim_type mode)
 {
-   assert(mode <= ARRAY_SIZE(prog->pipelines));
+   VkPrimitiveTopology vkmode = primitive_topology(mode);
+   assert(vkmode <= ARRAY_SIZE(prog->pipelines));
+
+   struct hash_entry *entry = NULL;
+   
+   if (!state->hash) {
+      state->hash = hash_gfx_pipeline_state(state);
+      /* make sure the hash is not zero, as we take it as invalid.
+       * TODO: rework this using a separate dirty-bit */
+      assert(state->hash != 0);
+   }
+   entry = _mesa_hash_table_search_pre_hashed(prog->pipelines[vkmode], state->hash, state);
 
-   /* TODO: use pre-hashed versions to save some time (can re-hash only when
-      state changes) */
-   struct hash_entry *entry = _mesa_hash_table_search(prog->pipelines[mode], state);
    if (!entry) {
-      VkPrimitiveTopology vkmode = primitive_topology(mode);
       VkPipeline pipeline = zink_create_gfx_pipeline(screen, prog,
                                                      state, vkmode);
       if (pipeline == VK_NULL_HANDLE)
@@ -336,7 +355,8 @@ zink_get_gfx_pipeline(struct zink_screen *screen,
       memcpy(&pc_entry->state, state, sizeof(*state));
       pc_entry->pipeline = pipeline;
 
-      entry = _mesa_hash_table_insert(prog->pipelines[mode], &pc_entry->state, pc_entry);
+      assert(state->hash);
+      entry = _mesa_hash_table_insert_pre_hashed(prog->pipelines[vkmode], state->hash, state, pc_entry);
       assert(entry);
 
       reference_render_pass(screen, prog, state->render_pass);