Skip to content

Commit

Permalink
Support status argument for GatherXXX (shader-slang#4490)
Browse files Browse the repository at this point in the history
* 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 shader-slang#4466

Limit Gather with status to HLSL

Exclude Gather-status test from VK

* Fix capability errors

---------

Co-authored-by: Yong He <yonghe@outlook.com>
  • Loading branch information
jkwak-work and csyonghe authored Jul 10, 2024
1 parent 4a24724 commit 59343c1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 21 deletions.
51 changes: 42 additions & 9 deletions source/slang/hlsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -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

${{{{
Expand Down
48 changes: 36 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,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()
*/
Expand Down Expand Up @@ -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
// DX12: 340
// DX12: 340
// DX12: 340
// DX12: 340
// DX12CS6: 363
// DX12CS6: 363
// DX12CS6: 363
// DX12CS6: 363
// VK: 351
// VK: 351
// VK: 351
// VK: 351

0 comments on commit 59343c1

Please sign in to comment.