diff options
author | Erik Faye-Lund <[email protected]> | 2020-01-03 14:51:55 +0100 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-01-18 10:45:38 +0000 |
commit | c0ba9000d21ee22a25fec0b3338ea53184dd1130 (patch) | |
tree | 57cf4dc1983ea5aa27fcf5fd40a4af7779232f2d /src | |
parent | a9023ec5665ae84f6d05d2d58e5950b79ebcf977 (diff) |
zink: support arrays of samplers
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3275>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3275>
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c | 56 | ||||
-rw-r--r-- | src/gallium/drivers/zink/zink_compiler.c | 26 |
2 files changed, 60 insertions, 22 deletions
diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c index 922ed8c81f5..6d2d713b7f9 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c +++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c @@ -386,13 +386,15 @@ type_to_dim(enum glsl_sampler_dim gdim, bool *is_ms) static void emit_sampler(struct ntv_context *ctx, struct nir_variable *var) { + const struct glsl_type *type = glsl_without_array(var->type); + bool is_ms; - SpvDim dimension = type_to_dim(glsl_get_sampler_dim(var->type), &is_ms); + SpvDim dimension = type_to_dim(glsl_get_sampler_dim(type), &is_ms); - SpvId result_type = get_glsl_basetype(ctx, glsl_get_sampler_result_type(var->type)); + SpvId result_type = get_glsl_basetype(ctx, glsl_get_sampler_result_type(type)); SpvId image_type = spirv_builder_type_image(&ctx->builder, result_type, dimension, false, - glsl_sampler_type_is_array(var->type), + glsl_sampler_type_is_array(type), is_ms, 1, SpvImageFormatUnknown); @@ -401,21 +403,45 @@ emit_sampler(struct ntv_context *ctx, struct nir_variable *var) SpvId pointer_type = spirv_builder_type_pointer(&ctx->builder, SpvStorageClassUniformConstant, sampled_type); - SpvId var_id = spirv_builder_emit_var(&ctx->builder, pointer_type, - SpvStorageClassUniformConstant); - if (var->name) - spirv_builder_emit_name(&ctx->builder, var_id, var->name); + if (glsl_type_is_array(var->type)) { + for (int i = 0; i < glsl_get_length(var->type); ++i) { + SpvId var_id = spirv_builder_emit_var(&ctx->builder, pointer_type, + SpvStorageClassUniformConstant); - assert(ctx->num_samplers < ARRAY_SIZE(ctx->image_types)); - ctx->image_types[ctx->num_samplers] = image_type; + if (var->name) { + char element_name[100]; + snprintf(element_name, sizeof(element_name), "%s_%d", var->name, i); + spirv_builder_emit_name(&ctx->builder, var_id, var->name); + } - assert(ctx->num_samplers < ARRAY_SIZE(ctx->samplers)); - ctx->samplers[ctx->num_samplers++] = var_id; + assert(ctx->num_samplers < ARRAY_SIZE(ctx->image_types)); + ctx->image_types[ctx->num_samplers] = image_type; - spirv_builder_emit_descriptor_set(&ctx->builder, var_id, - var->data.descriptor_set); - spirv_builder_emit_binding(&ctx->builder, var_id, var->data.binding); + assert(ctx->num_samplers < ARRAY_SIZE(ctx->samplers)); + ctx->samplers[ctx->num_samplers++] = var_id; + + spirv_builder_emit_descriptor_set(&ctx->builder, var_id, + var->data.descriptor_set); + spirv_builder_emit_binding(&ctx->builder, var_id, var->data.binding); + } + } else { + SpvId var_id = spirv_builder_emit_var(&ctx->builder, pointer_type, + SpvStorageClassUniformConstant); + + 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; + + spirv_builder_emit_descriptor_set(&ctx->builder, var_id, + var->data.descriptor_set); + spirv_builder_emit_binding(&ctx->builder, var_id, var->data.binding); + } } static void @@ -465,7 +491,7 @@ emit_uniform(struct ntv_context *ctx, struct nir_variable *var) emit_ubo(ctx, var); else { assert(var->data.mode == nir_var_uniform); - if (glsl_type_is_sampler(var->type)) + if (glsl_type_is_sampler(glsl_without_array(var->type))) emit_sampler(ctx, var); } } diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index 7a89dc1088a..a1428785bd4 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -256,18 +256,30 @@ zink_compile_nir(struct zink_screen *screen, struct nir_shader *nir) ret->num_bindings = 0; nir_foreach_variable(var, &nir->uniforms) { - if (glsl_type_is_sampler(var->type)) { - ret->bindings[ret->num_bindings].index = var->data.driver_location; - var->data.binding = zink_binding(stage, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, var->data.driver_location); - ret->bindings[ret->num_bindings].binding = var->data.binding; - ret->bindings[ret->num_bindings].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - ret->num_bindings++; - } else if (var->interface_type) { + if (var->data.mode == nir_var_mem_ubo) { ret->bindings[ret->num_bindings].index = var->data.binding; var->data.binding = zink_binding(stage, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, var->data.binding); ret->bindings[ret->num_bindings].binding = var->data.binding; ret->bindings[ret->num_bindings].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; ret->num_bindings++; + } else { + assert(var->data.mode == nir_var_uniform); + if (glsl_type_is_array(var->type) && + glsl_type_is_sampler(glsl_get_array_element(var->type))) { + for (int i = 0; i < glsl_get_length(var->type); ++i) { + ret->bindings[ret->num_bindings].index = var->data.driver_location + i; + var->data.binding = zink_binding(stage, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, var->data.driver_location + i); + ret->bindings[ret->num_bindings].binding = var->data.binding; + ret->bindings[ret->num_bindings].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + ret->num_bindings++; + } + } else if (glsl_type_is_sampler(var->type)) { + ret->bindings[ret->num_bindings].index = var->data.driver_location; + var->data.binding = zink_binding(stage, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, var->data.driver_location); + ret->bindings[ret->num_bindings].binding = var->data.binding; + ret->bindings[ret->num_bindings].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + ret->num_bindings++; + } } } |