From 8813c610562b1c30222ec3ef0734ef601d43b617 Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:38:23 -0400 Subject: Capability System: Implicit capability upgrade warning/error (#4241) * capability upgrade warning/error adjusted implementation + tests to support a warning/error if capabilities are implicitly upgraded and test accordingly. * add glsl profile caps * add GLSL and HLSL capabilities to the associated capability * syntax error in capdef * only error if user explicitly enables capabilities 1. changed testing infrastructure to not set a `profile` explicitly, 2. Added tests to be sure this works as intended with user API and with slangc command line * Change capability atom definitions and how Slang manages them to fix errors 1. most `glsl_spirv` version atoms have been removed from `.capdef`, instead we will translate `spirv` version atoms into `glsl_spirv` since there is no point in writing the same code twice in `.capdef` files to define `spirv` versions. 2. add spirv version, and hlsl sm version (and equivlent) capability dependencies 3. removed some stage requirments which were set on objects, keep the wrapper capabilities. I am keeping the wrapper capabilities since I am unaware on if there are stage limitations (spec says code in practice does not work). * check internal version instead of version profile (_spirv_1_5 vs. spirv_1_5) * remove unused OpCapability. adjust SPIRV version'ing again for glsl_spirv * apply workaround for glslang bug with rayquery usage * ensure capabilities targetted by a profile and added together by a user are valid * remove additions to `spirv_1_*` wrapper * spirv_* -> glsl_spirv fix * fix bug where incompatable profiles would cause invalid target caps * try to avoid joining invalid capabilities * fix the warning/error & printing * run through tests to fix capability system and test mistakes many mistakes were mesh shaders doing `-profile glsl_450+spirv_1_4`. This is not allowed for a few reasons 1. the test tooling does not handle arguments the same as `slangc` 2. glsl_450 core profile does not support mesh shaders, nor does spirv_1_4. sm_6_5 does work in this senario * set some sm_4_1 intrinsics to sm_4_0 * replace `GLSL_` defs with `glsl_` * swap the unsupported render-test syntax for working syntax * set d3d11/d3d12 profile defaults this is required since sm version changes compiled code & behavior * adjusted nvapi capabilities with atomics + d3d11 set to use sm_5_0 as per default * cleanup * address review * incorrect styling * change `bitscanForward` to work as intended on 32 bit targets --------- Co-authored-by: Yong He --- .../language-feature/capability/capability5.slang | 29 ++++++++++++++++++++++ .../capability/specializeTargetSwitch.slang | 12 +++++++++ .../testing-framework-with-profiles.slang | 21 ++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 tests/language-feature/capability/capability5.slang create mode 100644 tests/language-feature/capability/testing-framework-with-profiles.slang (limited to 'tests/language-feature/capability') diff --git a/tests/language-feature/capability/capability5.slang b/tests/language-feature/capability/capability5.slang new file mode 100644 index 000000000..6199f045a --- /dev/null +++ b/tests/language-feature/capability/capability5.slang @@ -0,0 +1,29 @@ +//TEST:SIMPLE(filecheck=PASS): -target glsl -entry main -stage compute -allow-glsl +//TEST:SIMPLE(filecheck=PASS): -target glsl -entry main -stage compute -allow-glsl -capability shader5_sm_5_0 +//TEST:SIMPLE(filecheck=PASS): -target glsl -entry main -stage compute -allow-glsl -profile sm_6_0 +//TEST:SIMPLE(filecheck=WARN): -target glsl -entry main -stage compute -allow-glsl -capability GLSL_130 +//TEST:SIMPLE(filecheck=ERROR): -target glsl -entry main -stage compute -allow-glsl -capability GLSL_130 -restrictive-capability-check +// CHECK_IGNORE_CAPS-NOT: error 36104 + +// Check that a non-static member method implictly requires capabilities +// defined in ThisType. + +//PASS-NOT: warning 41012 +//PASS-NOT: error 41012 + +//WARN: warning 41012 +//WARN-NOT: error 41012 + +//ERROR-NOT: warning 41012 +//ERROR: error 41012 + +buffer MyBlockName +{ + int data; +} inputBuffer; + +[numthreads(1,1,1)] +void main() +{ + inputBuffer.data = firstbithigh(1); +} diff --git a/tests/language-feature/capability/specializeTargetSwitch.slang b/tests/language-feature/capability/specializeTargetSwitch.slang index 251adfaf8..e1e5d4225 100644 --- a/tests/language-feature/capability/specializeTargetSwitch.slang +++ b/tests/language-feature/capability/specializeTargetSwitch.slang @@ -1,6 +1,8 @@ //TEST:SIMPLE(filecheck=CHECK_HLSL): -target hlsl -entry main -stage compute -capability _sm_5_1 //TEST:SIMPLE(filecheck=CHECK_GLSL1): -target glsl -entry main -stage compute -capability _GLSL_420 +//TEST:SIMPLE(filecheck=CHECK_GLSL1): -target glsl -entry main -stage compute -capability _GLSL_420 //TEST:SIMPLE(filecheck=CHECK_GLSL2): -target glsl -entry main -stage compute -capability _GLSL_330 +//TEST:SIMPLE(filecheck=CHECK_GLSL2_NO_UPGRADE): -target glsl -entry main -stage compute -capability _GLSL_330 -DTURN_OFF_LARGER_GLSL_TARGETS //TEST:SIMPLE(filecheck=CHECK_METAL): -target cpp -entry main -stage compute -capability image_loadstore //TEST:SIMPLE(filecheck=CHECK_WILL_ERROR1): -target glsl -entry main -stage compute -capability image_loadstore -DWILL_ERROR1 //TEST:SIMPLE(filecheck=CHECK_WILL_ERROR2): -target glsl -entry main -stage compute -capability _GLSL_130 -DWILL_ERROR2 @@ -9,11 +11,19 @@ RWTexture1D tex; //CHECK_HLSL: {{.*}}21{{.*}}; + //CHECK_GLSL1: {{.*}}13{{.*}} + //CHECK_GLSL2: {{.*}}11{{.*}} + +//CHECK_GLSL2_NO_UPGRADE-NOT: warning 41012 +//CHECK_GLSL2_NO_UPGRADE-NOT: error 41012 + //CHECK_METAL: {{.*}}30{{.*}} + //CHECK_WILL_ERROR1: error 36109 //CHECK_WILL_ERROR2: error 41011 + //CHECK_GLSL3: {{.*}}30{{.*}} int specialize() @@ -31,10 +41,12 @@ int specialize() return 10; case _GLSL_330: return 11; +#ifndef TURN_OFF_LARGER_GLSL_TARGETS case _GLSL_400: return 12; case _GLSL_410: return 13; +#endif #ifdef WILL_ERROR1 case image_loadstore: return 14; diff --git a/tests/language-feature/capability/testing-framework-with-profiles.slang b/tests/language-feature/capability/testing-framework-with-profiles.slang new file mode 100644 index 000000000..215ba887e --- /dev/null +++ b/tests/language-feature/capability/testing-framework-with-profiles.slang @@ -0,0 +1,21 @@ + +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -profile sm_6_1 +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -entry computeMain -stage compute +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -entry computeMain -stage compute -capability sm_6_1 +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -entry computeMain -stage compute -profile sm_6_1 +//TEST:SIMPLE(filecheck=CHECK_WARN): -target hlsl -entry computeMain -stage compute -capability sm_4_0 + +//CHECK-NOT: warning 41012 +//CHECK_WARN: warning 41012 +//CHECK: computeMain + +//TEST_INPUT:ubuffer(data=[1], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + // BUF: 1 + outputBuffer[0] = WaveMaskSum(0xFF, 1); +} -- cgit v1.2.3