diff options
| -rw-r--r-- | slang.h | 9 | ||||
| -rw-r--r-- | source/slang/diagnostics.h | 2 | ||||
| -rw-r--r-- | source/slang/emit.cpp | 5 | ||||
| -rw-r--r-- | source/slang/modifier-defs.h | 1 | ||||
| -rw-r--r-- | source/slang/parameter-binding.cpp | 7 | ||||
| -rw-r--r-- | source/slang/parser.cpp | 1 | ||||
| -rw-r--r-- | source/slang/type-layout.cpp | 29 | ||||
| -rw-r--r-- | source/slang/type-layout.h | 9 | ||||
| -rw-r--r-- | tests/rewriter/resources-in-structs.glsl | 2 |
9 files changed, 57 insertions, 8 deletions
@@ -440,6 +440,7 @@ extern "C" enum { SLANG_PARAMETER_CATEGORY_NONE, + SLANG_PARAMETER_CATEGORY_MIXED, SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER, SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE, SLANG_PARAMETER_CATEGORY_UNORDERED_ACCESS, @@ -449,7 +450,10 @@ extern "C" SLANG_PARAMETER_CATEGORY_UNIFORM, SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT, SLANG_PARAMETER_CATEGORY_SPECIALIZATION_CONSTANT, - SLANG_PARAMETER_CATEGORY_MIXED, + SLANG_PARAMETER_CATEGORY_PUSH_CONSTANT_BUFFER, + + // + SLANG_PARAMETER_CATEGORY_COUNT, }; typedef SlangUInt32 SlangStage; @@ -686,6 +690,7 @@ namespace slang { // TODO: these aren't scoped... None = SLANG_PARAMETER_CATEGORY_NONE, + Mixed = SLANG_PARAMETER_CATEGORY_MIXED, ConstantBuffer = SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER, ShaderResource = SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE, UnorderedAccess = SLANG_PARAMETER_CATEGORY_UNORDERED_ACCESS, @@ -695,7 +700,7 @@ namespace slang Uniform = SLANG_PARAMETER_CATEGORY_UNIFORM, DescriptorTableSlot = SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT, SpecializationConstant = SLANG_PARAMETER_CATEGORY_SPECIALIZATION_CONSTANT, - Mixed = SLANG_PARAMETER_CATEGORY_MIXED, + PushConstantBuffer = SLANG_PARAMETER_CATEGORY_PUSH_CONSTANT_BUFFER, }; struct TypeLayoutReflection diff --git a/source/slang/diagnostics.h b/source/slang/diagnostics.h index 6957fc763..988cb742b 100644 --- a/source/slang/diagnostics.h +++ b/source/slang/diagnostics.h @@ -206,7 +206,7 @@ namespace Slang #define SLANG_UNIMPLEMENTED(sink, pos, what) \ (sink)->diagnose(Slang::CodePosition(__LINE__, 0, 0, __FILE__), Slang::Diagnostics::unimplemented, what) -#define SLANG_UNREACHABLE(msg) do { assert(!"ureachable code:" msg); exit(1); } while(0) +#define SLANG_UNREACHABLE(msg) do { assert(!"ureachable code:" msg); throw 0; } while(0) #else #define SLANG_INTERNAL_ERROR(sink, pos) \ (sink)->diagnose(pos, Slang::Diagnostics::internalCompilerError) diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 21c91a5c0..88b80589a 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -3161,6 +3161,11 @@ struct EmitVisitor } Emit(")\n"); break; + + case LayoutResourceKind::PushConstantBuffer: + Emit("layout(push_constant)\n"); + break; + } } diff --git a/source/slang/modifier-defs.h b/source/slang/modifier-defs.h index 9806a12a5..665551b35 100644 --- a/source/slang/modifier-defs.h +++ b/source/slang/modifier-defs.h @@ -109,6 +109,7 @@ SIMPLE_SYNTAX_CLASS(GLSLConstantIDLayoutModifier , GLSLParsedLayoutModifier) SIMPLE_SYNTAX_CLASS(GLSLBindingLayoutModifier , GLSLParsedLayoutModifier) SIMPLE_SYNTAX_CLASS(GLSLSetLayoutModifier , GLSLParsedLayoutModifier) SIMPLE_SYNTAX_CLASS(GLSLLocationLayoutModifier , GLSLParsedLayoutModifier) +SIMPLE_SYNTAX_CLASS(GLSLPushConstantLayoutModifier, GLSLParsedLayoutModifier) // A catch-all for single-keyword modifiers SIMPLE_SYNTAX_CLASS(SimpleModifier, Modifier) diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 0683c7f8c..01727fb36 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -101,7 +101,7 @@ struct ParameterBindingInfo enum { - kLayoutResourceKindCount = SLANG_PARAMETER_CATEGORY_MIXED, + kLayoutResourceKindCount = SLANG_PARAMETER_CATEGORY_COUNT, }; // Information on a single parameter @@ -290,6 +290,11 @@ getTypeLayoutForGlobalShaderParameter_GLSL( // any more. As such we also inspect the type // of the variable. + // We want to check for a constant-buffer type with a `push_constant` layout + // qualifier before we move on to anything else. + if (varDecl->HasModifier<GLSLPushConstantLayoutModifier>() && type->As<ConstantBufferType>()) + return CreateTypeLayout(type, rules->getPushConstantBufferRules()); + // TODO(tfoley): We have multiple variations of // the `uniform` modifier right now, and that // needs to get fixed... diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 8314b0930..e0ff85164 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -747,6 +747,7 @@ namespace Slang CASE(binding, GLSLBindingLayoutModifier); CASE(set, GLSLSetLayoutModifier); CASE(location, GLSLLocationLayoutModifier); + CASE(push_constant, GLSLPushConstantLayoutModifier); #undef CASE else diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp index 2977ee9b8..2e0f3035a 100644 --- a/source/slang/type-layout.cpp +++ b/source/slang/type-layout.cpp @@ -337,6 +337,19 @@ struct GLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl }; GLSLObjectLayoutRulesImpl kGLSLObjectLayoutRulesImpl; +struct GLSLPushConstantBufferObjectLayoutRulesImpl : GLSLObjectLayoutRulesImpl +{ + virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind kind) override + { + // Special-case the layout for a constant-buffer, because we don't + // want it to allocate a descriptor-table slot + return SimpleLayoutInfo(LayoutResourceKind::PushConstantBuffer, 1); + + return GLSLObjectLayoutRulesImpl::GetObjectLayout(kind); + } +}; +GLSLPushConstantBufferObjectLayoutRulesImpl kGLSLPushConstantBufferObjectLayoutRulesImpl_; + struct HLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl { virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind kind) override @@ -392,6 +405,7 @@ HLSLVaryingLayoutRulesImpl kHLSLVaryingOutputLayoutRulesImpl(LayoutResourceKind: struct GLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl { virtual LayoutRulesImpl* getConstantBufferRules() override; + virtual LayoutRulesImpl* getPushConstantBufferRules() override; virtual LayoutRulesImpl* getTextureBufferRules() override; virtual LayoutRulesImpl* getVaryingInputRules() override; virtual LayoutRulesImpl* getVaryingOutputRules() override; @@ -402,6 +416,7 @@ struct GLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl struct HLSLLayoutRulesFamilyImpl : LayoutRulesFamilyImpl { virtual LayoutRulesImpl* getConstantBufferRules() override; + virtual LayoutRulesImpl* getPushConstantBufferRules() override; virtual LayoutRulesImpl* getTextureBufferRules() override; virtual LayoutRulesImpl* getVaryingInputRules() override; virtual LayoutRulesImpl* getVaryingOutputRules() override; @@ -423,6 +438,10 @@ LayoutRulesImpl kStd430LayoutRulesImpl_ = { &kGLSLLayoutRulesFamilyImpl, &kStd430LayoutRulesImpl, &kGLSLObjectLayoutRulesImpl, }; +LayoutRulesImpl kGLSLPushConstantLayoutRulesImpl_ = { + &kGLSLLayoutRulesFamilyImpl, &kStd430LayoutRulesImpl, &kGLSLPushConstantBufferObjectLayoutRulesImpl_, +}; + LayoutRulesImpl kGLSLVaryingInputLayoutRulesImpl_ = { &kGLSLLayoutRulesFamilyImpl, &kGLSLVaryingInputLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl, }; @@ -460,6 +479,11 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getConstantBufferRules() return &kStd140LayoutRulesImpl_; } +LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getPushConstantBufferRules() +{ + return &kGLSLPushConstantLayoutRulesImpl_; +} + LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getTextureBufferRules() { return nullptr; @@ -492,6 +516,11 @@ LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getConstantBufferRules() return &kHLSLConstantBufferLayoutRulesImpl_; } +LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getPushConstantBufferRules() +{ + return &kHLSLConstantBufferLayoutRulesImpl_; +} + LayoutRulesImpl* HLSLLayoutRulesFamilyImpl::getTextureBufferRules() { return nullptr; diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h index add9930ae..d2254c9e5 100644 --- a/source/slang/type-layout.h +++ b/source/slang/type-layout.h @@ -517,10 +517,11 @@ struct LayoutRulesImpl struct LayoutRulesFamilyImpl { - virtual LayoutRulesImpl* getConstantBufferRules() = 0; - virtual LayoutRulesImpl* getTextureBufferRules() = 0; - virtual LayoutRulesImpl* getVaryingInputRules() = 0; - virtual LayoutRulesImpl* getVaryingOutputRules() = 0; + virtual LayoutRulesImpl* getConstantBufferRules() = 0; + virtual LayoutRulesImpl* getPushConstantBufferRules() = 0; + virtual LayoutRulesImpl* getTextureBufferRules() = 0; + virtual LayoutRulesImpl* getVaryingInputRules() = 0; + virtual LayoutRulesImpl* getVaryingOutputRules() = 0; virtual LayoutRulesImpl* getSpecializationConstantRules() = 0; virtual LayoutRulesImpl* getShaderStorageBufferRules() = 0; }; diff --git a/tests/rewriter/resources-in-structs.glsl b/tests/rewriter/resources-in-structs.glsl index 26e21f630..6273e8720 100644 --- a/tests/rewriter/resources-in-structs.glsl +++ b/tests/rewriter/resources-in-structs.glsl @@ -47,8 +47,10 @@ uniform texture2D SLANG_parameterBlock_U_m_t; layout(binding = 2) uniform sampler SLANG_parameterBlock_U_m_s; +layout(location = 0) in vec2 uv; +layout(location = 0) out vec4 color; void main() |
