diff options
| author | ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> | 2024-06-24 09:16:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-24 09:16:28 -0400 |
| commit | cf8d1ceffcfbbb64734e6180a2c0cebd033f5b2e (patch) | |
| tree | 5ccbc854e3c363822d6e85c2fb5812d7c2572381 /source/slang/slang-type-layout.cpp | |
| parent | d349fd9e1f65fd32b2f4ea0e38c5084256d0dd04 (diff) | |
Implementing `tbuffer` layout(s) (#4436)
* Implementing `tbuffer` layouts.
1. Add to layout options 'TextureBuffer' layouts.
2. Add on to existing logic a way to allocate appropriate registers for TextureBufferType (this was made to work with parameter block logic).
3. Added asserts so objects missing a layout will gracefully crash
This means `tbuffer` now works for hlsl,glsl,metal targets, spirv has yet to implement logic for `TextureBufferType`.
* disable metal tests and fix emitting code a bit
fixing the emitting code means metal compilation emits a useful error (help point users/developers to #4435)
* fix warning
Diffstat (limited to 'source/slang/slang-type-layout.cpp')
| -rw-r--r-- | source/slang/slang-type-layout.cpp | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index 1aeaceb72..22aa3f304 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -917,7 +917,7 @@ struct GLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl virtual LayoutRulesImpl* getAnyValueRules() override; virtual LayoutRulesImpl* getConstantBufferRules(CompilerOptionSet& compilerOptions) override; virtual LayoutRulesImpl* getPushConstantBufferRules() override; - virtual LayoutRulesImpl* getTextureBufferRules() override; + virtual LayoutRulesImpl* getTextureBufferRules(CompilerOptionSet& compilerOptions) override; virtual LayoutRulesImpl* getVaryingInputRules() override; virtual LayoutRulesImpl* getVaryingOutputRules() override; virtual LayoutRulesImpl* getSpecializationConstantRules() override; @@ -938,7 +938,7 @@ struct HLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl virtual LayoutRulesImpl* getAnyValueRules() override; virtual LayoutRulesImpl* getConstantBufferRules(CompilerOptionSet& compilerOptions) override; virtual LayoutRulesImpl* getPushConstantBufferRules() override; - virtual LayoutRulesImpl* getTextureBufferRules() override; + virtual LayoutRulesImpl* getTextureBufferRules(CompilerOptionSet& compilerOptions) override; virtual LayoutRulesImpl* getVaryingInputRules() override; virtual LayoutRulesImpl* getVaryingOutputRules() override; virtual LayoutRulesImpl* getSpecializationConstantRules() override; @@ -959,7 +959,7 @@ struct CPULayoutRulesFamilyImpl : LayoutRulesFamilyImpl virtual LayoutRulesImpl* getAnyValueRules() override; virtual LayoutRulesImpl* getConstantBufferRules(CompilerOptionSet& compilerOptions) override; virtual LayoutRulesImpl* getPushConstantBufferRules() override; - virtual LayoutRulesImpl* getTextureBufferRules() override; + virtual LayoutRulesImpl* getTextureBufferRules(CompilerOptionSet& compilerOptions) override; virtual LayoutRulesImpl* getVaryingInputRules() override; virtual LayoutRulesImpl* getVaryingOutputRules() override; virtual LayoutRulesImpl* getSpecializationConstantRules() override; @@ -979,7 +979,7 @@ struct CUDALayoutRulesFamilyImpl : LayoutRulesFamilyImpl virtual LayoutRulesImpl* getAnyValueRules() override; virtual LayoutRulesImpl* getConstantBufferRules(CompilerOptionSet& compilerOptions) override; virtual LayoutRulesImpl* getPushConstantBufferRules() override; - virtual LayoutRulesImpl* getTextureBufferRules() override; + virtual LayoutRulesImpl* getTextureBufferRules(CompilerOptionSet& compilerOptions) override; virtual LayoutRulesImpl* getVaryingInputRules() override; virtual LayoutRulesImpl* getVaryingOutputRules() override; virtual LayoutRulesImpl* getSpecializationConstantRules() override; @@ -999,7 +999,7 @@ struct MetalLayoutRulesFamilyImpl : LayoutRulesFamilyImpl virtual LayoutRulesImpl* getAnyValueRules() override; virtual LayoutRulesImpl* getConstantBufferRules(CompilerOptionSet& compilerOptions) override; virtual LayoutRulesImpl* getPushConstantBufferRules() override; - virtual LayoutRulesImpl* getTextureBufferRules() override; + virtual LayoutRulesImpl* getTextureBufferRules(CompilerOptionSet& compilerOptions) override; virtual LayoutRulesImpl* getVaryingInputRules() override; virtual LayoutRulesImpl* getVaryingOutputRules() override; virtual LayoutRulesImpl* getSpecializationConstantRules() override; @@ -1255,6 +1255,10 @@ LayoutRulesImpl kHLSLStructuredBufferLayoutRulesImpl_ = { &kHLSLLayoutRulesFamilyImpl, &kHLSLStructuredBufferLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl, }; +LayoutRulesImpl kHLSLTextureBufferLayoutRulesImpl_ = { + &kHLSLLayoutRulesFamilyImpl, &kHLSLConstantBufferLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl, +}; + LayoutRulesImpl kHLSLVaryingInputLayoutRulesImpl_ = { &kHLSLLayoutRulesFamilyImpl, &kHLSLVaryingInputLayoutRulesImpl, &kHLSLObjectLayoutRulesImpl, }; @@ -1306,9 +1310,12 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getShaderRecordConstantBufferRules() return &kGLSLShaderRecordLayoutRulesImpl_; } -LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getTextureBufferRules() +LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getTextureBufferRules(CompilerOptionSet& compilerOptions) { - return nullptr; + if (compilerOptions.shouldUseScalarLayout()) + return &kScalarLayoutRulesImpl_; + return &kStd430LayoutRulesImpl_; + } LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getVaryingInputRules() @@ -1389,9 +1396,9 @@ LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getStructuredBufferRules(CompilerOpt return &kHLSLStructuredBufferLayoutRulesImpl_; } -LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getTextureBufferRules() +LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getTextureBufferRules(CompilerOptionSet&) { - return nullptr; + return &kHLSLTextureBufferLayoutRulesImpl_; } LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getVaryingInputRules() @@ -1446,9 +1453,9 @@ LayoutRulesImpl* CPULayoutRulesFamilyImpl::getPushConstantBufferRules() return &kCPULayoutRulesImpl_; } -LayoutRulesImpl* CPULayoutRulesFamilyImpl::getTextureBufferRules() +LayoutRulesImpl* CPULayoutRulesFamilyImpl::getTextureBufferRules(CompilerOptionSet&) { - return nullptr; + return &kCPULayoutRulesImpl_; } LayoutRulesImpl* CPULayoutRulesFamilyImpl::getVaryingInputRules() @@ -1512,9 +1519,9 @@ LayoutRulesImpl* CUDALayoutRulesFamilyImpl::getPushConstantBufferRules() return &kCUDALayoutRulesImpl_; } -LayoutRulesImpl* CUDALayoutRulesFamilyImpl::getTextureBufferRules() +LayoutRulesImpl* CUDALayoutRulesFamilyImpl::getTextureBufferRules(CompilerOptionSet&) { - return nullptr; + return &kCUDALayoutRulesImpl_; } LayoutRulesImpl* CUDALayoutRulesFamilyImpl::getVaryingInputRules() @@ -1702,9 +1709,9 @@ LayoutRulesImpl* MetalLayoutRulesFamilyImpl::getStructuredBufferRules(CompilerOp return &kMetalStructuredBufferLayoutRulesImpl_; } -LayoutRulesImpl* MetalLayoutRulesFamilyImpl::getTextureBufferRules() +LayoutRulesImpl* MetalLayoutRulesFamilyImpl::getTextureBufferRules(CompilerOptionSet&) { - return nullptr; + return &kMetalConstantBufferLayoutRulesImpl_; } LayoutRulesImpl* MetalLayoutRulesFamilyImpl::getVaryingInputRules() @@ -2628,11 +2635,16 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout( if( wantConstantBuffer ) { // If there is any ordinary data, then we'll need to - // allocate a constant buffer regiser/binding into - // the overall layout, to account for it. + // allocate a constant buffer or tbuffer (if we have a tbuffer parameter group type) + // register/binding the overall layout, to account for this. // - auto cbUsage = parameterGroupRules->GetObjectLayout(ShaderParameterKind::ConstantBuffer, context.objectLayoutOptions); - for (auto layoutInfo : cbUsage.layoutInfos) + ShaderParameterKind parameterKind = ShaderParameterKind::ConstantBuffer; + if (as<TextureBufferType>(parameterGroupType)) + { + parameterKind = ShaderParameterKind::TextureUniformBuffer; + } + auto bufferUsage = parameterGroupRules->GetObjectLayout(parameterKind, context.objectLayoutOptions); + for (auto layoutInfo : bufferUsage.layoutInfos) containerTypeLayout->addResourceUsage(layoutInfo.kind, layoutInfo.size); } @@ -3048,7 +3060,7 @@ LayoutRulesImpl* getParameterBufferElementTypeLayoutRules( } else if( as<TextureBufferType>(parameterGroupType) ) { - return rules->getLayoutRulesFamily()->getTextureBufferRules(); + return rules->getLayoutRulesFamily()->getTextureBufferRules(compilerOptions); } else if( as<GLSLInputParameterGroupType>(parameterGroupType) ) { |
