zink: store image-type per texture
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Fri, 3 Jan 2020 12:55:35 +0000 (13:55 +0100)
committerMarge Bot <eric+marge@anholt.net>
Sat, 18 Jan 2020 10:45:38 +0000 (10:45 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3275>

src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c

index bb916cf7a984c582098b0842041e472ba86362ee..3c0f226028833c03e8d1381dddbb350190fba35b 100644 (file)
@@ -38,6 +38,7 @@ struct ntv_context {
 
    SpvId ubos[128];
    size_t num_ubos;
+   SpvId image_types[PIPE_MAX_SAMPLERS];
    SpvId samplers[PIPE_MAX_SAMPLERS];
    size_t num_samplers;
    SpvId entry_ifaces[PIPE_MAX_SHADER_INPUTS * 4 + PIPE_MAX_SHADER_OUTPUTS * 4];
@@ -403,6 +404,9 @@ emit_sampler(struct ntv_context *ctx, struct nir_variable *var)
    if (var->name)
       spirv_builder_emit_name(&ctx->builder, var_id, var->name);
 
+   assert(ctx->num_samplers < ARRAY_SIZE(ctx->image_types));
+   ctx->image_types[ctx->num_samplers] = image_type;
+
    assert(ctx->num_samplers < ARRAY_SIZE(ctx->samplers));
    ctx->samplers[ctx->num_samplers++] = var_id;
 
@@ -1438,12 +1442,7 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
       assert(lod != 0);
    }
 
-   bool is_ms;
-   SpvDim dimension = type_to_dim(tex->sampler_dim, &is_ms);
-   SpvId float_type = spirv_builder_type_float(&ctx->builder, 32);
-   SpvId image_type = spirv_builder_type_image(&ctx->builder, float_type,
-                            dimension, false, tex->is_array, is_ms, 1,
-                            SpvImageFormatUnknown);
+   SpvId image_type = ctx->image_types[tex->texture_index];
    SpvId sampled_type = spirv_builder_type_sampled_image(&ctx->builder,
                                                          image_type);
 
@@ -1487,7 +1486,7 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
 
    SpvId actual_dest_type = dest_type;
    if (dref)
-      actual_dest_type = float_type;
+      actual_dest_type = spirv_builder_type_float(&ctx->builder, 32);
 
    SpvId result;
    if (tex->op == nir_texop_txf) {