return SpvDim2D;
}
+uint32_t
+zink_binding(gl_shader_stage stage, VkDescriptorType type, int index)
+{
+ if (stage == MESA_SHADER_NONE ||
+ stage >= MESA_SHADER_COMPUTE) {
+ unreachable("not supported");
+ } else {
+ uint32_t stage_offset = (uint32_t)stage * (PIPE_MAX_CONSTANT_BUFFERS +
+ PIPE_MAX_SHADER_SAMPLER_VIEWS);
+
+ switch (type) {
+ case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
+ assert(index < PIPE_MAX_CONSTANT_BUFFERS);
+ return stage_offset + index;
+
+ case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
+ assert(index < PIPE_MAX_SHADER_SAMPLER_VIEWS);
+ return stage_offset + PIPE_MAX_CONSTANT_BUFFERS + index;
+
+ default:
+ unreachable("unexpected type");
+ }
+ }
+}
+
static void
emit_sampler(struct ntv_context *ctx, struct nir_variable *var)
{
spirv_builder_emit_name(&ctx->builder, var_id, var->name);
}
- int index = var->data.driver_location + i;
+ int index = var->data.binding + i;
assert(!(ctx->samplers_used & (1 << index)));
assert(!ctx->image_types[index]);
ctx->image_types[index] = 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);
+ int binding = zink_binding(ctx->stage,
+ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+ var->data.binding + i);
+ spirv_builder_emit_binding(&ctx->builder, var_id, binding);
}
} else {
SpvId var_id = spirv_builder_emit_var(&ctx->builder, pointer_type,
if (var->name)
spirv_builder_emit_name(&ctx->builder, var_id, var->name);
- int index = var->data.driver_location;
+ int index = var->data.binding;
assert(!(ctx->samplers_used & (1 << index)));
assert(!ctx->image_types[index]);
ctx->image_types[index] = 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);
+ int binding = zink_binding(ctx->stage,
+ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+ var->data.binding);
+ spirv_builder_emit_binding(&ctx->builder, var_id, binding);
}
}
spirv_builder_emit_descriptor_set(&ctx->builder, var_id,
var->data.descriptor_set);
- spirv_builder_emit_binding(&ctx->builder, var_id, var->data.binding);
+ int binding = zink_binding(ctx->stage,
+ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+ var->data.binding);
+ spirv_builder_emit_binding(&ctx->builder, var_id, binding);
}
static void
} while (progress);
}
-static uint32_t
-zink_binding(enum pipe_shader_type stage, VkDescriptorType type, int index)
-{
- if (stage == PIPE_SHADER_COMPUTE) {
- unreachable("not supported");
- } else {
- uint32_t stage_offset = (uint32_t)stage * (PIPE_MAX_CONSTANT_BUFFERS +
- PIPE_MAX_SHADER_SAMPLER_VIEWS);
-
- switch (type) {
- case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
- assert(index < PIPE_MAX_CONSTANT_BUFFERS);
- return stage_offset + index;
-
- case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
- assert(index < PIPE_MAX_SHADER_SAMPLER_VIEWS);
- return stage_offset + PIPE_MAX_CONSTANT_BUFFERS + index;
-
- default:
- unreachable("unexpected type");
- }
- }
-}
-
struct zink_shader *
zink_compile_nir(struct zink_screen *screen, struct nir_shader *nir)
{
fprintf(stderr, "---8<---\n");
}
- enum pipe_shader_type stage = pipe_shader_type_from_mesa(nir->info.stage);
-
ret->num_bindings = 0;
nir_foreach_variable(var, &nir->uniforms) {
if (var->data.mode == nir_var_mem_ubo) {
+ int binding = zink_binding(nir->info.stage,
+ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+ var->data.binding);
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].binding = binding;
ret->bindings[ret->num_bindings].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
ret->num_bindings++;
} else {
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.binding;
- var->data.driver_location = var->data.binding + i;
- 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;
+ int binding = zink_binding(nir->info.stage,
+ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+ var->data.binding + i);
+ ret->bindings[ret->num_bindings].index = var->data.binding + i;
+ ret->bindings[ret->num_bindings].binding = binding;
ret->bindings[ret->num_bindings].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
ret->num_bindings++;
}
} else if (glsl_type_is_sampler(var->type)) {
+ int binding = zink_binding(nir->info.stage,
+ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+ var->data.binding);
ret->bindings[ret->num_bindings].index = var->data.binding;
- var->data.driver_location = var->data.binding;
- 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].binding = binding;
ret->bindings[ret->num_bindings].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
ret->num_bindings++;
}