[HLSL] Implement Texture2DMSArray for HLSL
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## References
- https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-texture2dmsarray
- https://github.com/llvm/wg-hlsl/blob/main/proposals/0037-texture-and-sampler-types.md
- https://github.com/llvm/wg-hlsl/blob/main/proposals/0015-resource-attributes-in-dxil-and-spirv.md
- https://github.com/llvm/wg-hlsl/blob/main/proposals/0006-resource-representations.md
## Description
Add `Texture2DMSArray` to the HLSL front-end. This is a multisampled, arrayed 2D texture. It uses `ResourceDimension::Dim2D` with `IsMultiSampled=true` and `IsArray=true`. Unlike regular textures, `Texture2DMSArray` does **not** support any Sample/SampleBias/SampleGrad/SampleLevel/SampleCmp methods, Gather, CalculateLevelOfDetail, or mips. It uses a distinct `Load` that takes a sample index parameter.
Template: `Texture2DMSArray`
## Tasks
- [ ] **Register the type** in `clang/lib/Sema/HLSLExternalSemaSource.cpp`
- Declare `Texture2DMSArray` template with `element_type` (default `float4`) and `int sample_count` (default 1) parameters
- Wire `onCompletion` to a setup function that:
- Calls `addTextureHandle` with `RC=SRV`, `IsROV=false`, `Dim=Dim2D`, `IsMultiSampled=true`, `IsArray=true`
- Adds MS-specific Load (with sample index parameter)
- Adds `operator[]` (with `int3` index: x, y, arrayIndex)
- Skips Sample/SampleBias/SampleGrad/SampleLevel/SampleCmp/Gather/GatherCmp/CalculateLevelOfDetail/mips
- [ ] **Add MS-specific Load method** in `clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp` (shared with Texture2DMS)
- `T Load(int3 location, int sampleIndex)` — location is (x, y, arrayIndex)
- `T Load(int3 location, int sampleIndex, int2 offset)`
- Uses `__builtin_hlsl_resource_load_ms` builtin
- [ ] **Write tests**
Add tests for Texture2DMSArray to the following files:
- AST (`clang/test/AST/HLSL/`): `Textures-AST.hlsl`
- CodeGen (`clang/test/CodeGenHLSL/resources/`): `Textures-Load.hlsl`, `Textures-Subscript.hlsl`, `Textures-default.hlsl`
- Sema (`clang/test/SemaHLSL/Resources/`): `Textures-Sema.hlsl`
Contributor guide
Assessment
This issue has not been assessed yet.