From 80ddf40274fdca93f2ae95a247ff3af122aec6ac Mon Sep 17 00:00:00 2001 From: "James Helferty (NVIDIA)" Date: Wed, 27 Aug 2025 20:08:54 -0700 Subject: Add SPIRV OpCapability for 8/16bit use in storage (#8194) Emits the appropriate OpCapability for 8- and 16-bit type usage: - UniformAndStorageBuffer8BitAccess: for 16-bit types in SpvStorageClassUniform and SpvStorageClassStorageBuffer - UniformAndStorageBuffer16BitAccess: for 16-bit types in SpvStorageClassUniform and SpvStorageClassStorageBuffer - StoragePushConstant8: for 8-bit types in SpvStorageClassPushConstant - StoragePushConstant16: for 16-bit types in SpvStorageClassPushConstant - StorageInputOutput16: for 16-bit types in SpvStorageClassInput and SpvStorageClassOutput Generated with Claude Code, with revisions. Fixes #7879. --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: James Helferty (NVIDIA) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- tests/spirv/capability-storage-input-output.slang | 44 +++++++++++++++ tests/spirv/capability-storage-push-constant.slang | 35 ++++++++++++ tests/spirv/capability-uniform-and-storage.slang | 65 ++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 tests/spirv/capability-storage-input-output.slang create mode 100644 tests/spirv/capability-storage-push-constant.slang create mode 100644 tests/spirv/capability-uniform-and-storage.slang (limited to 'tests') diff --git a/tests/spirv/capability-storage-input-output.slang b/tests/spirv/capability-storage-input-output.slang new file mode 100644 index 000000000..0cccd26c7 --- /dev/null +++ b/tests/spirv/capability-storage-input-output.slang @@ -0,0 +1,44 @@ +//TEST:SIMPLE(filecheck=CHECK16): -target spirv -profile spirv_1_3 -DIN_HALF +//TEST:SIMPLE(filecheck=CHECK16): -target spirv -profile spirv_1_3 -DIN_UINT16 +//TEST:SIMPLE(filecheck=CHECK16): -target spirv -profile spirv_1_3 -DOUT_HALF +//TEST:SIMPLE(filecheck=CHECK): -target spirv -profile spirv_1_3 + +//CHECK16: OpCapability StorageInputOutput16 +//CHECK-NOT: OpCapability StorageInputOutput16 + +struct VertexInput { +#ifdef IN_HALF + half4 position : POSITION; +#else + float4 position : POSITION; +#endif +#ifdef IN_UINT16 + uint16_t id : ID; +#else + uint32_t id : ID; +#endif +}; + +#ifdef OUT_HALF +#define OUT_TYPE half4 +#else +#define OUT_TYPE float4 +#endif + +struct VertexOutput { + float4 position : SV_POSITION; + OUT_TYPE color : COLOR; +}; + +[shader("vertex")] +VertexOutput vertexMain(VertexInput input) +{ + VertexOutput output; + output.position = float4(input.position); + if (input.id == 0) { + output.color = OUT_TYPE(input.position); + } else { + output.color = OUT_TYPE(0); + } + return output; +} diff --git a/tests/spirv/capability-storage-push-constant.slang b/tests/spirv/capability-storage-push-constant.slang new file mode 100644 index 000000000..6cb540da9 --- /dev/null +++ b/tests/spirv/capability-storage-push-constant.slang @@ -0,0 +1,35 @@ +//TEST:SIMPLE(filecheck=CHECK8): -target spirv -profile spirv_1_3 -DCONST_UINT8 +//TEST:SIMPLE(filecheck=CHECK16): -target spirv -profile spirv_1_3 -DCONST_UINT16 +//TEST:SIMPLE(filecheck=CHECK16): -target spirv -profile spirv_1_3 -DCONST_HALF +//TEST:SIMPLE(filecheck=CHECKBOTH): -target spirv -profile spirv_1_3 -DCONST_UINT8 -DCONST_HALF +//TEST:SIMPLE(filecheck=CHECK): -target spirv -profile spirv_1_3 + +//CHECK8: OpCapability StoragePushConstant8 +//CHECK16: OpCapability StoragePushConstant16 +//CHECKBOTH-DAG: OpCapability StoragePushConstant8 +//CHECKBOTH-DAG: OpCapability StoragePushConstant16 +//CHECK-NOT: OpCapability StoragePushConstant16 + +struct PushConstants { +#if defined(CONST_HALF) + half4 color; +#else + float4 color; +#endif +#if defined(CONST_UINT8) + int8_t index; +#elif defined(CONST_UINT16) + int16_t index; +#else + int32_t index; +#endif +}; + +[[vk::push_constant]] +PushConstants pushConstants; + +[shader("vertex")] +float4 vertexMain() : SV_POSITION +{ + return float4(pushConstants.color); +} diff --git a/tests/spirv/capability-uniform-and-storage.slang b/tests/spirv/capability-uniform-and-storage.slang new file mode 100644 index 000000000..665a6b91a --- /dev/null +++ b/tests/spirv/capability-uniform-and-storage.slang @@ -0,0 +1,65 @@ +//TEST:SIMPLE(filecheck=CHECK8): -target spirv -profile spirv_1_3 -DIN_UINT8 +//TEST:SIMPLE(filecheck=CHECK16): -target spirv -profile spirv_1_3 -DIN_UINT16 +//TEST:SIMPLE(filecheck=CHECK16): -target spirv -profile spirv_1_3 -DIN_HALF +//TEST:SIMPLE(filecheck=CHECKBOTH): -target spirv -profile spirv_1_3 -DIN_UINT8 -DIN_HALF +//TEST:SIMPLE(filecheck=CHECK8): -target spirv -profile spirv_1_3 -DOUT_UINT8 +//TEST:SIMPLE(filecheck=CHECK16): -target spirv -profile spirv_1_3 -DOUT_UINT16 +//TEST:SIMPLE(filecheck=CHECK16): -target spirv -profile spirv_1_3 -DOUT_HALF +//TEST:SIMPLE(filecheck=CHECK16): -target spirv -profile spirv_1_3 -DOUT_HALF -DATOMIC +//TEST:SIMPLE(filecheck=CHECK): -target spirv -profile spirv_1_3 + +//CHECK8: OpCapability UniformAndStorageBuffer8BitAccess +//CHECK8-NOT: OpCapability UniformAndStorageBuffer16BitAccess +//CHECK16: OpCapability UniformAndStorageBuffer16BitAccess +//CHECK16-NOT: OpCapability UniformAndStorageBuffer8BitAccess +//CHECKBOTH-DAG: OpCapability UniformAndStorageBuffer8BitAccess +//CHECKBOTH-DAG: OpCapability UniformAndStorageBuffer16BitAccess +//CHECK-NOT: OpCapability UniformAndStorageBuffer8BitAccess +//CHECK-NOT: OpCapability UniformAndStorageBuffer16BitAccess + + +uniform struct { +#if defined(IN_HALF) + half4 data; +#else + float4 data; +#endif +#if defined(IN_UINT8) + uint8_t index; +#elif defined(IN_UINT16) + uint16_t index; +#else + uint32_t index; +#endif +} inputBuffer; + +#if defined(OUT_HALF) +#define OUT_FLOAT_TYPE half +#else +#define OUT_FLOAT_TYPE float +#endif +#if defined(OUT_UINT8) +#define OUT_UINT_TYPE uint8_t +#elif defined(OUT_UINT16) +#define OUT_UINT_TYPE uint16_t +#else +#define OUT_UINT_TYPE uint32_t +#endif + +struct st { +#if defined(ATOMIC) + Atomic data; +#else + OUT_FLOAT_TYPE data; +#endif + OUT_UINT_TYPE index; +}; +RWStructuredBuffer outputBuffer; + +[shader("compute")] +[numthreads(1, 1, 1)] +void computeMain() +{ + outputBuffer[0].data = OUT_FLOAT_TYPE(inputBuffer.data.x); + outputBuffer[1].index = OUT_UINT_TYPE(inputBuffer.index); +} -- cgit v1.2.3