Zebediah Figura : vkd3d-shader/hlsl: Allocate textures for SM4.
Alexandre Julliard
julliard at winehq.org
Fri Oct 15 15:39:49 CDT 2021
Module: vkd3d
Branch: master
Commit: 899c2f25e219604e2e10c80640e9e757f2f68f1f
URL: https://source.winehq.org/git/vkd3d.git/?a=commit;h=899c2f25e219604e2e10c80640e9e757f2f68f1f
Author: Zebediah Figura <zfigura at codeweavers.com>
Date: Mon Oct 11 21:58:46 2021 -0500
vkd3d-shader/hlsl: Allocate textures for SM4.
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
libs/vkd3d-shader/hlsl_codegen.c | 63 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 00fe76b..bf93a03 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -1197,6 +1197,64 @@ static void allocate_buffers(struct hlsl_ctx *ctx)
}
}
+static const struct hlsl_ir_var *get_reserved_texture(struct hlsl_ctx *ctx, uint32_t index)
+{
+ const struct hlsl_ir_var *var;
+
+ LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, const struct hlsl_ir_var, extern_entry)
+ {
+ if (var->has_resource_access && var->reg_reservation.type == 't' && var->reg_reservation.index == index)
+ return var;
+ }
+ return NULL;
+}
+
+static void allocate_textures(struct hlsl_ctx *ctx)
+{
+ struct hlsl_ir_var *var;
+ uint32_t index = 0;
+
+ LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry)
+ {
+ if (!var->has_resource_access || var->data_type->type != HLSL_CLASS_OBJECT
+ || var->data_type->base_type != HLSL_TYPE_TEXTURE)
+ continue;
+
+ if (var->reg_reservation.type == 't')
+ {
+ const struct hlsl_ir_var *reserved_texture = get_reserved_texture(ctx, var->reg_reservation.index);
+
+ if (reserved_texture && reserved_texture != var)
+ {
+ hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_OVERLAPPING_RESERVATIONS,
+ "Multiple textures bound to t%u.", var->reg_reservation.index);
+ hlsl_note(ctx, reserved_texture->loc, VKD3D_SHADER_LOG_ERROR,
+ "Texture '%s' is already bound to t%u.", reserved_texture->name,
+ var->reg_reservation.index);
+ }
+
+ var->reg.id = var->reg_reservation.index;
+ var->reg.allocated = true;
+ TRACE("Allocated reserved %s to t%u.\n", var->name, index);
+ }
+ else if (!var->reg_reservation.type)
+ {
+ while (get_reserved_texture(ctx, index))
+ ++index;
+
+ var->reg.id = index;
+ var->reg.allocated = true;
+ TRACE("Allocated %s to t%u.\n", var->name, index);
+ ++index;
+ }
+ else
+ {
+ hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_RESERVATION,
+ "Textures must be bound to register type 't'.");
+ }
+ }
+}
+
static bool type_is_single_reg(const struct hlsl_type *type)
{
return type->type == HLSL_CLASS_SCALAR || type->type == HLSL_CLASS_VECTOR;
@@ -1315,9 +1373,14 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
allocate_temp_registers(ctx, entry_func);
if (ctx->profile->major_version < 4)
+ {
allocate_const_registers(ctx, entry_func);
+ }
else
+ {
allocate_buffers(ctx);
+ allocate_textures(ctx);
+ }
allocate_semantic_registers(ctx);
if (ctx->result)
More information about the wine-cvs
mailing list