From d9c57e613f2dacd221d9c46c10395cf373a8fcaf Mon Sep 17 00:00:00 2001 From: Theresa Foley <10618364+tangent-vector@users.noreply.github.com> Date: Mon, 10 Jul 2023 17:48:51 -0700 Subject: Add support for texture footprint queries (#2970) --- .../nv-shader-texture-footprint-simple.slang | 72 ++++++ .../footprint/nv-shader-texture-footprint.slang | 250 +++++++++++++++++++++ 2 files changed, 322 insertions(+) create mode 100644 tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint-simple.slang create mode 100644 tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint.slang (limited to 'tests/gpu-feature') diff --git a/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint-simple.slang b/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint-simple.slang new file mode 100644 index 000000000..b219ca829 --- /dev/null +++ b/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint-simple.slang @@ -0,0 +1,72 @@ +//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry fragmentMain -stage fragment +//DISABLED_TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry fragmentMain -stage fragment +//TEST:SIMPLE(filecheck=HLSL):-target hlsl -entry fragmentMain -stage fragment + +//DISABLED_TEST:SIMPLE:-target spirv-assembly -entry fragmentMain -stage fragment +//DISABLED_TEST:SIMPLE:-target dxil-assembly -entry fragmentMain -stage fragment +//DISABLED_TEST:SIMPLE:-target hlsl -entry fragmentMain -stage fragment + +// In order to make sure that all of the data produced in each +// query is referenced (and thus cannot be DCE'd away), we maintain +// single accumulator that will have the bits of each query result +// mixed into it. + +void accumulate(inout uint r, uint u) +{ + r = r ^ u; +} + +void accumulate(inout uint r, bool b) +{ + accumulate(r, uint(b)); +} + +void accumulate(inout uint r, uint2 u) +{ + accumulate(r, u.x); + accumulate(r, u.y); +} + +void accumulate(inout uint r, uint3 u) +{ + accumulate(r, u.x); + accumulate(r, u.y); + accumulate(r, u.z); +} + +void accumulate(inout uint r, TextureFootprint2D f) +{ + accumulate(r, f.anchor); + accumulate(r, f.offset); + accumulate(r, f.mask); + accumulate(r, f.lod); + accumulate(r, f.granularity); + accumulate(r, f.isSingleLevel); +} + +uniform Texture2D texture; +uniform SamplerState sampler; +uniform RWStructuredBuffer outputBuffer; + +cbuffer Uniforms +{ + uniform float2 coords; + uniform uint granularity; +}; + +void fragmentMain( + float v : VARYING) +{ + uint index = uint(v); + uint r = 0; + + accumulate(r, texture.queryFootprintCoarse(granularity, sampler, coords)); + +// SPIRV: Extension "SPV_NV_shader_image_footprint" +// SPIRV: ImageSampleFootprintNV + +// HLSL: NvFootprintCoarse + + outputBuffer[index] = r; +} + diff --git a/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint.slang b/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint.slang new file mode 100644 index 000000000..12ccd59fc --- /dev/null +++ b/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint.slang @@ -0,0 +1,250 @@ +//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry fragmentMain -stage fragment -DENABLE_CLAMP +//DISABLED_TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry fragmentMain -stage fragment +//TEST:SIMPLE(filecheck=HLSL):-target hlsl -entry fragmentMain -stage fragment + +//DISABLED_TEST:SIMPLE:-target spirv-assembly -entry fragmentMain -stage fragment -DENABLE_CLAMP +//DISABLED_TEST:SIMPLE:-target dxil-assembly -entry fragmentMain -stage fragment +//DISABLED_TEST:SIMPLE:-target hlsl -entry fragmentMain -stage fragment + +// In order to make sure that all of the data produced in each +// query is referenced (and thus cannot be DCE'd away), we maintain +// single accumulator that will have the bits of each query result +// mixed into it. + +void accumulate(inout uint r, uint u) +{ + r = r ^ u; +} + +void accumulate(inout uint r, bool b) +{ + accumulate(r, uint(b)); +} + +void accumulate(inout uint r, uint2 u) +{ + accumulate(r, u.x); + accumulate(r, u.y); +} + +void accumulate(inout uint r, uint3 u) +{ + accumulate(r, u.x); + accumulate(r, u.y); + accumulate(r, u.z); +} + +void accumulate_2D(inout uint r, TextureFootprint2D f) +{ + accumulate(r, f.anchor); +// HLSL-DAG: NvFootprintExtractAnchorTileLoc2D + + accumulate(r, f.offset); +// HLSL-DAG: NvFootprintExtractOffset2D + + accumulate(r, f.mask); +// HLSL-DAG: NvFootprintExtractBitmask + + accumulate(r, f.lod); +// HLSL-DAG: NvFootprintExtractLOD + + accumulate(r, f.granularity); +// HLSL-DAG: NvFootprintExtractReturnGran + + accumulate(r, f.isSingleLevel); +} + +void accumulate_3D(inout uint r, TextureFootprint3D f) +{ + accumulate(r, f.anchor); +// HLSL-DAG: NvFootprintExtractAnchorTileLoc3D + + accumulate(r, f.offset); +// HLSL-DAG: NvFootprintExtractOffset3D + + accumulate(r, f.mask); +// HLSL-DAG: NvFootprintExtractBitmask + + accumulate(r, f.lod); +// HLSL-DAG: NvFootprintExtractLOD + + accumulate(r, f.granularity); +// HLSL-DAG: NvFootprintExtractReturnGran + + accumulate(r, f.isSingleLevel); +} + +// SPRIV: Extension "SPV_NV_shader_image_footprint" + +void fragmentMain( + float v : VARYING, + + uniform Texture2D texture_2D, +// SPIRV: TypeImage +// SPIRV-SAME: 2D + +// HLSL-DAG: Texture2D{{.*}}register(t0) + + uniform Texture3D texture_3D, +// SPIRV: TypeImage +// SPIRV-SAME: 3D + +// HLSL-DAG: Texture3D{{.*}}register(t1) + + uniform SamplerState sampler, + uniform RWStructuredBuffer outputBuffer, + uniform float4 c, + uniform float4 gx, + uniform float4 gy, + uniform uint g, + uniform float lodBias, + uniform float lodClamp, + uniform float lod) +{ + uint index = uint(v); + uint r = 0; + + TextureFootprint2D.Granularity granularity = g; + +#ifdef ENABLE_CLAMP +#define CLAMP(ARG) ARG +#else +#define CLAMP(ARG) /* empty */ +#endif + +#define TEST_COMMON(ND, COARSE_OR_FINE) \ + accumulate##ND(r, texture##ND.queryFootprint##COARSE_OR_FINE (granularity, sampler, coords )) ;\ + accumulate##ND(r, texture##ND.queryFootprint##COARSE_OR_FINE##Bias (granularity, sampler, coords, lodBias )) ;\ +CLAMP( accumulate##ND(r, texture##ND.queryFootprint##COARSE_OR_FINE##Clamp (granularity, sampler, coords, lodClamp ))) ;\ +CLAMP( accumulate##ND(r, texture##ND.queryFootprint##COARSE_OR_FINE##BiasClamp (granularity, sampler, coords, lodBias, lodClamp))) ;\ + accumulate##ND(r, texture##ND.queryFootprint##COARSE_OR_FINE##Level (granularity, sampler, coords, lod )) ;\ +/* end */ + +#define TEST_GRAD(ND, COARSE_OR_FINE) \ + accumulate##ND(r, texture##ND.queryFootprint##COARSE_OR_FINE##Grad (granularity, sampler, coords, dx, dy )) ;\ +CLAMP( accumulate##ND(r, texture##ND.queryFootprint##COARSE_OR_FINE##GradClamp (granularity, sampler, coords, dx, dy, lodClamp ))) ;\ +/* end */ + + +#define TEST_2D(COARSE_OR_FINE) \ + TEST_COMMON(_2D, COARSE_OR_FINE) \ + TEST_GRAD(_2D, COARSE_OR_FINE) \ + /* end */ + +#define TEST_3D(COARSE_OR_FINE) \ + TEST_COMMON(_3D, COARSE_OR_FINE) \ + /* end */ + +// SPIRV-DAG: [[TRUE:[0-9]+]]:{{.*}}ConstantTrue +// SPIRV-DAG: [[FALSE:[0-9]+]]:{{.*}}ConstantFalse + + { + let coords = c.xy; + let dx = gx.xy; + let dy = gy.xy; + + TEST_2D(Coarse); + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] +// HLSL-DAG: NvFootprintCoarse{{.*}}NV_EXTN_TEXTURE_2D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] Bias +// HLSL-DAG: NvFootprintCoarseBias{{.*}}NV_EXTN_TEXTURE_2D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] MinLod + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] Bias MinLod + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] Lod +// HLSL-DAG: NvFootprintCoarseLevel{{.*}}NV_EXTN_TEXTURE_2D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] Grad +// HLSL-DAG: NvFootprintCoarseGrad{{.*}}NV_EXTN_TEXTURE_2D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] Grad MinLod + + TEST_2D(Fine); + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] +// HLSL-DAG: NvFootprintFine{{.*}}NV_EXTN_TEXTURE_2D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] Bias +// HLSL-DAG: NvFootprintFineBias{{.*}}NV_EXTN_TEXTURE_2D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] MinLod + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] Bias MinLod + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] Lod +// HLSL-DAG: NvFootprintFineLevel{{.*}}NV_EXTN_TEXTURE_2D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] Grad +// HLSL-DAG: NvFootprintFineGrad{{.*}}NV_EXTN_TEXTURE_2D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] Grad MinLod + + } + + { + let coords = c.xyz; + let dx = gx.xyz; + let dy = gy.xyz; + + TEST_3D(Coarse); + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] +// HLSL-DAG: NvFootprintCoarse{{.*}}NV_EXTN_TEXTURE_3D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] Bias +// HLSL-DAG: NvFootprintCoarseBias{{.*}}NV_EXTN_TEXTURE_3D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] MinLod + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] Bias MinLod + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[TRUE]] Lod +// HLSL-DAG: NvFootprintCoarseLevel{{.*}}NV_EXTN_TEXTURE_3D + + TEST_3D(Fine); + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] +// HLSL-DAG: NvFootprintFine{{.*}}NV_EXTN_TEXTURE_3D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] Bias +// HLSL-DAG: NvFootprintFineBias{{.*}}NV_EXTN_TEXTURE_3D + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] MinLod + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] Bias MinLod + +// SPIRV: ImageSampleFootprintNV +// SPIRV-SAME: [[FALSE]] Lod +// HLSL-DAG: NvFootprintFineLevel{{.*}}NV_EXTN_TEXTURE_3D + + } + + outputBuffer[index] = r; +} -- cgit v1.2.3