From: Francisco Casas fcasas@codeweavers.com
Co-authored-by: Giovanni Mascellani gmascellani@codeweavers.com
These may happen when storing to structured buffers, and we are not handling them properly yet. The included test reaches unreacheable code before this patch.
Storing to buffers is complicated since we need to split the index chain in two paths: - The path within the variable where the resource is. - The subpath to the part of the resource element that is being stored to.
For now, we will emit a fixme when the index chain in the lhs is not a direct resource access. --- libs/vkd3d-shader/hlsl.c | 9 +++++++++ libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 8 +++++++- tests/hlsl/uav-rwstructuredbuffer.shader_test | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 3d068ac6d..7286c5ca0 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1554,6 +1554,15 @@ bool hlsl_index_is_resource_access(struct hlsl_ir_index *index) return index->val.node->data_type->class == HLSL_CLASS_OBJECT; }
+bool hlsl_index_chain_has_resource_access(struct hlsl_ir_index *index) +{ + if (hlsl_index_is_resource_access(index)) + return true; + if (index->val.node->type == HLSL_IR_INDEX) + return hlsl_index_chain_has_resource_access(hlsl_ir_index(index->val.node)); + return false; +} + struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *val, struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc) { diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 43bc079db..392d4cb58 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1252,6 +1252,7 @@ bool hlsl_new_store_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
bool hlsl_index_is_noncontiguous(struct hlsl_ir_index *index); bool hlsl_index_is_resource_access(struct hlsl_ir_index *index); +bool hlsl_index_chain_has_resource_access(struct hlsl_ir_index *index);
struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *val, struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc); diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 37a372893..7cdb07f97 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1915,7 +1915,7 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct hlsl_blo } }
- if (lhs->type == HLSL_IR_INDEX && hlsl_index_is_resource_access(hlsl_ir_index(lhs))) + if (lhs->type == HLSL_IR_INDEX && hlsl_index_chain_has_resource_access(hlsl_ir_index(lhs))) { struct hlsl_ir_node *coords = hlsl_ir_index(lhs)->idx.node; struct hlsl_deref resource_deref; @@ -1923,6 +1923,12 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct hlsl_blo struct hlsl_ir_node *store; unsigned int dim_count;
+ if (!hlsl_index_is_resource_access(hlsl_ir_index(lhs))) + { + hlsl_fixme(ctx, &lhs->loc, "Non-direct structured resource store."); + return NULL; + } + if (!hlsl_init_deref_from_index_chain(ctx, &resource_deref, hlsl_ir_index(lhs)->val.node)) return NULL;
diff --git a/tests/hlsl/uav-rwstructuredbuffer.shader_test b/tests/hlsl/uav-rwstructuredbuffer.shader_test index 37f52ee75..f962e18e0 100644 --- a/tests/hlsl/uav-rwstructuredbuffer.shader_test +++ b/tests/hlsl/uav-rwstructuredbuffer.shader_test @@ -108,3 +108,18 @@ float4 main() : sv_target1 { return 0; } + + +[pixel shader todo] +struct apple +{ + float3 a, x; +}; + +RWStructuredBuffer<apple> u; + +float4 main() : sv_target +{ + u[0].x = float3(30.0, 40.0, 50.0); + return 0; +}