From 355d4c4a860f47a1b3d722bdaf1f9486df1fd884 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Wed, 7 Aug 2024 19:14:10 -0400 Subject: [PATCH] vkd3d-shader/hlsl: Skip writing string default values. This causes a crash in the native compiler, but can only happen in ps_5_0 were it is possible to declare structs that are both used in the shader and contain strings. struct { float a; string b; } apple = {1, "foobar"}; float4 main() : sv_target { return apple.a; } In our case, hlsl_type_get_component_offset() triggered an assertion failure because it does not expect the string type. So this is replaced by an hlsl_error(). --- libs/vkd3d-shader/tpf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 39b4f795..aec72fc3 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -22,6 +22,7 @@ */ #include "hlsl.h" +#include "vkd3d_shader_private.h" #define SM4_MAX_SRC_COUNT 6 #define SM4_MAX_DST_COUNT 2 @@ -3600,6 +3601,13 @@ static void write_sm4_rdef(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc) unsigned int comp_offset; enum hlsl_regset regset; + if (comp_type->class == HLSL_CLASS_STRING) + { + hlsl_error(ctx, &var->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, + "Cannot write string default value."); + continue; + } + comp_offset = hlsl_type_get_component_offset(ctx, var->data_type, k, ®set); if (regset == HLSL_REGSET_NUMERIC) {