diff options
| author | Yong He <yonghe@outlook.com> | 2024-06-07 21:42:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-07 21:42:45 -0700 |
| commit | 2a45bc312d9e4d2bc7d4ef0f172dd54750133b35 (patch) | |
| tree | e5d174d775f99e3c2e911271f89c079a5454b8d3 | |
| parent | 056a4b94743f6bab01fd95822c4ab34dd2c58a76 (diff) | |
Support HLSL `.mips` syntax. (#4310)
| -rw-r--r-- | source/slang/hlsl.meta.slang | 31 | ||||
| -rw-r--r-- | tests/hlsl/texture-mips-operator.slang | 13 |
2 files changed, 44 insertions, 0 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index defb27ce3..f9831bef2 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -3050,6 +3050,37 @@ ${{{{ } // for (access). }}}} +// Definitions to support the legacy texture .mips[][] operator. +struct __TextureMip<T, Shape : __ITextureShape, let isArray : int, let isCombined : int, let format : int> +{ + __TextureImpl<T, Shape, isArray, 0 /*isMS*/, 0 /*sampleCount*/, 0 /*access*/, 0 /*isShadow*/, isCombined, format> tex; + int mip; + __subscript(vector<int, isArray + Shape.dimensions> pos)->T + { + [__unsafeForceInlineEarly] + get { return tex.Load(__makeVector(pos, mip)); } + } +} +struct __TextureMips<T, Shape : __ITextureShape, let isArray : int, let isCombined : int, let format : int> +{ + __TextureImpl<T, Shape, isArray, 0 /*isMS*/, 0 /*sampleCount*/, 0 /*access*/, 0 /*isShadow*/, isCombined, format> tex; + __subscript(int mip)->__TextureMip<T, Shape, isArray, isCombined, format> + { + [__unsafeForceInlineEarly] + get { return { tex, mip }; } + } +} + +__generic<T, Shape : __ITextureShape, let isArray : int, let isCombined : int, let format : int> +extension __TextureImpl<T, Shape, isArray, 0 /*isMS*/, 0 /*sampleCount*/, 0 /*access*/, 0 /*isShadow*/, isCombined, format> +{ + property __TextureMips<T, Shape, isArray, isCombined, format> mips + { + [__unsafeForceInlineEarly] + get { return { this }; } + } +} + // Texture type aliases. // T, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int ${{{{ diff --git a/tests/hlsl/texture-mips-operator.slang b/tests/hlsl/texture-mips-operator.slang new file mode 100644 index 000000000..9da8711c5 --- /dev/null +++ b/tests/hlsl/texture-mips-operator.slang @@ -0,0 +1,13 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +// CHECK: OpImageFetch %v4float {{.*}} Lod %int_1 + +RWStructuredBuffer<float4> result; + +uniform Texture2D gTex; + +[numthreads(1,1,1)] +void main() +{ + result[0] = gTex.mips[1][int2(3,4)]; +}
\ No newline at end of file |
