Skip to content

Commit

Permalink
Support status argument for GatherXXX
Browse files Browse the repository at this point in the history
This commit adds an argument to all texture GatherXXX functions.
The new argument is for "status" as described in SM5.0 definision.

Close shader-slang#4466
  • Loading branch information
jkwak-work committed Jul 9, 2024
1 parent ddd14be commit df793d1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
22 changes: 16 additions & 6 deletions source/slang/hlsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -2328,11 +2328,17 @@ ${{{{
{
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" : "";
}}}}
[ForceInline]
[require(glsl_hlsl_metal_spirv, texture_gather)]
vector<T,4> Gather$(cmp)$(componentName)($(samplerStateType)$(samplerStateParam) vector<float, Shape.dimensions+isArray> location $(cmpParam))
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)";
Expand All @@ -2345,8 +2351,9 @@ ${{{{
}
[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)
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)";
Expand All @@ -2363,8 +2370,10 @@ ${{{{
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)";
Expand All @@ -2373,10 +2382,11 @@ ${{{{
return __texture_gather$(cmp)_offsets<T>(this,$(samplerStateParam) location $(compareArg), offset1,offset2,offset3,offset4 $(glslComponent));
}
}
${{{{
${{{{
} // for (isStatus)
} // for (componentId)
} // for (isCmp)
}}}}
}}}}
} // end extension for gather

${{{{
Expand Down
46 changes: 34 additions & 12 deletions tests/hlsl-intrinsic/texture/texture-intrinsics.slang
Original file line number Diff line number Diff line change
Expand Up @@ -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()
*/
Expand Down Expand Up @@ -244,6 +246,26 @@ 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
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;

/*
ret Object.Load()
*/
Expand Down Expand Up @@ -289,15 +311,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
// DX12: 340
// DX12: 340
// DX12: 340
// DX12: 340
// DX12CS6: 363
// DX12CS6: 363
// DX12CS6: 363
// DX12CS6: 363
// VK: 363
// VK: 363
// VK: 363
// VK: 363

0 comments on commit df793d1

Please sign in to comment.