vkd3d-shader/hlsl: Move shader version helpers to hlsl.h.

This commit is contained in:
Zebediah Figura 2024-04-03 14:28:18 -05:00 committed by Alexandre Julliard
parent e72c3bab71
commit 5fbd2708c0
Notes: Alexandre Julliard 2024-04-09 15:45:34 -05:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/757
2 changed files with 16 additions and 16 deletions

View File

@ -927,6 +927,16 @@ struct hlsl_ctx
bool warn_implicit_truncation; bool warn_implicit_truncation;
}; };
static inline bool hlsl_version_ge(const struct hlsl_ctx *ctx, unsigned int major, unsigned int minor)
{
return ctx->profile->major_version > major || (ctx->profile->major_version == major && ctx->profile->minor_version >= minor);
}
static inline bool hlsl_version_lt(const struct hlsl_ctx *ctx, unsigned int major, unsigned int minor)
{
return !hlsl_version_ge(ctx, major, minor);
}
struct hlsl_resource_load_params struct hlsl_resource_load_params
{ {
struct hlsl_type *format; struct hlsl_type *format;

View File

@ -939,16 +939,6 @@ static bool shader_is_sm_5_1(const struct hlsl_ctx *ctx)
return ctx->profile->major_version == 5 && ctx->profile->minor_version >= 1; return ctx->profile->major_version == 5 && ctx->profile->minor_version >= 1;
} }
static bool shader_profile_version_ge(const struct hlsl_ctx *ctx, unsigned int major, unsigned int minor)
{
return ctx->profile->major_version > major || (ctx->profile->major_version == major && ctx->profile->minor_version >= minor);
}
static bool shader_profile_version_lt(const struct hlsl_ctx *ctx, unsigned int major, unsigned int minor)
{
return !shader_profile_version_ge(ctx, major, minor);
}
static bool gen_struct_fields(struct hlsl_ctx *ctx, struct parse_fields *fields, static bool gen_struct_fields(struct hlsl_ctx *ctx, struct parse_fields *fields,
struct hlsl_type *type, uint32_t modifiers, struct list *defs) struct hlsl_type *type, uint32_t modifiers, struct list *defs)
{ {
@ -1216,7 +1206,7 @@ static struct hlsl_reg_reservation parse_packoffset(struct hlsl_ctx *ctx, const
struct hlsl_reg_reservation reservation = {0}; struct hlsl_reg_reservation reservation = {0};
char *endptr; char *endptr;
if (shader_profile_version_lt(ctx, 4, 0)) if (hlsl_version_lt(ctx, 4, 0))
return reservation; return reservation;
reservation.offset_index = strtoul(reg_string + 1, &endptr, 10); reservation.offset_index = strtoul(reg_string + 1, &endptr, 10);
@ -3939,7 +3929,7 @@ static bool intrinsic_tex(struct hlsl_ctx *ctx, const struct parse_initializer *
return false; return false;
} }
if (shader_profile_version_ge(ctx, 4, 0)) if (hlsl_version_ge(ctx, 4, 0))
{ {
unsigned int count = hlsl_sampler_dim_count(dim); unsigned int count = hlsl_sampler_dim_count(dim);
struct hlsl_ir_node *divisor; struct hlsl_ir_node *divisor;
@ -3986,7 +3976,7 @@ static bool intrinsic_tex(struct hlsl_ctx *ctx, const struct parse_initializer *
return false; return false;
initialize_var_components(ctx, params->instrs, var, &idx, coords); initialize_var_components(ctx, params->instrs, var, &idx, coords);
if (shader_profile_version_ge(ctx, 4, 0)) if (hlsl_version_ge(ctx, 4, 0))
{ {
if (!(half = hlsl_new_float_constant(ctx, 0.5f, loc))) if (!(half = hlsl_new_float_constant(ctx, 0.5f, loc)))
return false; return false;
@ -4172,7 +4162,7 @@ static bool intrinsic_d3dcolor_to_ubyte4(struct hlsl_ctx *ctx,
if (!(ret = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, arg, c, loc))) if (!(ret = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, arg, c, loc)))
return false; return false;
if (shader_profile_version_ge(ctx, 4, 0)) if (hlsl_version_ge(ctx, 4, 0))
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_TRUNC, ret, loc); return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_TRUNC, ret, loc);
return true; return true;
@ -6461,7 +6451,7 @@ type_no_void:
{ {
validate_texture_format_type(ctx, $3, &@3); validate_texture_format_type(ctx, $3, &@3);
if (shader_profile_version_lt(ctx, 4, 1)) if (hlsl_version_lt(ctx, 4, 1))
{ {
hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Multisampled texture object declaration needs sample count for profile %s.", ctx->profile->name); "Multisampled texture object declaration needs sample count for profile %s.", ctx->profile->name);
@ -6500,7 +6490,7 @@ type_no_void:
$$ = hlsl_get_type(ctx->cur_scope, $1, true, true); $$ = hlsl_get_type(ctx->cur_scope, $1, true, true);
if ($$->is_minimum_precision) if ($$->is_minimum_precision)
{ {
if (shader_profile_version_lt(ctx, 4, 0)) if (hlsl_version_lt(ctx, 4, 0))
{ {
hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Target profile doesn't support minimum-precision types."); "Target profile doesn't support minimum-precision types.");