mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/hlsl: Introduce the "error" type.
Currently, if an expression successfully parses according to the bison grammar, but for one reason or another cannot generate a meaningful IR instruction, we abort parsing with YYABORT. This includes, for example, an undefined variable or function, invalid swizzle or field reference, or a constructor with a complex or non-numeric data type. Aborting parsing is unfortunate, however, because it means that any further errors in the program cannot be caught by the programmer, increasing the number of times they will need to fix errors and recompile. The idea of this patch is that any such expression will instead generate an IR node whose data type is of HLSL_CLASS_ERROR. Any further expression which would consume an "error" typed instruction will instead immediately return an expression of type "error" (probably the same one) instead of aborting or doing any other type-checking. Currently these "error" instructions should not pass the parsing stage, since hlsl_compile_shader() will immediately notice that compilation has failed and skip any optimization, lowering, or bytecode-writing. A further direction to take this is to pre-allocate one "error" expression immediately when creating the HLSL parser, and return that expression when we fail to allocate an hlsl_ir_node of any type. This means we do not need to handle allocation errors when constructing nodes, saving us quite a lot of error handling (which is not only tedious but currently often broken, if nothing else by virtue of neglecting cleanup of local variables).
This commit is contained in:
parent
7daaaf6386
commit
c43e5c8eb5
Notes:
Henri Verbeet
2024-09-23 15:55:59 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1071
@ -1522,6 +1522,7 @@ D3DXPARAMETER_CLASS hlsl_sm1_class(const struct hlsl_type *type)
|
||||
case HLSL_CLASS_DEPTH_STENCIL_STATE:
|
||||
case HLSL_CLASS_DEPTH_STENCIL_VIEW:
|
||||
case HLSL_CLASS_EFFECT_GROUP:
|
||||
case HLSL_CLASS_ERROR:
|
||||
case HLSL_CLASS_PASS:
|
||||
case HLSL_CLASS_RASTERIZER_STATE:
|
||||
case HLSL_CLASS_RENDER_TARGET_VIEW:
|
||||
@ -1627,6 +1628,7 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type)
|
||||
case HLSL_CLASS_DEPTH_STENCIL_STATE:
|
||||
case HLSL_CLASS_DEPTH_STENCIL_VIEW:
|
||||
case HLSL_CLASS_EFFECT_GROUP:
|
||||
case HLSL_CLASS_ERROR:
|
||||
case HLSL_CLASS_PASS:
|
||||
case HLSL_CLASS_RASTERIZER_STATE:
|
||||
case HLSL_CLASS_RENDER_TARGET_VIEW:
|
||||
|
@ -665,6 +665,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
|
||||
|
||||
case HLSL_CLASS_ARRAY:
|
||||
case HLSL_CLASS_EFFECT_GROUP:
|
||||
case HLSL_CLASS_ERROR:
|
||||
case HLSL_CLASS_PASS:
|
||||
case HLSL_CLASS_TECHNIQUE:
|
||||
case HLSL_CLASS_CONSTANT_BUFFER:
|
||||
@ -1117,6 +1118,7 @@ static bool is_type_supported_fx_2(struct hlsl_ctx *ctx, const struct hlsl_type
|
||||
return false;
|
||||
|
||||
case HLSL_CLASS_EFFECT_GROUP:
|
||||
case HLSL_CLASS_ERROR:
|
||||
case HLSL_CLASS_PASS:
|
||||
case HLSL_CLASS_TECHNIQUE:
|
||||
case HLSL_CLASS_CONSTANT_BUFFER:
|
||||
|
@ -276,6 +276,7 @@ bool hlsl_type_is_shader(const struct hlsl_type *type)
|
||||
case HLSL_CLASS_DEPTH_STENCIL_STATE:
|
||||
case HLSL_CLASS_DEPTH_STENCIL_VIEW:
|
||||
case HLSL_CLASS_EFFECT_GROUP:
|
||||
case HLSL_CLASS_ERROR:
|
||||
case HLSL_CLASS_PASS:
|
||||
case HLSL_CLASS_RASTERIZER_STATE:
|
||||
case HLSL_CLASS_RENDER_TARGET_VIEW:
|
||||
@ -418,6 +419,7 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type
|
||||
case HLSL_CLASS_DEPTH_STENCIL_STATE:
|
||||
case HLSL_CLASS_DEPTH_STENCIL_VIEW:
|
||||
case HLSL_CLASS_EFFECT_GROUP:
|
||||
case HLSL_CLASS_ERROR:
|
||||
case HLSL_CLASS_PASS:
|
||||
case HLSL_CLASS_PIXEL_SHADER:
|
||||
case HLSL_CLASS_RASTERIZER_STATE:
|
||||
@ -494,6 +496,7 @@ static bool type_is_single_component(const struct hlsl_type *type)
|
||||
{
|
||||
case HLSL_CLASS_DEPTH_STENCIL_STATE:
|
||||
case HLSL_CLASS_DEPTH_STENCIL_VIEW:
|
||||
case HLSL_CLASS_ERROR:
|
||||
case HLSL_CLASS_PIXEL_SHADER:
|
||||
case HLSL_CLASS_SCALAR:
|
||||
case HLSL_CLASS_SAMPLER:
|
||||
@ -670,6 +673,7 @@ unsigned int hlsl_type_get_component_offset(struct hlsl_ctx *ctx, struct hlsl_ty
|
||||
break;
|
||||
|
||||
case HLSL_CLASS_EFFECT_GROUP:
|
||||
case HLSL_CLASS_ERROR:
|
||||
case HLSL_CLASS_PASS:
|
||||
case HLSL_CLASS_TECHNIQUE:
|
||||
case HLSL_CLASS_VOID:
|
||||
@ -1061,6 +1065,7 @@ unsigned int hlsl_type_component_count(const struct hlsl_type *type)
|
||||
|
||||
case HLSL_CLASS_DEPTH_STENCIL_STATE:
|
||||
case HLSL_CLASS_DEPTH_STENCIL_VIEW:
|
||||
case HLSL_CLASS_ERROR:
|
||||
case HLSL_CLASS_PIXEL_SHADER:
|
||||
case HLSL_CLASS_RASTERIZER_STATE:
|
||||
case HLSL_CLASS_RENDER_TARGET_VIEW:
|
||||
@ -1155,6 +1160,7 @@ bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2
|
||||
case HLSL_CLASS_DEPTH_STENCIL_STATE:
|
||||
case HLSL_CLASS_DEPTH_STENCIL_VIEW:
|
||||
case HLSL_CLASS_EFFECT_GROUP:
|
||||
case HLSL_CLASS_ERROR:
|
||||
case HLSL_CLASS_PASS:
|
||||
case HLSL_CLASS_PIXEL_SHADER:
|
||||
case HLSL_CLASS_RASTERIZER_STATE:
|
||||
@ -2710,6 +2716,10 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru
|
||||
}
|
||||
return string;
|
||||
|
||||
case HLSL_CLASS_ERROR:
|
||||
vkd3d_string_buffer_printf(string, "<error type>");
|
||||
return string;
|
||||
|
||||
case HLSL_CLASS_DEPTH_STENCIL_STATE:
|
||||
case HLSL_CLASS_DEPTH_STENCIL_VIEW:
|
||||
case HLSL_CLASS_EFFECT_GROUP:
|
||||
@ -4146,6 +4156,7 @@ static void declare_predefined_types(struct hlsl_ctx *ctx)
|
||||
ctx->builtin_types.Void = hlsl_new_simple_type(ctx, "void", HLSL_CLASS_VOID);
|
||||
ctx->builtin_types.null = hlsl_new_type(ctx, "NULL", HLSL_CLASS_NULL, HLSL_TYPE_UINT, 1, 1);
|
||||
ctx->builtin_types.string = hlsl_new_simple_type(ctx, "string", HLSL_CLASS_STRING);
|
||||
ctx->builtin_types.error = hlsl_new_simple_type(ctx, "<error type>", HLSL_CLASS_ERROR);
|
||||
hlsl_scope_add_type(ctx->globals, ctx->builtin_types.string);
|
||||
hlsl_scope_add_type(ctx->globals, hlsl_new_simple_type(ctx, "DepthStencilView", HLSL_CLASS_DEPTH_STENCIL_VIEW));
|
||||
hlsl_scope_add_type(ctx->globals, hlsl_new_simple_type(ctx, "DepthStencilState", HLSL_CLASS_DEPTH_STENCIL_STATE));
|
||||
|
@ -106,6 +106,7 @@ enum hlsl_type_class
|
||||
HLSL_CLASS_BLEND_STATE,
|
||||
HLSL_CLASS_VOID,
|
||||
HLSL_CLASS_NULL,
|
||||
HLSL_CLASS_ERROR,
|
||||
};
|
||||
|
||||
enum hlsl_base_type
|
||||
@ -1046,6 +1047,7 @@ struct hlsl_ctx
|
||||
struct hlsl_type *string;
|
||||
struct hlsl_type *Void;
|
||||
struct hlsl_type *null;
|
||||
struct hlsl_type *error;
|
||||
} builtin_types;
|
||||
|
||||
/* List of the instruction nodes for initializing static variables. */
|
||||
|
@ -1661,6 +1661,7 @@ static bool copy_propagation_transform_load(struct hlsl_ctx *ctx,
|
||||
* solve that problem for us, since we may be called on a partial
|
||||
* block, but DCE deletes dead stores, so it needs to be able to
|
||||
* see the whole program. */
|
||||
case HLSL_CLASS_ERROR:
|
||||
return false;
|
||||
|
||||
case HLSL_CLASS_CONSTANT_BUFFER:
|
||||
|
@ -3236,6 +3236,7 @@ static D3D_SHADER_VARIABLE_CLASS sm4_class(const struct hlsl_type *type)
|
||||
case HLSL_CLASS_DEPTH_STENCIL_STATE:
|
||||
case HLSL_CLASS_DEPTH_STENCIL_VIEW:
|
||||
case HLSL_CLASS_EFFECT_GROUP:
|
||||
case HLSL_CLASS_ERROR:
|
||||
case HLSL_CLASS_STRUCT:
|
||||
case HLSL_CLASS_PASS:
|
||||
case HLSL_CLASS_PIXEL_SHADER:
|
||||
|
Loading…
x
Reference in New Issue
Block a user