Updated vkd3d-latest patchset

This commit is contained in:
Alistair Leslie-Hughes 2023-06-10 10:59:31 +10:00
parent 6c167535e3
commit 710e29cc68
5 changed files with 1434 additions and 1804 deletions

View File

@ -1,4 +1,4 @@
From b349a2915750a5de22339a8bd12ec10ad35d61da Mon Sep 17 00:00:00 2001
From 494b9575bff5b2f6a2225847752899af0860768f Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Date: Wed, 17 May 2023 08:13:47 +1000
Subject: [PATCH 1/2] wined3d: rename shader_extract_from_dxbc to

View File

@ -1,611 +0,0 @@
From 8af3410aba9ba20ac32a17241dfe1f33f259fbd1 Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Date: Fri, 2 Jun 2023 10:30:18 +1000
Subject: [PATCH 3/3] Updated vkd3d to 7c360330d74f5c2f6de962355927ee6e7d7dfbf0
---
libs/vkd3d/libs/vkd3d-shader/hlsl.c | 21 +-
libs/vkd3d/libs/vkd3d-shader/hlsl.h | 7 +-
libs/vkd3d/libs/vkd3d-shader/hlsl.y | 202 +++++++++++++++-----
libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c | 6 +
libs/vkd3d/libs/vkd3d-shader/preproc.l | 1 +
libs/vkd3d/libs/vkd3d-shader/tpf.c | 96 +++++-----
6 files changed, 239 insertions(+), 94 deletions(-)
diff --git a/libs/vkd3d/libs/vkd3d-shader/hlsl.c b/libs/vkd3d/libs/vkd3d-shader/hlsl.c
index 5bca84ba38a..152ec6275eb 100644
--- a/libs/vkd3d/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d/libs/vkd3d-shader/hlsl.c
@@ -1356,6 +1356,7 @@ struct hlsl_ir_node *hlsl_new_resource_load(struct hlsl_ctx *ctx,
hlsl_src_from_node(&load->lod, params->lod);
hlsl_src_from_node(&load->ddx, params->ddx);
hlsl_src_from_node(&load->ddy, params->ddy);
+ hlsl_src_from_node(&load->cmp, params->cmp);
load->sampling_dim = params->sampling_dim;
if (load->sampling_dim == HLSL_SAMPLER_DIM_GENERIC)
load->sampling_dim = hlsl_deref_get_type(ctx, &load->resource)->sampler_dim;
@@ -1649,6 +1650,7 @@ static struct hlsl_ir_node *clone_resource_load(struct hlsl_ctx *ctx,
clone_src(map, &dst->ddx, &src->ddx);
clone_src(map, &dst->ddy, &src->ddy);
clone_src(map, &dst->sample_index, &src->sample_index);
+ clone_src(map, &dst->cmp, &src->cmp);
clone_src(map, &dst->texel_offset, &src->texel_offset);
dst->sampling_dim = src->sampling_dim;
return &dst->node;
@@ -2442,6 +2444,8 @@ static void dump_ir_resource_load(struct vkd3d_string_buffer *buffer, const stru
{
[HLSL_RESOURCE_LOAD] = "load_resource",
[HLSL_RESOURCE_SAMPLE] = "sample",
+ [HLSL_RESOURCE_SAMPLE_CMP] = "sample_cmp",
+ [HLSL_RESOURCE_SAMPLE_CMP_LZ] = "sample_cmp_lz",
[HLSL_RESOURCE_SAMPLE_LOD] = "sample_lod",
[HLSL_RESOURCE_SAMPLE_LOD_BIAS] = "sample_biased",
[HLSL_RESOURCE_SAMPLE_GRAD] = "sample_grad",
@@ -2483,6 +2487,11 @@ static void dump_ir_resource_load(struct vkd3d_string_buffer *buffer, const stru
vkd3d_string_buffer_printf(buffer, ", ddy = ");
dump_src(buffer, &load->ddy);
}
+ if (load->cmp.node)
+ {
+ vkd3d_string_buffer_printf(buffer, ", cmp = ");
+ dump_src(buffer, &load->cmp);
+ }
vkd3d_string_buffer_printf(buffer, ")");
}
@@ -2720,6 +2729,7 @@ static void free_ir_resource_load(struct hlsl_ir_resource_load *load)
hlsl_src_remove(&load->lod);
hlsl_src_remove(&load->ddx);
hlsl_src_remove(&load->ddy);
+ hlsl_src_remove(&load->cmp);
hlsl_src_remove(&load->texel_offset);
hlsl_src_remove(&load->sample_index);
vkd3d_free(load);
@@ -3061,11 +3071,12 @@ static void declare_predefined_types(struct hlsl_ctx *ctx)
static const char *const sampler_names[] =
{
- [HLSL_SAMPLER_DIM_GENERIC] = "sampler",
- [HLSL_SAMPLER_DIM_1D] = "sampler1D",
- [HLSL_SAMPLER_DIM_2D] = "sampler2D",
- [HLSL_SAMPLER_DIM_3D] = "sampler3D",
- [HLSL_SAMPLER_DIM_CUBE] = "samplerCUBE",
+ [HLSL_SAMPLER_DIM_GENERIC] = "sampler",
+ [HLSL_SAMPLER_DIM_COMPARISON] = "SamplerComparisonState",
+ [HLSL_SAMPLER_DIM_1D] = "sampler1D",
+ [HLSL_SAMPLER_DIM_2D] = "sampler2D",
+ [HLSL_SAMPLER_DIM_3D] = "sampler3D",
+ [HLSL_SAMPLER_DIM_CUBE] = "samplerCUBE",
};
static const struct
diff --git a/libs/vkd3d/libs/vkd3d-shader/hlsl.h b/libs/vkd3d/libs/vkd3d-shader/hlsl.h
index 376191b9ff3..6b79c582f55 100644
--- a/libs/vkd3d/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d/libs/vkd3d-shader/hlsl.h
@@ -105,6 +105,7 @@ enum hlsl_base_type
enum hlsl_sampler_dim
{
HLSL_SAMPLER_DIM_GENERIC,
+ HLSL_SAMPLER_DIM_COMPARISON,
HLSL_SAMPLER_DIM_1D,
HLSL_SAMPLER_DIM_2D,
HLSL_SAMPLER_DIM_3D,
@@ -614,6 +615,8 @@ enum hlsl_resource_load_type
{
HLSL_RESOURCE_LOAD,
HLSL_RESOURCE_SAMPLE,
+ HLSL_RESOURCE_SAMPLE_CMP,
+ HLSL_RESOURCE_SAMPLE_CMP_LZ,
HLSL_RESOURCE_SAMPLE_LOD,
HLSL_RESOURCE_SAMPLE_LOD_BIAS,
HLSL_RESOURCE_SAMPLE_GRAD,
@@ -628,7 +631,7 @@ struct hlsl_ir_resource_load
struct hlsl_ir_node node;
enum hlsl_resource_load_type load_type;
struct hlsl_deref resource, sampler;
- struct hlsl_src coords, lod, ddx, ddy, sample_index, texel_offset;
+ struct hlsl_src coords, lod, ddx, ddy, cmp, sample_index, texel_offset;
enum hlsl_sampler_dim sampling_dim;
};
@@ -830,7 +833,7 @@ struct hlsl_resource_load_params
struct hlsl_type *format;
enum hlsl_resource_load_type type;
struct hlsl_ir_node *resource, *sampler;
- struct hlsl_ir_node *coords, *lod, *ddx, *ddy, *sample_index, *texel_offset;
+ struct hlsl_ir_node *coords, *lod, *ddx, *ddy, *cmp, *sample_index, *texel_offset;
enum hlsl_sampler_dim sampling_dim;
};
diff --git a/libs/vkd3d/libs/vkd3d-shader/hlsl.y b/libs/vkd3d/libs/vkd3d-shader/hlsl.y
index dae1851c7ad..cf483d82c65 100644
--- a/libs/vkd3d/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d/libs/vkd3d-shader/hlsl.y
@@ -3721,6 +3721,18 @@ static unsigned int hlsl_offset_dim_count(enum hlsl_sampler_dim dim)
}
}
+static bool raise_invalid_method_object_type(struct hlsl_ctx *ctx, const struct hlsl_type *object_type,
+ const char *method, const struct vkd3d_shader_location *loc)
+{
+ struct vkd3d_string_buffer *string;
+
+ if ((string = hlsl_type_to_string(ctx, object_type)))
+ hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED,
+ "Method '%s' is not defined on type '%s'.", method, string->buffer);
+ hlsl_release_string_buffer(ctx, string);
+ return false;
+}
+
static bool add_load_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *object,
const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
@@ -3731,6 +3743,12 @@ static bool add_load_method_call(struct hlsl_ctx *ctx, struct list *instrs, stru
struct hlsl_ir_node *load;
bool multisampled;
+ if (object_type->sampler_dim == HLSL_SAMPLER_DIM_CUBE
+ || object_type->sampler_dim == HLSL_SAMPLER_DIM_CUBEARRAY)
+ {
+ return raise_invalid_method_object_type(ctx, object_type, name, loc);
+ }
+
multisampled = object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS
|| object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY;
@@ -3784,6 +3802,12 @@ static bool add_sample_method_call(struct hlsl_ctx *ctx, struct list *instrs, st
const struct hlsl_type *sampler_type;
struct hlsl_ir_node *load;
+ if (object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS
+ || object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY)
+ {
+ return raise_invalid_method_object_type(ctx, object_type, name, loc);
+ }
+
if (params->args_count < 2 || params->args_count > 4 + !!offset_dim)
{
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
@@ -3832,6 +3856,80 @@ static bool add_sample_method_call(struct hlsl_ctx *ctx, struct list *instrs, st
return true;
}
+static bool add_sample_cmp_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *object,
+ const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
+{
+ const struct hlsl_type *object_type = object->data_type;
+ const unsigned int sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim);
+ const unsigned int offset_dim = hlsl_offset_dim_count(object_type->sampler_dim);
+ struct hlsl_resource_load_params load_params = { 0 };
+ const struct hlsl_type *sampler_type;
+ struct hlsl_ir_node *load;
+
+ if (object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS
+ || object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY)
+ {
+ return raise_invalid_method_object_type(ctx, object_type, name, loc);
+ }
+
+ if (!strcmp(name, "SampleCmpLevelZero"))
+ load_params.type = HLSL_RESOURCE_SAMPLE_CMP_LZ;
+ else
+ load_params.type = HLSL_RESOURCE_SAMPLE_CMP;
+
+ if (params->args_count < 3 || params->args_count > 5 + !!offset_dim)
+ {
+ hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
+ "Wrong number of arguments to method '%s': expected from 3 to %u, but got %u.",
+ name, 5 + !!offset_dim, params->args_count);
+ return false;
+ }
+
+ sampler_type = params->args[0]->data_type;
+ if (sampler_type->class != HLSL_CLASS_OBJECT || sampler_type->base_type != HLSL_TYPE_SAMPLER
+ || sampler_type->sampler_dim != HLSL_SAMPLER_DIM_COMPARISON)
+ {
+ struct vkd3d_string_buffer *string;
+
+ if ((string = hlsl_type_to_string(ctx, sampler_type)))
+ hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "Wrong type for argument 0 of %s(): expected 'SamplerComparisonState', but got '%s'.",
+ name, string->buffer);
+ hlsl_release_string_buffer(ctx, string);
+ return false;
+ }
+
+ if (!(load_params.coords = add_implicit_conversion(ctx, instrs, params->args[1],
+ hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, sampler_dim), loc)))
+ return false;
+
+ if (!(load_params.cmp = add_implicit_conversion(ctx, instrs, params->args[2],
+ hlsl_get_scalar_type(ctx, HLSL_TYPE_FLOAT), loc)))
+ load_params.cmp = params->args[2];
+
+ if (offset_dim && params->args_count > 3)
+ {
+ if (!(load_params.texel_offset = add_implicit_conversion(ctx, instrs, params->args[2],
+ hlsl_get_vector_type(ctx, HLSL_TYPE_INT, offset_dim), loc)))
+ return false;
+ }
+
+ if (params->args_count > 3 + !!offset_dim)
+ hlsl_fixme(ctx, loc, "%s() clamp parameter.", name);
+ if (params->args_count > 4 + !!offset_dim)
+ hlsl_fixme(ctx, loc, "Tiled resource status argument.");
+
+ load_params.format = object_type->e.resource_format;
+ load_params.resource = object;
+ load_params.sampler = params->args[0];
+
+ if (!(load = hlsl_new_resource_load(ctx, &load_params, loc)))
+ return false;
+ list_add_tail(instrs, &load->entry);
+
+ return true;
+}
+
static bool add_gather_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *object,
const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
@@ -3843,6 +3941,14 @@ static bool add_gather_method_call(struct hlsl_ctx *ctx, struct list *instrs, st
struct hlsl_ir_node *load;
unsigned int read_channel;
+ if (object_type->sampler_dim != HLSL_SAMPLER_DIM_2D
+ && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DARRAY
+ && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBE
+ && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBEARRAY)
+ {
+ return raise_invalid_method_object_type(ctx, object_type, name, loc);
+ }
+
if (!strcmp(name, "GatherGreen"))
{
load_params.type = HLSL_RESOURCE_GATHER_GREEN;
@@ -3940,6 +4046,12 @@ static bool add_sample_lod_method_call(struct hlsl_ctx *ctx, struct list *instrs
const struct hlsl_type *sampler_type;
struct hlsl_ir_node *load;
+ if (object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS
+ || object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY)
+ {
+ return raise_invalid_method_object_type(ctx, object_type, name, loc);
+ }
+
if (!strcmp(name, "SampleLevel"))
load_params.type = HLSL_RESOURCE_SAMPLE_LOD;
else
@@ -4004,6 +4116,12 @@ static bool add_sample_grad_method_call(struct hlsl_ctx *ctx, struct list *instr
const struct hlsl_type *sampler_type;
struct hlsl_ir_node *load;
+ if (object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS
+ || object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY)
+ {
+ return raise_invalid_method_object_type(ctx, object_type, name, loc);
+ }
+
load_params.type = HLSL_RESOURCE_SAMPLE_GRAD;
if (params->args_count < 4 || params->args_count > 5 + !!offset_dim)
@@ -4059,10 +4177,42 @@ static bool add_sample_grad_method_call(struct hlsl_ctx *ctx, struct list *instr
return true;
}
+static const struct method_function
+{
+ const char *name;
+ bool (*handler)(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *object,
+ const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc);
+}
+object_methods[] =
+{
+ { "Gather", add_gather_method_call },
+ { "GatherAlpha", add_gather_method_call },
+ { "GatherBlue", add_gather_method_call },
+ { "GatherGreen", add_gather_method_call },
+ { "GatherRed", add_gather_method_call },
+
+ { "Load", add_load_method_call },
+
+ { "Sample", add_sample_method_call },
+ { "SampleBias", add_sample_lod_method_call },
+ { "SampleCmp", add_sample_cmp_method_call },
+ { "SampleCmpLevelZero", add_sample_cmp_method_call },
+ { "SampleGrad", add_sample_grad_method_call },
+ { "SampleLevel", add_sample_lod_method_call },
+};
+
+static int object_method_function_name_compare(const void *a, const void *b)
+{
+ const struct method_function *func = b;
+
+ return strcmp(a, func->name);
+}
+
static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *object,
const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
const struct hlsl_type *object_type = object->data_type;
+ const struct method_function *method;
if (object_type->class != HLSL_CLASS_OBJECT || object_type->base_type != HLSL_TYPE_TEXTURE
|| object_type->sampler_dim == HLSL_SAMPLER_DIM_GENERIC)
@@ -4076,54 +4226,14 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
return false;
}
- if (!strcmp(name, "Load")
- && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBE
- && object_type->sampler_dim != HLSL_SAMPLER_DIM_CUBEARRAY)
- {
- return add_load_method_call(ctx, instrs, object, name, params, loc);
- }
- else if (!strcmp(name, "Sample")
- && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMS
- && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMSARRAY)
- {
- return add_sample_method_call(ctx, instrs, object, name, params, loc);
- }
- else if ((!strcmp(name, "Gather") || !strcmp(name, "GatherRed") || !strcmp(name, "GatherBlue")
- || !strcmp(name, "GatherGreen") || !strcmp(name, "GatherAlpha"))
- && (object_type->sampler_dim == HLSL_SAMPLER_DIM_2D
- || object_type->sampler_dim == HLSL_SAMPLER_DIM_2DARRAY
- || object_type->sampler_dim == HLSL_SAMPLER_DIM_CUBE
- || object_type->sampler_dim == HLSL_SAMPLER_DIM_CUBEARRAY))
- {
- return add_gather_method_call(ctx, instrs, object, name, params, loc);
- }
- else if (!strcmp(name, "SampleLevel")
- && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMS
- && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMSARRAY)
- {
- return add_sample_lod_method_call(ctx, instrs, object, name, params, loc);
- }
- else if (!strcmp(name, "SampleBias")
- && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMS
- && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMSARRAY)
- {
- return add_sample_lod_method_call(ctx, instrs, object, name, params, loc);
- }
- else if (!strcmp(name, "SampleGrad")
- && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMS
- && object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMSARRAY)
+ if ((method = bsearch(name, object_methods, ARRAY_SIZE(object_methods),
+ sizeof(*method), object_method_function_name_compare)))
{
- return add_sample_grad_method_call(ctx, instrs, object, name, params, loc);
+ return method->handler(ctx, instrs, object, name, params, loc);
}
else
{
- struct vkd3d_string_buffer *string;
-
- if ((string = hlsl_type_to_string(ctx, object_type)))
- hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED,
- "Method '%s' is not defined on type '%s'.", name, string->buffer);
- hlsl_release_string_buffer(ctx, string);
- return false;
+ return raise_invalid_method_object_type(ctx, object_type, name, loc);
}
}
@@ -5114,6 +5224,10 @@ type_no_void:
{
$$ = ctx->builtin_types.sampler[HLSL_SAMPLER_DIM_GENERIC];
}
+ | KW_SAMPLERCOMPARISONSTATE
+ {
+ $$ = ctx->builtin_types.sampler[HLSL_SAMPLER_DIM_COMPARISON];
+ }
| KW_SAMPLER1D
{
$$ = ctx->builtin_types.sampler[HLSL_SAMPLER_DIM_1D];
diff --git a/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c
index bbb5223b1ec..2b6c595a15d 100644
--- a/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c
@@ -2680,6 +2680,8 @@ static void compute_liveness_recurse(struct hlsl_block *block, unsigned int loop
load->ddy.node->last_read = last_read;
if (load->sample_index.node)
load->sample_index.node->last_read = last_read;
+ if (load->cmp.node)
+ load->cmp.node->last_read = last_read;
break;
}
case HLSL_IR_RESOURCE_STORE:
@@ -3002,6 +3004,10 @@ static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx,
LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry)
{
+ /* In SM4 all constants are inlined. */
+ if (ctx->profile->major_version >= 4 && instr->type == HLSL_IR_CONSTANT)
+ continue;
+
if (!instr->reg.allocated && instr->last_read)
{
instr->reg = allocate_numeric_registers_for_type(ctx, allocator, instr->index, instr->last_read,
diff --git a/libs/vkd3d/libs/vkd3d-shader/preproc.l b/libs/vkd3d/libs/vkd3d-shader/preproc.l
index 8e35e3555ba..94079696280 100644
--- a/libs/vkd3d/libs/vkd3d-shader/preproc.l
+++ b/libs/vkd3d/libs/vkd3d-shader/preproc.l
@@ -20,6 +20,7 @@
%{
+#include "preproc.h"
#include "preproc.tab.h"
#undef ERROR /* defined in wingdi.h */
diff --git a/libs/vkd3d/libs/vkd3d-shader/tpf.c b/libs/vkd3d/libs/vkd3d-shader/tpf.c
index 2166eb41ac2..60948d6498b 100644
--- a/libs/vkd3d/libs/vkd3d-shader/tpf.c
+++ b/libs/vkd3d/libs/vkd3d-shader/tpf.c
@@ -3512,16 +3512,6 @@ static void sm4_dst_from_node(struct sm4_dst_register *dst, const struct hlsl_ir
sm4_register_from_node(&dst->reg, &dst->writemask, &swizzle_type, instr);
}
-static void sm4_src_from_node(struct sm4_src_register *src,
- const struct hlsl_ir_node *instr, unsigned int map_writemask)
-{
- unsigned int writemask;
-
- sm4_register_from_node(&src->reg, &writemask, &src->swizzle_type, instr);
- if (src->swizzle_type == VKD3D_SM4_SWIZZLE_VEC4)
- src->swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), map_writemask);
-}
-
static void sm4_src_from_constant_value(struct sm4_src_register *src,
const struct hlsl_constant_value *value, unsigned int width, unsigned int map_writemask)
{
@@ -3545,6 +3535,24 @@ static void sm4_src_from_constant_value(struct sm4_src_register *src,
}
}
+static void sm4_src_from_node(struct sm4_src_register *src,
+ const struct hlsl_ir_node *instr, unsigned int map_writemask)
+{
+ unsigned int writemask;
+
+ if (instr->type == HLSL_IR_CONSTANT)
+ {
+ struct hlsl_ir_constant *constant = hlsl_ir_constant(instr);
+
+ sm4_src_from_constant_value(src, &constant->value, instr->data_type->dimx, map_writemask);
+ return;
+ }
+
+ sm4_register_from_node(&src->reg, &writemask, &src->swizzle_type, instr);
+ if (src->swizzle_type == VKD3D_SM4_SWIZZLE_VEC4)
+ src->swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), map_writemask);
+}
+
static uint32_t sm4_encode_register(const struct sm4_register *reg)
{
return (reg->type << VKD3D_SM4_REGISTER_TYPE_SHIFT)
@@ -3680,23 +3688,24 @@ static void write_sm4_dcl_constant_buffer(struct vkd3d_bytecode_buffer *buffer,
static void write_sm4_dcl_samplers(struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_var *var)
{
unsigned int i, count = var->data_type->reg_size[HLSL_REGSET_SAMPLERS];
- struct sm4_instruction instr;
+ struct sm4_instruction instr =
+ {
+ .opcode = VKD3D_SM4_OP_DCL_SAMPLER,
+
+ .dsts[0].reg.type = VKD3D_SM4_RT_SAMPLER,
+ .dsts[0].reg.idx_count = 1,
+ .dst_count = 1,
+ };
+
+ if (var->data_type->sampler_dim == HLSL_SAMPLER_DIM_COMPARISON)
+ instr.opcode |= VKD3D_SM4_SAMPLER_COMPARISON << VKD3D_SM4_SAMPLER_MODE_SHIFT;
for (i = 0; i < count; ++i)
{
if (!var->objects_usage[HLSL_REGSET_SAMPLERS][i].used)
continue;
- instr = (struct sm4_instruction)
- {
- .opcode = VKD3D_SM4_OP_DCL_SAMPLER,
-
- .dsts[0].reg.type = VKD3D_SM4_RT_SAMPLER,
- .dsts[0].reg.idx = {var->regs[HLSL_REGSET_SAMPLERS].id + i},
- .dsts[0].reg.idx_count = 1,
- .dst_count = 1,
- };
-
+ instr.dsts[0].reg.idx[0] = var->regs[HLSL_REGSET_SAMPLERS].id + i;
write_sm4_instruction(buffer, &instr);
}
}
@@ -3994,24 +4003,6 @@ static void write_sm4_binary_op_with_two_destinations(struct vkd3d_bytecode_buff
write_sm4_instruction(buffer, &instr);
}
-static void write_sm4_constant(struct hlsl_ctx *ctx,
- struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_constant *constant)
-{
- const unsigned int dimx = constant->node.data_type->dimx;
- struct sm4_instruction instr;
-
- memset(&instr, 0, sizeof(instr));
- instr.opcode = VKD3D_SM4_OP_MOV;
-
- sm4_dst_from_node(&instr.dsts[0], &constant->node);
- instr.dst_count = 1;
-
- sm4_src_from_constant_value(&instr.srcs[0], &constant->value, dimx, instr.dsts[0].writemask);
- instr.src_count = 1,
-
- write_sm4_instruction(buffer, &instr);
-}
-
static void write_sm4_ld(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer,
const struct hlsl_type *resource_type, const struct hlsl_ir_node *dst,
const struct hlsl_deref *resource, const struct hlsl_ir_node *coords,
@@ -4108,6 +4099,14 @@ static void write_sm4_sample(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer
instr.opcode = VKD3D_SM4_OP_SAMPLE;
break;
+ case HLSL_RESOURCE_SAMPLE_CMP:
+ instr.opcode = VKD3D_SM4_OP_SAMPLE_C;
+ break;
+
+ case HLSL_RESOURCE_SAMPLE_CMP_LZ:
+ instr.opcode = VKD3D_SM4_OP_SAMPLE_C_LZ;
+ break;
+
case HLSL_RESOURCE_SAMPLE_LOD:
instr.opcode = VKD3D_SM4_OP_SAMPLE_LOD;
break;
@@ -4154,6 +4153,12 @@ static void write_sm4_sample(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer
sm4_src_from_node(&instr.srcs[4], load->ddy.node, VKD3DSP_WRITEMASK_ALL);
instr.src_count += 2;
}
+ else if (load->load_type == HLSL_RESOURCE_SAMPLE_CMP
+ || load->load_type == HLSL_RESOURCE_SAMPLE_CMP_LZ)
+ {
+ sm4_src_from_node(&instr.srcs[3], load->cmp.node, VKD3DSP_WRITEMASK_ALL);
+ ++instr.src_count;
+ }
write_sm4_instruction(buffer, &instr);
}
@@ -4952,6 +4957,8 @@ static void write_sm4_resource_load(struct hlsl_ctx *ctx,
break;
case HLSL_RESOURCE_SAMPLE:
+ case HLSL_RESOURCE_SAMPLE_CMP:
+ case HLSL_RESOURCE_SAMPLE_CMP_LZ:
case HLSL_RESOURCE_SAMPLE_LOD:
case HLSL_RESOURCE_SAMPLE_LOD_BIAS:
case HLSL_RESOURCE_SAMPLE_GRAD:
@@ -5072,16 +5079,19 @@ static void write_sm4_block(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *
}
assert(instr->data_type->class == HLSL_CLASS_SCALAR || instr->data_type->class == HLSL_CLASS_VECTOR);
+
+ if (!instr->reg.allocated)
+ {
+ assert(instr->type == HLSL_IR_CONSTANT);
+ continue;
+ }
}
switch (instr->type)
{
case HLSL_IR_CALL:
- vkd3d_unreachable();
-
case HLSL_IR_CONSTANT:
- write_sm4_constant(ctx, buffer, hlsl_ir_constant(instr));
- break;
+ vkd3d_unreachable();
case HLSL_IR_EXPR:
write_sm4_expr(ctx, buffer, hlsl_ir_expr(instr));
--
2.40.1

View File

@ -1,39 +0,0 @@
From 0c66ff2fbfc263e55ebd008772f56e4f432e32a9 Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Date: Wed, 7 Jun 2023 08:12:13 +1000
Subject: [PATCH] Update vkd3d to 82ddc6b417b79919f3e730ef3f2e167ab8462010
---
libs/vkd3d/libs/vkd3d-shader/d3d_asm.c | 2 +-
libs/vkd3d/libs/vkd3d-shader/hlsl.y | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d/libs/vkd3d-shader/d3d_asm.c b/libs/vkd3d/libs/vkd3d-shader/d3d_asm.c
index 3357b4505c0..0a821b5c878 100644
--- a/libs/vkd3d/libs/vkd3d-shader/d3d_asm.c
+++ b/libs/vkd3d/libs/vkd3d-shader/d3d_asm.c
@@ -646,7 +646,7 @@ static void shader_dump_decl_usage(struct vkd3d_d3d_asm_compiler *compiler,
break;
case VKD3D_SHADER_RESOURCE_TEXTURE_3D:
- shader_addline(buffer, "_3d");
+ shader_addline(buffer, "_volume");
break;
case VKD3D_SHADER_RESOURCE_TEXTURE_CUBE:
diff --git a/libs/vkd3d/libs/vkd3d-shader/hlsl.y b/libs/vkd3d/libs/vkd3d-shader/hlsl.y
index cf483d82c65..30d0975102f 100644
--- a/libs/vkd3d/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d/libs/vkd3d-shader/hlsl.y
@@ -5242,7 +5242,7 @@ type_no_void:
}
| KW_SAMPLERCUBE
{
- $$ = ctx->builtin_types.sampler[HLSL_SAMPLER_DIM_3D];
+ $$ = ctx->builtin_types.sampler[HLSL_SAMPLER_DIM_CUBE];
}
| KW_TEXTURE
{
--
2.40.1

View File

@ -1,336 +0,0 @@
From 65a602939e9306618d1ec33d19b217b869638beb Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Date: Thu, 8 Jun 2023 14:11:22 +1000
Subject: [PATCH] Updated vkd3d to ebf7573571d4bfcd3f38846886106f204fd7f0e8
---
libs/vkd3d/libs/vkd3d-shader/hlsl.c | 13 ++
libs/vkd3d/libs/vkd3d-shader/hlsl.h | 2 +
libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c | 209 ++++++++++++++++----
3 files changed, 191 insertions(+), 33 deletions(-)
diff --git a/libs/vkd3d/libs/vkd3d-shader/hlsl.c b/libs/vkd3d/libs/vkd3d-shader/hlsl.c
index 152ec6275eb..f1edfa5e625 100644
--- a/libs/vkd3d/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d/libs/vkd3d-shader/hlsl.c
@@ -1287,6 +1287,19 @@ struct hlsl_ir_load *hlsl_new_load_index(struct hlsl_ctx *ctx, const struct hlsl
return load;
}
+struct hlsl_ir_load *hlsl_new_load_parent(struct hlsl_ctx *ctx, const struct hlsl_deref *deref,
+ const struct vkd3d_shader_location *loc)
+{
+ /* This deref can only exists temporarily because it is not the real owner of its members. */
+ struct hlsl_deref tmp_deref;
+
+ assert(deref->path_len >= 1);
+
+ tmp_deref = *deref;
+ tmp_deref.path_len = deref->path_len - 1;
+ return hlsl_new_load_index(ctx, &tmp_deref, NULL, loc);
+}
+
struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var,
const struct vkd3d_shader_location *loc)
{
diff --git a/libs/vkd3d/libs/vkd3d-shader/hlsl.h b/libs/vkd3d/libs/vkd3d-shader/hlsl.h
index 6b79c582f55..14037a4a96f 100644
--- a/libs/vkd3d/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d/libs/vkd3d-shader/hlsl.h
@@ -1129,6 +1129,8 @@ struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ctx *ctx, struct hlsl_ir_var
const struct vkd3d_shader_location *loc);
struct hlsl_ir_load *hlsl_new_load_index(struct hlsl_ctx *ctx, const struct hlsl_deref *deref,
struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc);
+struct hlsl_ir_load *hlsl_new_load_parent(struct hlsl_ctx *ctx, const struct hlsl_deref *deref,
+ const struct vkd3d_shader_location *loc);
struct hlsl_ir_node *hlsl_new_load_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
const struct hlsl_deref *deref, unsigned int comp, const struct vkd3d_shader_location *loc);
diff --git a/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c
index 2b6c595a15d..72ab27d3b80 100644
--- a/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d/libs/vkd3d-shader/hlsl_codegen.c
@@ -123,15 +123,14 @@ static struct hlsl_ir_node *new_offset_instr_from_deref(struct hlsl_ctx *ctx, st
}
/* TODO: remove when no longer needed, only used for transform_deref_paths_into_offsets() */
-static void replace_deref_path_with_offset(struct hlsl_ctx *ctx, struct hlsl_deref *deref,
+static bool replace_deref_path_with_offset(struct hlsl_ctx *ctx, struct hlsl_deref *deref,
struct hlsl_ir_node *instr)
{
const struct hlsl_type *type;
struct hlsl_ir_node *offset;
struct hlsl_block block;
- if (!deref->var)
- return;
+ assert(deref->var);
/* register offsets shouldn't be used before this point is reached. */
assert(!deref->offset.node);
@@ -143,45 +142,19 @@ static void replace_deref_path_with_offset(struct hlsl_ctx *ctx, struct hlsl_der
if (type->class == HLSL_CLASS_STRUCT || type->class == HLSL_CLASS_ARRAY)
{
hlsl_cleanup_deref(deref);
- return;
+ return true;
}
deref->offset_regset = hlsl_type_get_regset(type);
if (!(offset = new_offset_instr_from_deref(ctx, &block, deref, &instr->loc)))
- return;
+ return false;
list_move_before(&instr->entry, &block.instrs);
hlsl_cleanup_deref(deref);
hlsl_src_from_node(&deref->offset, offset);
-}
-/* TODO: remove when no longer needed. */
-static bool transform_deref_paths_into_offsets(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
-{
- switch(instr->type)
- {
- case HLSL_IR_LOAD:
- replace_deref_path_with_offset(ctx, &hlsl_ir_load(instr)->src, instr);
- return true;
-
- case HLSL_IR_STORE:
- replace_deref_path_with_offset(ctx, &hlsl_ir_store(instr)->lhs, instr);
- return true;
-
- case HLSL_IR_RESOURCE_LOAD:
- replace_deref_path_with_offset(ctx, &hlsl_ir_resource_load(instr)->resource, instr);
- replace_deref_path_with_offset(ctx, &hlsl_ir_resource_load(instr)->sampler, instr);
- return true;
-
- case HLSL_IR_RESOURCE_STORE:
- replace_deref_path_with_offset(ctx, &hlsl_ir_resource_store(instr)->resource, instr);
- return true;
-
- default:
- return false;
- }
- return false;
+ return true;
}
/* Split uniforms into two variables representing the constant and temp
@@ -600,6 +573,44 @@ bool hlsl_transform_ir(struct hlsl_ctx *ctx, bool (*func)(struct hlsl_ctx *ctx,
return progress;
}
+static bool transform_instr_derefs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
+{
+ bool res;
+ bool (*func)(struct hlsl_ctx *ctx, struct hlsl_deref *, struct hlsl_ir_node *) = context;
+
+ switch(instr->type)
+ {
+ case HLSL_IR_LOAD:
+ res = func(ctx, &hlsl_ir_load(instr)->src, instr);
+ return res;
+
+ case HLSL_IR_STORE:
+ res = func(ctx, &hlsl_ir_store(instr)->lhs, instr);
+ return res;
+
+ case HLSL_IR_RESOURCE_LOAD:
+ res = func(ctx, &hlsl_ir_resource_load(instr)->resource, instr);
+ if (hlsl_ir_resource_load(instr)->sampler.var)
+ res |= func(ctx, &hlsl_ir_resource_load(instr)->sampler, instr);
+ return res;
+
+ case HLSL_IR_RESOURCE_STORE:
+ res = func(ctx, &hlsl_ir_resource_store(instr)->resource, instr);
+ return res;
+
+ default:
+ return false;
+ }
+ return false;
+}
+
+static bool transform_derefs(struct hlsl_ctx *ctx,
+ bool (*func)(struct hlsl_ctx *ctx, struct hlsl_deref *, struct hlsl_ir_node *),
+ struct hlsl_block *block)
+{
+ return hlsl_transform_ir(ctx, transform_instr_derefs, block, func);
+}
+
struct recursive_call_ctx
{
const struct hlsl_ir_function_decl **backtrace;
@@ -1981,6 +1992,81 @@ static bool remove_trivial_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *i
return true;
}
+static bool lower_nonconstant_vector_derefs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
+{
+ struct hlsl_ir_node *idx;
+ struct hlsl_deref *deref;
+ struct hlsl_type *type;
+ unsigned int i;
+
+ if (instr->type != HLSL_IR_LOAD)
+ return false;
+
+ deref = &hlsl_ir_load(instr)->src;
+ assert(deref->var);
+
+ if (deref->path_len == 0)
+ return false;
+
+ type = deref->var->data_type;
+ for (i = 0; i < deref->path_len - 1; ++i)
+ type = hlsl_get_element_type_from_path_index(ctx, type, deref->path[i].node);
+
+ idx = deref->path[deref->path_len - 1].node;
+
+ if (type->class == HLSL_CLASS_VECTOR && idx->type != HLSL_IR_CONSTANT)
+ {
+ struct hlsl_ir_node *eq, *swizzle, *dot, *operands[HLSL_MAX_OPERANDS] = {0};
+ struct hlsl_ir_load *vector_load;
+ struct hlsl_ir_constant *c;
+ enum hlsl_ir_expr_op op;
+
+ if (!(vector_load = hlsl_new_load_parent(ctx, deref, &instr->loc)))
+ return false;
+ list_add_before(&instr->entry, &vector_load->node.entry);
+
+ if (!(swizzle = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(X, X, X, X), type->dimx, idx, &instr->loc)))
+ return false;
+ list_add_before(&instr->entry, &swizzle->entry);
+
+ if (!(c = hlsl_new_constant(ctx, hlsl_get_vector_type(ctx, HLSL_TYPE_UINT, type->dimx), &instr->loc)))
+ return false;
+ c->value.u[0].u = 0;
+ c->value.u[1].u = 1;
+ c->value.u[2].u = 2;
+ c->value.u[3].u = 3;
+ list_add_before(&instr->entry, &c->node.entry);
+
+ operands[0] = swizzle;
+ operands[1] = &c->node;
+ if (!(eq = hlsl_new_expr(ctx, HLSL_OP2_EQUAL, operands,
+ hlsl_get_vector_type(ctx, HLSL_TYPE_BOOL, type->dimx), &instr->loc)))
+ return false;
+ list_add_before(&instr->entry, &eq->entry);
+
+ if (!(eq = hlsl_new_cast(ctx, eq, type, &instr->loc)))
+ return false;
+ list_add_before(&instr->entry, &eq->entry);
+
+ op = HLSL_OP2_DOT;
+ if (type->dimx == 1)
+ op = type->base_type == HLSL_TYPE_BOOL ? HLSL_OP2_LOGIC_AND : HLSL_OP2_MUL;
+
+ /* Note: We may be creating a DOT for bool vectors here, which we need to lower to
+ * LOGIC_OR + LOGIC_AND. */
+ operands[0] = &vector_load->node;
+ operands[1] = eq;
+ if (!(dot = hlsl_new_expr(ctx, op, operands, instr->data_type, &instr->loc)))
+ return false;
+ list_add_before(&instr->entry, &dot->entry);
+ hlsl_replace_node(instr, dot);
+
+ return true;
+ }
+
+ return false;
+}
+
/* Lower DIV to RCP + MUL. */
static bool lower_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
@@ -2378,6 +2464,58 @@ static bool lower_int_abs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void
return true;
}
+static bool lower_int_dot(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
+{
+ struct hlsl_ir_node *arg1, *arg2, *mult, *comps[4] = {0}, *res;
+ struct hlsl_type *type = instr->data_type;
+ struct hlsl_ir_expr *expr;
+ unsigned int i, dimx;
+ bool is_bool;
+
+ if (instr->type != HLSL_IR_EXPR)
+ return false;
+ expr = hlsl_ir_expr(instr);
+
+ if (expr->op != HLSL_OP2_DOT)
+ return false;
+
+ if (type->base_type == HLSL_TYPE_INT || type->base_type == HLSL_TYPE_UINT
+ || type->base_type == HLSL_TYPE_BOOL)
+ {
+ arg1 = expr->operands[0].node;
+ arg2 = expr->operands[1].node;
+ assert(arg1->data_type->dimx == arg2->data_type->dimx);
+ dimx = arg1->data_type->dimx;
+ is_bool = type->base_type == HLSL_TYPE_BOOL;
+
+ if (!(mult = hlsl_new_binary_expr(ctx, is_bool ? HLSL_OP2_LOGIC_AND : HLSL_OP2_MUL, arg1, arg2)))
+ return false;
+ list_add_before(&instr->entry, &mult->entry);
+
+ for (i = 0; i < dimx; ++i)
+ {
+ unsigned int s = hlsl_swizzle_from_writemask(1 << i);
+
+ if (!(comps[i] = hlsl_new_swizzle(ctx, s, 1, mult, &instr->loc)))
+ return false;
+ list_add_before(&instr->entry, &comps[i]->entry);
+ }
+
+ res = comps[0];
+ for (i = 1; i < dimx; ++i)
+ {
+ if (!(res = hlsl_new_binary_expr(ctx, is_bool ? HLSL_OP2_LOGIC_OR : HLSL_OP2_ADD, res, comps[i])))
+ return false;
+ list_add_before(&instr->entry, &res->entry);
+ }
+
+ hlsl_replace_node(instr, res);
+ return true;
+ }
+
+ return false;
+}
+
static bool lower_float_modulus(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_ir_node *arg1, *arg2, *mul1, *neg1, *ge, *neg2, *div, *mul2, *frc, *cond;
@@ -3925,6 +4063,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
hlsl_transform_ir(ctx, lower_narrowing_casts, body, NULL);
hlsl_transform_ir(ctx, lower_casts_to_bool, body, NULL);
+ hlsl_transform_ir(ctx, lower_int_dot, body, NULL);
hlsl_transform_ir(ctx, lower_int_division, body, NULL);
hlsl_transform_ir(ctx, lower_int_modulus, body, NULL);
hlsl_transform_ir(ctx, lower_int_abs, body, NULL);
@@ -3939,6 +4078,10 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
}
while (progress);
+ hlsl_transform_ir(ctx, lower_nonconstant_vector_derefs, body, NULL);
+ hlsl_transform_ir(ctx, lower_casts_to_bool, body, NULL);
+ hlsl_transform_ir(ctx, lower_int_dot, body, NULL);
+
if (profile->major_version < 4)
{
hlsl_transform_ir(ctx, lower_division, body, NULL);
@@ -3956,7 +4099,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
hlsl_transform_ir(ctx, track_object_components_usage, body, NULL);
/* TODO: move forward, remove when no longer needed */
- hlsl_transform_ir(ctx, transform_deref_paths_into_offsets, body, NULL);
+ transform_derefs(ctx, replace_deref_path_with_offset, body);
while (hlsl_transform_ir(ctx, hlsl_fold_constant_exprs, body, NULL));
do
--
2.40.1