From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 3 +++ libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 4 ++++ 3 files changed, 8 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index edd99238d..01a95168a 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -3516,6 +3516,9 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) type->e.version = technique_types[i].version; hlsl_scope_add_type(ctx->globals, type); } + + type = hlsl_new_type(ctx, "RenderTargetView", HLSL_CLASS_OBJECT, HLSL_TYPE_RENDERTARGETVIEW, 1, 1); + hlsl_scope_add_type(ctx->globals, type); }
static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const struct vkd3d_shader_compile_info *compile_info, diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 0b9218ba7..cc5aaf8a8 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -96,6 +96,7 @@ enum hlsl_base_type HLSL_TYPE_PIXELSHADER, HLSL_TYPE_VERTEXSHADER, HLSL_TYPE_PASS, + HLSL_TYPE_RENDERTARGETVIEW, HLSL_TYPE_TECHNIQUE, HLSL_TYPE_EFFECT_GROUP, HLSL_TYPE_STRING, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 000e14b6d..e44466327 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -6294,6 +6294,10 @@ type_no_void: hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_REDEFINED, ""%s" redefined as a structure.", $2); vkd3d_free($2); } + | KW_RENDERTARGETVIEW + { + $$ = hlsl_get_type(ctx->cur_scope, "RenderTargetView", true, true); + }
type: type_no_void
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- libs/vkd3d-shader/fx.c | 94 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 84 insertions(+), 10 deletions(-)
diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index 11dee4ba9..7830ba6e4 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -83,6 +83,7 @@ struct fx_write_context uint32_t group_count; uint32_t buffer_count; uint32_t numeric_variable_count; + uint32_t object_variable_count; int status;
const struct fx_write_context_ops *ops; @@ -392,9 +393,21 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co } else if (type->class == HLSL_CLASS_OBJECT) { - FIXME("Object types are not supported.\n"); - set_status(fx, VKD3D_ERROR_NOT_IMPLEMENTED); - return 0; + static const uint32_t object_type[] = + { + [HLSL_TYPE_RENDERTARGETVIEW] = 19, + }; + + switch (type->base_type) + { + case HLSL_TYPE_RENDERTARGETVIEW: + put_u32_unaligned(buffer, object_type[type->base_type]); + break; + default: + FIXME("Object type %u is not supported.\n", type->base_type); + set_status(fx, VKD3D_ERROR_NOT_IMPLEMENTED); + return 0; + } } else /* Numeric type */ { @@ -588,12 +601,12 @@ static const struct fx_write_context_ops fx_4_ops = .write_pass = write_fx_4_pass, };
-static void write_fx_4_variable(struct hlsl_ir_var *var, struct fx_write_context *fx) +static void write_fx_4_numeric_variable(struct hlsl_ir_var *var, struct fx_write_context *fx) { struct vkd3d_bytecode_buffer *buffer = &fx->structured; uint32_t semantic_offset, flags = 0; uint32_t name_offset, type_offset; - enum fx_4_variable_flags + enum fx_4_numeric_variable_flags { HAS_EXPLICIT_BIND_POINT = 0x4, }; @@ -618,6 +631,29 @@ static void write_fx_4_variable(struct hlsl_ir_var *var, struct fx_write_context /* FIXME: write annotations */ }
+static void write_fx_4_object_variable(struct hlsl_ir_var *var, struct fx_write_context *fx) +{ + struct vkd3d_bytecode_buffer *buffer = &fx->structured; + uint32_t semantic_offset, bind_point = ~0u; + uint32_t name_offset, type_offset; + + if (var->reg_reservation.reg_type) + bind_point = var->reg_reservation.reg_index; + + type_offset = write_type(var->data_type, fx); + name_offset = write_string(var->name, fx); + semantic_offset = write_string(var->semantic.name, fx); + + put_u32(buffer, name_offset); + put_u32(buffer, type_offset); + + semantic_offset = put_u32(buffer, semantic_offset); /* Semantic */ + put_u32(buffer, bind_point); /* Explicit bind point */ + + put_u32(buffer, 0); /* Annotations count */ + /* FIXME: write annotations */ +} + static void write_fx_4_buffer(struct hlsl_buffer *b, struct fx_write_context *fx) { enum fx_4_buffer_flags @@ -656,7 +692,7 @@ static void write_fx_4_buffer(struct hlsl_buffer *b, struct fx_write_context *fx if (var->buffer != b) continue;
- write_fx_4_variable(var, fx); + write_fx_4_numeric_variable(var, fx); size += get_fx_4_type_size(var->data_type); ++count; } @@ -687,6 +723,44 @@ static void write_buffers(struct fx_write_context *fx) } }
+static bool is_object_variable(const struct hlsl_ir_var *var) +{ + const struct hlsl_type *type = hlsl_get_multiarray_element_type(var->data_type); + + if (type->class != HLSL_CLASS_OBJECT) + return false; + + switch (type->base_type) + { + case HLSL_TYPE_SAMPLER: + case HLSL_TYPE_TEXTURE: + case HLSL_TYPE_UAV: + case HLSL_TYPE_PIXELSHADER: + case HLSL_TYPE_VERTEXSHADER: + case HLSL_TYPE_RENDERTARGETVIEW: + return true; + default: + return false; + } +} + +static void write_objects(struct fx_write_context *fx) +{ + struct hlsl_ir_var *var; + uint32_t count = 0; + + LIST_FOR_EACH_ENTRY(var, &fx->ctx->extern_vars, struct hlsl_ir_var, extern_entry) + { + if (!is_object_variable(var)) + continue; + + write_fx_4_object_variable(var, fx); + ++count; + } + + fx->object_variable_count += count; +} + static int hlsl_fx_4_write(struct hlsl_ctx *ctx, struct vkd3d_shader_code *out) { struct vkd3d_bytecode_buffer buffer = { 0 }; @@ -698,7 +772,7 @@ static int hlsl_fx_4_write(struct hlsl_ctx *ctx, struct vkd3d_shader_code *out) put_u32(&fx.unstructured, 0); /* Empty string placeholder. */
write_buffers(&fx); - /* TODO: objects */ + write_objects(&fx); /* TODO: shared buffers */ /* TODO: shared objects */
@@ -707,7 +781,7 @@ static int hlsl_fx_4_write(struct hlsl_ctx *ctx, struct vkd3d_shader_code *out) put_u32(&buffer, ctx->profile->minor_version == 0 ? 0xfeff1001 : 0xfeff1011); /* Version. */ put_u32(&buffer, fx.buffer_count); /* Buffer count. */ put_u32(&buffer, fx.numeric_variable_count); /* Numeric variable count. */ - put_u32(&buffer, 0); /* Object variable count. */ + put_u32(&buffer, fx.object_variable_count); /* Object variable count. */ put_u32(&buffer, 0); /* Pool buffer count. */ put_u32(&buffer, 0); /* Pool variable count. */ put_u32(&buffer, 0); /* Pool object count. */ @@ -757,7 +831,7 @@ static int hlsl_fx_5_write(struct hlsl_ctx *ctx, struct vkd3d_shader_code *out) put_u32(&fx.unstructured, 0); /* Empty string placeholder. */
write_buffers(&fx); - /* TODO: objects */ + write_objects(&fx); /* TODO: interface variables */
write_groups(&fx); @@ -765,7 +839,7 @@ static int hlsl_fx_5_write(struct hlsl_ctx *ctx, struct vkd3d_shader_code *out) put_u32(&buffer, 0xfeff2001); /* Version. */ put_u32(&buffer, fx.buffer_count); /* Buffer count. */ put_u32(&buffer, fx.numeric_variable_count); /* Numeric variable count. */ - put_u32(&buffer, 0); /* Object variable count. */ + put_u32(&buffer, fx.object_variable_count); /* Object variable count. */ put_u32(&buffer, 0); /* Pool buffer count. */ put_u32(&buffer, 0); /* Pool variable count. */ put_u32(&buffer, 0); /* Pool object count. */
From: Nikolay Sivov nsivov@codeweavers.com
--- libs/vkd3d-shader/fx.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index 7830ba6e4..b7982654c 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -327,6 +327,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co struct vkd3d_bytecode_buffer *buffer = &fx->unstructured; uint32_t name_offset, offset, size, stride, numeric_desc; uint32_t elements_count = 0; + const char *name; static const uint32_t variable_type[] = { [HLSL_CLASS_SCALAR] = 1, @@ -335,6 +336,19 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co [HLSL_CLASS_OBJECT] = 2, [HLSL_CLASS_STRUCT] = 3, }; + static const char * const texture_type_names[] = + { + [HLSL_SAMPLER_DIM_GENERIC] = "texture", + [HLSL_SAMPLER_DIM_1D] = "Texture1D", + [HLSL_SAMPLER_DIM_1DARRAY] = "Texture1DArray", + [HLSL_SAMPLER_DIM_2D] = "Texture2D", + [HLSL_SAMPLER_DIM_2DARRAY] = "Texture2DArray", + [HLSL_SAMPLER_DIM_2DMS] = "Texture2DMS", + [HLSL_SAMPLER_DIM_2DMSARRAY] = "Texture2DMSArray", + [HLSL_SAMPLER_DIM_3D] = "Texture3D", + [HLSL_SAMPLER_DIM_CUBE] = "TextureCube", + [HLSL_SAMPLER_DIM_CUBEARRAY] = "TextureCubeArray", + };
/* Resolve arrays to element type and number of elements. */ if (type->class == HLSL_CLASS_ARRAY) @@ -343,7 +357,12 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co type = hlsl_get_multiarray_element_type(type); }
- name_offset = write_string(type->name, fx); + if (type->base_type == HLSL_TYPE_TEXTURE) + name = texture_type_names[type->sampler_dim]; + else + name = type->name; + + name_offset = write_string(name, fx); offset = put_u32_unaligned(buffer, name_offset);
switch (type->class) @@ -397,12 +416,28 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co { [HLSL_TYPE_RENDERTARGETVIEW] = 19, }; + static const uint32_t texture_type[] = + { + [HLSL_SAMPLER_DIM_GENERIC] = 9, + [HLSL_SAMPLER_DIM_1D] = 10, + [HLSL_SAMPLER_DIM_1DARRAY] = 11, + [HLSL_SAMPLER_DIM_2D] = 12, + [HLSL_SAMPLER_DIM_2DARRAY] = 13, + [HLSL_SAMPLER_DIM_2DMS] = 14, + [HLSL_SAMPLER_DIM_2DMSARRAY] = 15, + [HLSL_SAMPLER_DIM_3D] = 16, + [HLSL_SAMPLER_DIM_CUBE] = 17, + [HLSL_SAMPLER_DIM_CUBEARRAY] = 23, + };
switch (type->base_type) { case HLSL_TYPE_RENDERTARGETVIEW: put_u32_unaligned(buffer, object_type[type->base_type]); break; + case HLSL_TYPE_TEXTURE: + put_u32_unaligned(buffer, texture_type[type->sampler_dim]); + break; default: FIXME("Object type %u is not supported.\n", type->base_type); set_status(fx, VKD3D_ERROR_NOT_IMPLEMENTED);
From: Nikolay Sivov nsivov@codeweavers.com
--- libs/vkd3d-shader/fx.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index b7982654c..93b76728f 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -349,6 +349,16 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co [HLSL_SAMPLER_DIM_CUBE] = "TextureCube", [HLSL_SAMPLER_DIM_CUBEARRAY] = "TextureCubeArray", }; + static const char * const uav_type_names[] = + { + [HLSL_SAMPLER_DIM_1D] = "RWTexture1D", + [HLSL_SAMPLER_DIM_1DARRAY] = "RWTexture1DArray", + [HLSL_SAMPLER_DIM_2D] = "RWTexture2D", + [HLSL_SAMPLER_DIM_2DARRAY] = "RWTexture2DArray", + [HLSL_SAMPLER_DIM_3D] = "RWTexture3D", + [HLSL_SAMPLER_DIM_BUFFER] = "RWBuffer", + [HLSL_SAMPLER_DIM_STRUCTURED_BUFFER] = "RWStructuredBuffer", + };
/* Resolve arrays to element type and number of elements. */ if (type->class == HLSL_CLASS_ARRAY) @@ -359,6 +369,8 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
if (type->base_type == HLSL_TYPE_TEXTURE) name = texture_type_names[type->sampler_dim]; + else if (type->base_type == HLSL_TYPE_UAV) + name = uav_type_names[type->sampler_dim]; else name = type->name;
@@ -429,6 +441,16 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co [HLSL_SAMPLER_DIM_CUBE] = 17, [HLSL_SAMPLER_DIM_CUBEARRAY] = 23, }; + static const uint32_t uav_type[] = + { + [HLSL_SAMPLER_DIM_1D] = 31, + [HLSL_SAMPLER_DIM_1DARRAY] = 32, + [HLSL_SAMPLER_DIM_2D] = 33, + [HLSL_SAMPLER_DIM_2DARRAY] = 34, + [HLSL_SAMPLER_DIM_3D] = 35, + [HLSL_SAMPLER_DIM_BUFFER] = 36, + [HLSL_SAMPLER_DIM_STRUCTURED_BUFFER] = 40, + };
switch (type->base_type) { @@ -438,6 +460,9 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co case HLSL_TYPE_TEXTURE: put_u32_unaligned(buffer, texture_type[type->sampler_dim]); break; + case HLSL_TYPE_UAV: + put_u32_unaligned(buffer, uav_type[type->sampler_dim]); + break; default: FIXME("Object type %u is not supported.\n", type->base_type); set_status(fx, VKD3D_ERROR_NOT_IMPLEMENTED);
From: Nikolay Sivov nsivov@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 7 +++---- libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 01a95168a..a02b412bb 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -3375,7 +3375,7 @@ static void declare_predefined_types(struct hlsl_ctx *ctx)
static const struct { - char name[13]; + char name[20]; enum hlsl_type_class class; enum hlsl_base_type base_type; unsigned int dimx, dimy; @@ -3391,6 +3391,8 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) {"TEXTURE", HLSL_CLASS_OBJECT, HLSL_TYPE_TEXTURE, 1, 1}, {"PIXELSHADER", HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1}, {"VERTEXSHADER", HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1}, + {"RenderTargetView",HLSL_CLASS_OBJECT, HLSL_TYPE_RENDERTARGETVIEW, 1, 1}, + {"DepthStencilView",HLSL_CLASS_OBJECT, HLSL_TYPE_DEPTHSTENCILVIEW, 1, 1}, };
static const struct @@ -3516,9 +3518,6 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) type->e.version = technique_types[i].version; hlsl_scope_add_type(ctx->globals, type); } - - type = hlsl_new_type(ctx, "RenderTargetView", HLSL_CLASS_OBJECT, HLSL_TYPE_RENDERTARGETVIEW, 1, 1); - hlsl_scope_add_type(ctx->globals, type); }
static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const struct vkd3d_shader_compile_info *compile_info, diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index cc5aaf8a8..eea76be76 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -97,6 +97,7 @@ enum hlsl_base_type HLSL_TYPE_VERTEXSHADER, HLSL_TYPE_PASS, HLSL_TYPE_RENDERTARGETVIEW, + HLSL_TYPE_DEPTHSTENCILVIEW, HLSL_TYPE_TECHNIQUE, HLSL_TYPE_EFFECT_GROUP, HLSL_TYPE_STRING, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index e44466327..64a1a1ef7 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -6298,6 +6298,10 @@ type_no_void: { $$ = hlsl_get_type(ctx->cur_scope, "RenderTargetView", true, true); } + | KW_DEPTHSTENCILVIEW + { + $$ = hlsl_get_type(ctx->cur_scope, "DepthStencilView", true, true); + }
type: type_no_void
From: Nikolay Sivov nsivov@codeweavers.com
--- libs/vkd3d-shader/fx.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index 93b76728f..bc70d5220 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -427,6 +427,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co static const uint32_t object_type[] = { [HLSL_TYPE_RENDERTARGETVIEW] = 19, + [HLSL_TYPE_DEPTHSTENCILVIEW] = 20, }; static const uint32_t texture_type[] = { @@ -454,6 +455,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
switch (type->base_type) { + case HLSL_TYPE_DEPTHSTENCILVIEW: case HLSL_TYPE_RENDERTARGETVIEW: put_u32_unaligned(buffer, object_type[type->base_type]); break;
If RenderTargetView is a keyword then perhaps it shouldn't be put in global scope, but rather ctx->builtin_types?
Giovanni Mascellani (@giomasce) commented about libs/vkd3d-shader/hlsl.c:
{"TEXTURE", HLSL_CLASS_OBJECT, HLSL_TYPE_TEXTURE, 1, 1}, {"PIXELSHADER", HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1}, {"VERTEXSHADER", HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1},
{"RenderTargetView",HLSL_CLASS_OBJECT, HLSL_TYPE_RENDERTARGETVIEW, 1, 1},
{"DepthStencilView",HLSL_CLASS_OBJECT, HLSL_TYPE_DEPTHSTENCILVIEW, 1, 1},
Nitpick, but I'd leave a space after the comma. If you want to keep the columns straight (since the last two fields are not aligned anyway) then please reformat the whole table, but to me it's ok to leave them unaligned.
This merge request was approved by Giovanni Mascellani.
On Wed Feb 21 10:56:39 2024 +0000, Zebediah Figura wrote:
If RenderTargetView is a keyword then perhaps it shouldn't be put in global scope, but rather ctx->builtin_types?
I thought those are unrelated. We use builtin_types as a shortcut for frequently used types, that were also added in global scope. Is that not the case?
On Wed Feb 21 10:56:39 2024 +0000, Nikolay Sivov wrote:
I thought those are unrelated. We use builtin_types as a shortcut for frequently used types, that were also added in global scope. Is that not the case?
Putting the type in global scope only makes sense if it can be looked up by name. If it's a keyword then it can't.
I guess there's not really a downside to doing it like this so I won't reject the patch over it.
This merge request was approved by Zebediah Figura.
This merge request was approved by Henri Verbeet.