diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2024-09-23 16:32:47 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-23 16:32:47 -0700 |
| commit | 3e950e11f46fa3d2a84f04345ea860907ae9715a (patch) | |
| tree | 13c115fb9c41f6ceb6c270f35822cd762f624f68 /source/slang/slang-ir-lower-combined-texture-sampler.cpp | |
| parent | 14b1098c934927898488c057b8c517da84990595 (diff) | |
Implemented Combined-texture for WGSL (#5130)
* Implemented Combined-texture for WGSL
* Remove unnecessary comment
* Limit to std430 layout
* Fix compiler warning for unused variable
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-ir-lower-combined-texture-sampler.cpp')
| -rw-r--r-- | source/slang/slang-ir-lower-combined-texture-sampler.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/source/slang/slang-ir-lower-combined-texture-sampler.cpp b/source/slang/slang-ir-lower-combined-texture-sampler.cpp index b6f65c933..656bd84a6 100644 --- a/source/slang/slang-ir-lower-combined-texture-sampler.cpp +++ b/source/slang/slang-ir-lower-combined-texture-sampler.cpp @@ -19,6 +19,7 @@ namespace Slang struct LowerCombinedSamplerContext { Dictionary<IRType*, LoweredCombinedSamplerStructInfo> mapTypeToLoweredInfo; + CodeGenTarget codeGenTarget; LoweredCombinedSamplerStructInfo lowerCombinedTextureSamplerType(IRTextureTypeBase* textureType) { @@ -57,8 +58,16 @@ namespace Slang builder.createStructField(structType, info.sampler, info.samplerType); // Type layout. - - auto textureResourceKind = isMutable ? LayoutResourceKind::UnorderedAccess : LayoutResourceKind::ShaderResource; + + bool isWGSLTarget = codeGenTarget == CodeGenTarget::WGSL; + LayoutResourceKind textureResourceKind = isMutable ? LayoutResourceKind::UnorderedAccess : LayoutResourceKind::ShaderResource; + LayoutResourceKind samplerResourceKind = LayoutResourceKind::SamplerState; + if (isWGSLTarget) + { + textureResourceKind = LayoutResourceKind::DescriptorTableSlot; + samplerResourceKind = LayoutResourceKind::DescriptorTableSlot; + } + IRTypeLayout::Builder textureTypeLayoutBuilder(&builder); textureTypeLayoutBuilder.addResourceUsage( textureResourceKind, @@ -67,7 +76,7 @@ namespace Slang IRTypeLayout::Builder samplerTypeLayoutBuilder(&builder); samplerTypeLayoutBuilder.addResourceUsage( - LayoutResourceKind::SamplerState, + samplerResourceKind, LayoutSize(1)); auto samplerTypeLayout = samplerTypeLayoutBuilder.build(); @@ -76,7 +85,7 @@ namespace Slang auto textureVarLayout = textureVarLayoutBuilder.build(); IRVarLayout::Builder samplerVarLayoutBuilder(&builder, samplerTypeLayout); - samplerVarLayoutBuilder.findOrAddResourceInfo(LayoutResourceKind::SamplerState)->offset = 0; + samplerVarLayoutBuilder.findOrAddResourceInfo(samplerResourceKind)->offset = isWGSLTarget ? 1 : 0; auto samplerVarLayout = samplerVarLayoutBuilder.build(); IRStructTypeLayout::Builder layoutBuilder(&builder); @@ -91,12 +100,14 @@ namespace Slang }; void lowerCombinedTextureSamplers( + CodeGenContext* codeGenContext, IRModule* module, DiagnosticSink* sink) { SLANG_UNUSED(sink); LowerCombinedSamplerContext context; + context.codeGenTarget = codeGenContext->getTargetFormat(); // Lower combined texture sampler type into a struct type. for (auto globalInst : module->getGlobalInsts()) @@ -127,12 +138,13 @@ namespace Slang for (auto offsetAttr : varLayout->getOffsetAttrs()) { - if (offsetAttr->getResourceKind() == LayoutResourceKind::UnorderedAccess || - offsetAttr->getResourceKind() == LayoutResourceKind::ShaderResource) + LayoutResourceKind resKind = offsetAttr->getResourceKind(); + if (resKind == LayoutResourceKind::UnorderedAccess || + resKind == LayoutResourceKind::ShaderResource) resOffsetAttr = offsetAttr; - else if (offsetAttr->getResourceKind() == LayoutResourceKind::DescriptorTableSlot) + else if (resKind == LayoutResourceKind::DescriptorTableSlot) descriptorTableSlotOffsetAttr = offsetAttr; - auto info = newVarLayoutBuilder.findOrAddResourceInfo(offsetAttr->getResourceKind()); + auto info = newVarLayoutBuilder.findOrAddResourceInfo(resKind); info->offset = offsetAttr->getOffset(); info->space = offsetAttr->getSpace(); info->kind = offsetAttr->getResourceKind(); |
