From 4ede2f1365e6c2d87699caba7ae4e8f1caa04f66 Mon Sep 17 00:00:00 2001 From: Shaun Ren Date: Fri, 6 Jun 2025 18:41:49 -0400 Subject: [PATCH] vkd3d-shader/hlsl: Allow memory barriers in SM4+ target profiles. --- libs/vkd3d-shader/hlsl.y | 8 ++--- tests/hlsl/barriers.shader_test | 53 +++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index fa3688fad..1232522a8 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -5144,10 +5144,10 @@ static bool intrinsic_InterlockedXor(struct hlsl_ctx *ctx, static void validate_group_barrier_profile(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc) { - if (ctx->profile->type != VKD3D_SHADER_TYPE_COMPUTE || hlsl_version_lt(ctx, 5, 0)) + if (ctx->profile->type != VKD3D_SHADER_TYPE_COMPUTE) { hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INCOMPATIBLE_PROFILE, - "Group barriers can only be used in compute shaders 5.0 or higher."); + "Group barriers can only be used in compute shaders."); } } @@ -5171,10 +5171,10 @@ static bool intrinsic_DeviceMemoryBarrier(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { if ((ctx->profile->type != VKD3D_SHADER_TYPE_COMPUTE && ctx->profile->type != VKD3D_SHADER_TYPE_PIXEL) - || hlsl_version_lt(ctx, 5, 0)) + || hlsl_version_lt(ctx, 4, 0)) { hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INCOMPATIBLE_PROFILE, - "DeviceMemoryBarrier() can only be used in pixel and compute shaders 5.0 or higher."); + "DeviceMemoryBarrier() can only be used in compute and pixel shaders 4.0 or higher."); } return !!hlsl_block_add_sync(ctx, params->instrs, VKD3DSSF_GLOBAL_UAV, loc); } diff --git a/tests/hlsl/barriers.shader_test b/tests/hlsl/barriers.shader_test index 4a649d331..7b357468b 100644 --- a/tests/hlsl/barriers.shader_test +++ b/tests/hlsl/barriers.shader_test @@ -1,9 +1,10 @@ [require] -shader model >= 5.0 +shader model >= 4.0 + +% These are just parsing tests. -% This is just a parsing test. [compute shader] - [numthreads(1024, 1, 1)] + [numthreads(768, 1, 1)] void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID) { GroupMemoryBarrier(); @@ -14,6 +15,52 @@ void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID) AllMemoryBarrierWithGroupSync(); } +[pixel shader] +float4 main() : sv_target +{ + DeviceMemoryBarrier(); + return 0; +} + +[pixel shader fail] +float4 main() : sv_target +{ + DeviceMemoryBarrierWithGroupSync(); + return 0; +} + +[pixel shader fail] +float4 main() : sv_target +{ + GroupMemoryBarrier(); + return 0; +} + +[pixel shader fail] +float4 main() : sv_target +{ + GroupMemoryBarrierWithGroupSync(); + return 0; +} + +[pixel shader fail] +float4 main() : sv_target +{ + AllMemoryBarrier(); + return 0; +} + +[pixel shader fail] +float4 main() : sv_target +{ + AllMemoryBarrierWithGroupSync(); + return 0; +} + + +[require] +shader model >= 5.0 + [uav 2] format r32g32b32a32-float size (buffer, 3)