diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2024-07-10 10:55:07 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-10 10:55:07 -0700 |
| commit | 59343c18928e476b7949a8700c5a792820da8656 (patch) | |
| tree | d4dfd04c760cfa8c7b24b929ce0a64c793945821 | |
| parent | 4a247244715e35872ab2359e9bc7cd55b5ea27d4 (diff) | |
Support status argument for GatherXXX (#4490)
* Support status argument for GatherXXX
This commit adds an argument to all texture GatherXXX functions.
The new argument is for "status" as described in SM5.0 definision.
Close #4466
Limit Gather with status to HLSL
Exclude Gather-status test from VK
* Fix capability errors
---------
Co-authored-by: Yong He <yonghe@outlook.com>
| -rw-r--r-- | source/slang/hlsl.meta.slang | 51 | ||||
| -rw-r--r-- | tests/hlsl-intrinsic/texture/texture-intrinsics.slang | 48 |
2 files changed, 78 insertions, 21 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 5564094db..17e2822a3 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -2328,55 +2328,88 @@ ${{{{ { auto componentName = componentNames[componentId]; auto glslComponent = (isCmp ? "" :glslComponentNames[componentId == 0 ? 0 : componentId - 1]); - }}}} + + for (bool isStatus : { false, true }) + { + const char* statusDecl = isStatus ? ", out uint status" : ""; + const char* statusInit = isStatus ? " status = 0;\n" : ""; + const char* statusCapWithMetal = isStatus ? "hlsl" : "glsl_hlsl_metal_spirv"; + const char* statusCapWithoutMetal = isStatus ? "hlsl" : "glsl_hlsl_spirv"; +}}}} [ForceInline] - [require(glsl_hlsl_metal_spirv, texture_gather)] - vector<T,4> Gather$(cmp)$(componentName)($(samplerStateType)$(samplerStateParam) vector<float, Shape.dimensions+isArray> location $(cmpParam)) + [require($(statusCapWithMetal), texture_gather)] + vector<T,4> Gather$(cmp)$(componentName)($(samplerStateType)$(samplerStateParam) vector<float, Shape.dimensions+isArray> location $(cmpParam) $(statusDecl)) { + $(statusInit) __target_switch { case hlsl: __intrinsic_asm ".Gather$(cmp)$(componentName)"; +${{{{ + if (!isStatus) + { +}}}} case metal: return __texture_gather$(cmp)<T>($(getTexture),$(getSampler) location $(compareArg) $(glslComponent)); case glsl: case spirv: return __texture_gather$(cmp)<T>(this,$(samplerStateParam) location $(compareArg) $(glslComponent)); +${{{{ + } // if(!isStatus) +}}}} } } [ForceInline] - [require(glsl_hlsl_metal_spirv, texture_gather)] - vector<T,4> Gather$(cmp)$(componentName)($(samplerStateType)$(samplerStateParam) vector<float, Shape.dimensions+isArray> location $(cmpParam), constexpr vector<int, Shape.planeDimensions> offset) + [require($(statusCapWithMetal), texture_gather)] + vector<T,4> Gather$(cmp)$(componentName)($(samplerStateType)$(samplerStateParam) vector<float, Shape.dimensions+isArray> location $(cmpParam), constexpr vector<int, Shape.planeDimensions> offset $(statusDecl)) { + $(statusInit) __target_switch { case hlsl: __intrinsic_asm ".Gather$(cmp)$(componentName)"; +${{{{ + if (!isStatus) + { +}}}} case metal: return __texture_gather$(cmp)_offset<T>($(getTexture),$(getSampler) location $(compareArg), offset $(glslComponent)); case glsl: case spirv: return __texture_gather$(cmp)_offset<T>(this,$(samplerStateParam) location $(compareArg), offset $(glslComponent)); +${{{{ + } // if(!isStatus) +}}}} } } [ForceInline] - [require(glsl_hlsl_spirv, texture_gather)] + [require($(statusCapWithoutMetal), texture_gather)] vector<T,4> Gather$(cmp)$(componentName)($(samplerStateType)$(samplerStateParam) vector<float, Shape.dimensions+isArray> location $(cmpParam), constexpr vector<int, Shape.planeDimensions> offset1, constexpr vector<int, Shape.planeDimensions> offset2, constexpr vector<int, Shape.planeDimensions> offset3, - constexpr vector<int, Shape.planeDimensions> offset4) + constexpr vector<int, Shape.planeDimensions> offset4 + $(statusDecl)) { + $(statusInit) __target_switch { case hlsl: __intrinsic_asm ".Gather$(cmp)$(componentName)"; +${{{{ + if (!isStatus) + { +}}}} case glsl: case spirv: return __texture_gather$(cmp)_offsets<T>(this,$(samplerStateParam) location $(compareArg), offset1,offset2,offset3,offset4 $(glslComponent)); +${{{{ + } // if(!isStatus) +}}}} } } - ${{{{ +${{{{ + } // for (isStatus) } // for (componentId) } // for (isCmp) - }}}} +}}}} } // end extension for gather ${{{{ diff --git a/tests/hlsl-intrinsic/texture/texture-intrinsics.slang b/tests/hlsl-intrinsic/texture/texture-intrinsics.slang index 09b7c30fb..8ae3b2fda 100644 --- a/tests/hlsl-intrinsic/texture/texture-intrinsics.slang +++ b/tests/hlsl-intrinsic/texture/texture-intrinsics.slang @@ -43,6 +43,8 @@ void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) uint numLevels = 0, elements = 0; float fnumLevels = 0.0f, felements = 0.0f; + uint status; + /* <Template Type> Object.SampleLevel() */ @@ -244,6 +246,28 @@ void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) f4 = t2DArray.Gather(samplerState, float3(u, u, 0), int2(0, 0)); val += f4.x; val += f4.y; val += f4.z; val += f4.w; + // Object.GatherGreen() + f4 = t2D.GatherGreen(samplerState, float2(u, u), int2(1, 2)); + val += f4.x; val += f4.y; val += f4.z; val += f4.w; + + f4 = t2D.GatherGreen(samplerState, float2(u, u), int2(1, 2), int2(3, 4), int2(5, 6), int2(7, 8)); + val += f4.x; val += f4.y; val += f4.z; val += f4.w; + + f4 = tCubeArray.GatherGreen(samplerState, float4(1.5, 1.5, 1.5, 1.5)); + val += f4.x; val += f4.y; val += f4.z; val += f4.w; + + // status variant +#if !defined(VK) + f4 = t2D.GatherGreen(samplerState, float2(u, u), int2(1, 2), status); + val += f4.x; val += f4.y; val += f4.z; val += f4.w; + + f4 = t2D.GatherGreen(samplerState, float2(u, u), int2(1, 2), int2(3, 4), int2(5, 6), int2(7, 8), status); + val += f4.x; val += f4.y; val += f4.z; val += f4.w; + + f4 = tCubeArray.GatherGreen(samplerState, float4(1.5, 1.5, 1.5, 1.5), status); + val += f4.x; val += f4.y; val += f4.z; val += f4.w; +#endif + /* ret Object.Load() */ @@ -289,15 +313,15 @@ void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) // DX11: 313 // DX11: 313 // DX11: 313 -// DX12: 316 -// DX12: 316 -// DX12: 316 -// DX12: 316 -// DX12CS6: 339 -// DX12CS6: 339 -// DX12CS6: 339 -// DX12CS6: 339 -// VK: 339 -// VK: 339 -// VK: 339 -// VK: 339
\ No newline at end of file +// DX12: 340 +// DX12: 340 +// DX12: 340 +// DX12: 340 +// DX12CS6: 363 +// DX12CS6: 363 +// DX12CS6: 363 +// DX12CS6: 363 +// VK: 351 +// VK: 351 +// VK: 351 +// VK: 351 |
