mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/hlsl: Parse string default values.
This commit is contained in:
parent
f8108a4753
commit
094e298c1c
Notes:
Henri Verbeet
2024-08-13 21:26:39 +02:00
Approved-by: Elizabeth Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/988
@ -1830,17 +1830,17 @@ void write_sm1_uniforms(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buff
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_INT:
|
case HLSL_TYPE_INT:
|
||||||
uni.f = var->default_values[k].value.i;
|
uni.f = var->default_values[k].number.i;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_UINT:
|
case HLSL_TYPE_UINT:
|
||||||
case HLSL_TYPE_BOOL:
|
case HLSL_TYPE_BOOL:
|
||||||
uni.f = var->default_values[k].value.u;
|
uni.f = var->default_values[k].number.u;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_HALF:
|
case HLSL_TYPE_HALF:
|
||||||
case HLSL_TYPE_FLOAT:
|
case HLSL_TYPE_FLOAT:
|
||||||
uni.u = var->default_values[k].value.u;
|
uni.u = var->default_values[k].number.u;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1243,7 +1243,7 @@ static uint32_t write_fx_4_default_value(struct hlsl_type *value_type, struct hl
|
|||||||
|
|
||||||
for (j = 0; j < comp_count; ++j)
|
for (j = 0; j < comp_count; ++j)
|
||||||
{
|
{
|
||||||
put_u32_unaligned(buffer, value->value.u);
|
put_u32_unaligned(buffer, value->number.u);
|
||||||
value++;
|
value++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -167,7 +167,14 @@ void hlsl_free_var(struct hlsl_ir_var *decl)
|
|||||||
for (k = 0; k <= HLSL_REGSET_LAST_OBJECT; ++k)
|
for (k = 0; k <= HLSL_REGSET_LAST_OBJECT; ++k)
|
||||||
vkd3d_free((void *)decl->objects_usage[k]);
|
vkd3d_free((void *)decl->objects_usage[k]);
|
||||||
|
|
||||||
|
if (decl->default_values)
|
||||||
|
{
|
||||||
|
unsigned int component_count = hlsl_type_component_count(decl->data_type);
|
||||||
|
|
||||||
|
for (k = 0; k < component_count; ++k)
|
||||||
|
vkd3d_free((void *)decl->default_values[k].string);
|
||||||
vkd3d_free(decl->default_values);
|
vkd3d_free(decl->default_values);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < decl->state_block_count; ++i)
|
for (i = 0; i < decl->state_block_count; ++i)
|
||||||
hlsl_free_state_block(decl->state_blocks[i]);
|
hlsl_free_state_block(decl->state_blocks[i]);
|
||||||
@ -3280,9 +3287,15 @@ void hlsl_dump_var_default_values(const struct hlsl_ir_var *var)
|
|||||||
vkd3d_string_buffer_printf(&buffer, "var \"%s\" default values:", var->name);
|
vkd3d_string_buffer_printf(&buffer, "var \"%s\" default values:", var->name);
|
||||||
for (k = 0; k < component_count; ++k)
|
for (k = 0; k < component_count; ++k)
|
||||||
{
|
{
|
||||||
if (k % 4 == 0)
|
bool is_string = var->default_values[k].string;
|
||||||
|
|
||||||
|
if (k % 4 == 0 || is_string)
|
||||||
vkd3d_string_buffer_printf(&buffer, "\n ");
|
vkd3d_string_buffer_printf(&buffer, "\n ");
|
||||||
vkd3d_string_buffer_printf(&buffer, " 0x%08x", var->default_values[k].value.u);
|
|
||||||
|
if (is_string)
|
||||||
|
vkd3d_string_buffer_printf(&buffer, " %s", debugstr_a(var->default_values[k].string));
|
||||||
|
else
|
||||||
|
vkd3d_string_buffer_printf(&buffer, " 0x%08x", var->default_values[k].number.u);
|
||||||
}
|
}
|
||||||
vkd3d_string_buffer_printf(&buffer, "\n");
|
vkd3d_string_buffer_printf(&buffer, "\n");
|
||||||
|
|
||||||
|
@ -456,8 +456,10 @@ struct hlsl_ir_var
|
|||||||
* This pointer is NULL for others. */
|
* This pointer is NULL for others. */
|
||||||
struct hlsl_default_value
|
struct hlsl_default_value
|
||||||
{
|
{
|
||||||
|
/* Default value, in case the component is a string, othewise it is NULL. */
|
||||||
|
const char *string;
|
||||||
/* Default value, in case the component is a numeric value. */
|
/* Default value, in case the component is a numeric value. */
|
||||||
union hlsl_constant_value_component value;
|
union hlsl_constant_value_component number;
|
||||||
} *default_values;
|
} *default_values;
|
||||||
|
|
||||||
/* A dynamic array containing the state block on the variable's declaration, if any.
|
/* A dynamic array containing the state block on the variable's declaration, if any.
|
||||||
|
@ -598,11 +598,10 @@ static void check_loop_attributes(struct hlsl_ctx *ctx, const struct parse_attri
|
|||||||
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Unroll attribute can't be used with 'fastopt' attribute.");
|
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Unroll attribute can't be used with 'fastopt' attribute.");
|
||||||
}
|
}
|
||||||
|
|
||||||
static union hlsl_constant_value_component evaluate_static_expression(struct hlsl_ctx *ctx,
|
static struct hlsl_default_value evaluate_static_expression(struct hlsl_ctx *ctx,
|
||||||
struct hlsl_block *block, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc)
|
struct hlsl_block *block, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
union hlsl_constant_value_component ret = {0};
|
struct hlsl_default_value ret = {0};
|
||||||
struct hlsl_ir_constant *constant;
|
|
||||||
struct hlsl_ir_node *node;
|
struct hlsl_ir_node *node;
|
||||||
struct hlsl_block expr;
|
struct hlsl_block expr;
|
||||||
struct hlsl_src src;
|
struct hlsl_src src;
|
||||||
@ -654,8 +653,16 @@ static union hlsl_constant_value_component evaluate_static_expression(struct hls
|
|||||||
|
|
||||||
if (node->type == HLSL_IR_CONSTANT)
|
if (node->type == HLSL_IR_CONSTANT)
|
||||||
{
|
{
|
||||||
constant = hlsl_ir_constant(node);
|
struct hlsl_ir_constant *constant = hlsl_ir_constant(node);
|
||||||
ret = constant->value.u[0];
|
|
||||||
|
ret.number = constant->value.u[0];
|
||||||
|
}
|
||||||
|
else if (node->type == HLSL_IR_STRING_CONSTANT)
|
||||||
|
{
|
||||||
|
struct hlsl_ir_string_constant *string = hlsl_ir_string_constant(node);
|
||||||
|
|
||||||
|
if (!(ret.string = vkd3d_strdup(string->string)))
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
else if (node->type == HLSL_IR_STRING_CONSTANT)
|
else if (node->type == HLSL_IR_STRING_CONSTANT)
|
||||||
{
|
{
|
||||||
@ -675,10 +682,11 @@ static union hlsl_constant_value_component evaluate_static_expression(struct hls
|
|||||||
static unsigned int evaluate_static_expression_as_uint(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
static unsigned int evaluate_static_expression_as_uint(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||||
const struct vkd3d_shader_location *loc)
|
const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
union hlsl_constant_value_component res;
|
struct hlsl_default_value res;
|
||||||
|
|
||||||
res = evaluate_static_expression(ctx, block, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), loc);
|
res = evaluate_static_expression(ctx, block, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), loc);
|
||||||
return res.u;
|
VKD3D_ASSERT(!res.string);
|
||||||
|
return res.number.u;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct hlsl_block *create_loop(struct hlsl_ctx *ctx, enum loop_type type,
|
static struct hlsl_block *create_loop(struct hlsl_ctx *ctx, enum loop_type type,
|
||||||
@ -2373,7 +2381,7 @@ static void initialize_var_components(struct hlsl_ctx *ctx, struct hlsl_block *i
|
|||||||
|
|
||||||
if (!hlsl_clone_block(ctx, &block, instrs))
|
if (!hlsl_clone_block(ctx, &block, instrs))
|
||||||
return;
|
return;
|
||||||
default_value.value = evaluate_static_expression(ctx, &block, dst_comp_type, &src->loc);
|
default_value = evaluate_static_expression(ctx, &block, dst_comp_type, &src->loc);
|
||||||
|
|
||||||
if (dst->is_param)
|
if (dst->is_param)
|
||||||
dst_index = *store_index;
|
dst_index = *store_index;
|
||||||
@ -2931,7 +2939,9 @@ static bool add_user_call(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *fu
|
|||||||
struct hlsl_ir_node *comp;
|
struct hlsl_ir_node *comp;
|
||||||
struct hlsl_block store_block;
|
struct hlsl_block store_block;
|
||||||
|
|
||||||
value.u[0] = param->default_values[j].value;
|
if (!param->default_values[j].string)
|
||||||
|
{
|
||||||
|
value.u[0] = param->default_values[j].number;
|
||||||
if (!(comp = hlsl_new_constant(ctx, type, &value, loc)))
|
if (!(comp = hlsl_new_constant(ctx, type, &value, loc)))
|
||||||
return false;
|
return false;
|
||||||
hlsl_block_add_instr(args->instrs, comp);
|
hlsl_block_add_instr(args->instrs, comp);
|
||||||
@ -2941,6 +2951,7 @@ static bool add_user_call(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *fu
|
|||||||
hlsl_block_add_block(args->instrs, &store_block);
|
hlsl_block_add_block(args->instrs, &store_block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!(call = hlsl_new_call(ctx, func, loc)))
|
if (!(call = hlsl_new_call(ctx, func, loc)))
|
||||||
return false;
|
return false;
|
||||||
|
@ -3607,7 +3607,7 @@ static void write_sm4_rdef(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc)
|
|||||||
hlsl_fixme(ctx, &var->loc, "Write double default values.");
|
hlsl_fixme(ctx, &var->loc, "Write double default values.");
|
||||||
|
|
||||||
set_u32(&buffer, default_value_offset + comp_offset * sizeof(uint32_t),
|
set_u32(&buffer, default_value_offset + comp_offset * sizeof(uint32_t),
|
||||||
var->default_values[k].value.u);
|
var->default_values[k].number.u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ float4 main() : sv_target
|
|||||||
return apple.a;
|
return apple.a;
|
||||||
}
|
}
|
||||||
|
|
||||||
[pixel shader fail todo]
|
[pixel shader fail]
|
||||||
struct apple
|
struct apple
|
||||||
{
|
{
|
||||||
float a;
|
float a;
|
||||||
@ -75,13 +75,13 @@ float4 main(struct apple ap = {1, "foobar"}) : sv_target
|
|||||||
return ap.a;
|
return ap.a;
|
||||||
}
|
}
|
||||||
|
|
||||||
[pixel shader fail todo]
|
[pixel shader fail]
|
||||||
float4 main(string s = "foobar") : sv_target
|
float4 main(string s = "foobar") : sv_target
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
[pixel shader fail(sm>=6) todo]
|
[pixel shader fail(sm>=6)]
|
||||||
string strs[2] = {"foo", "bar"};
|
string strs[2] = {"foo", "bar"};
|
||||||
|
|
||||||
float4 main() : sv_target { return 0; }
|
float4 main() : sv_target { return 0; }
|
||||||
@ -95,7 +95,7 @@ float4 main() : sv_target { return 0; }
|
|||||||
|
|
||||||
% Escape sequences are hanlded differently in DXC.
|
% Escape sequences are hanlded differently in DXC.
|
||||||
% Octal, hexadecimal, and unicode escape sequences that are out of range are considered errors.
|
% Octal, hexadecimal, and unicode escape sequences that are out of range are considered errors.
|
||||||
[pixel shader todo fail(sm>=6)]
|
[pixel shader fail(sm>=6)]
|
||||||
string a = "\nAAA\tBBB\rCCC\fDDD\vEEE\sFFF";
|
string a = "\nAAA\tBBB\rCCC\fDDD\vEEE\sFFF";
|
||||||
string b = "\\AAA\"BBB\'CCC\?DDD\aEEE\bFFF\sGGG";
|
string b = "\\AAA\"BBB\'CCC\?DDD\aEEE\bFFF\sGGG";
|
||||||
string c = "\52 AAA\052 BBB\0521 CCC\52a DDD\241 EEE\441 FFF\02 GGG\0 HHH";
|
string c = "\52 AAA\052 BBB\0521 CCC\52a DDD\241 EEE\441 FFF\02 GGG\0 HHH";
|
||||||
|
Loading…
Reference in New Issue
Block a user