From 1c969b9a85e2e6d6981a31bb758647fc61cf6482 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 11 Feb 2019 09:41:10 -0500 Subject: [[vk::shader_record]] (#836) * * Replaced ShaderRecordNVLayoutModifier with ShaderRecordAttribute * Allowed attributed [[vk::shader_record] and [[shader_record]] * Checking there is at most 1 ShaderRecord active * Small typo fixes * Slightly improve diagnostic. Replace expected file. --- source/slang/parameter-binding.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'source/slang/parameter-binding.cpp') diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index ba5a68341..826332b15 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -1109,13 +1109,14 @@ RefPtr getTypeLayoutForGlobalShaderParameter( auto layoutContext = context->layoutContext; auto rules = layoutContext.getRulesFamily(); - if( varDecl->HasModifier() && as(type) ) + if( varDecl->HasModifier() && as(type) ) { return CreateTypeLayout( layoutContext.with(rules->getShaderRecordConstantBufferRules()), type); } + // 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() && as(type)) @@ -2741,6 +2742,21 @@ void diagnoseGlobalUniform( getSink(sharedContext)->diagnose(varDecl, Diagnostics::globalUniformsNotSupported, varDecl->getName()); } +static int _calcTotalNumUsedRegistersForParameterCategory(ParameterBindingContext* bindingContext, SlangParameterCategory paramCategory) +{ + int numUsed = 0; + for (auto& pair : bindingContext->shared->globalSpaceUsedRangeSets) + { + UsedRangeSet* rangeSet = pair.Value; + const auto& usedRanges = rangeSet->usedResourceRanges[paramCategory]; + for (const auto& usedRange : usedRanges.ranges) + { + numUsed += int(usedRange.end - usedRange.begin); + } + } + return numUsed; +} + void generateParameterBindings( TargetRequest* targetReq) { @@ -2890,7 +2906,7 @@ void generateParameterBindings( // in the global scope we will process the parameters // of each entry point in order. // - // Note: the effect of the current implemetnation is to + // Note: the effect of the current implementation is to // allocate non-overlapping registers/bindings between all // the entry points in the compile request (e.g., if you // have a vertex and fragment shader being compiled together, @@ -2944,6 +2960,16 @@ void generateParameterBindings( cbInfo->index = globalConstantBufferBinding.index; } programLayout->parametersLayout = globalScopeVarLayout; + + { + const int numShaderRecordRegs = _calcTotalNumUsedRegistersForParameterCategory(&context, SLANG_PARAMETER_CATEGORY_SHADER_RECORD); + if (numShaderRecordRegs > 1) + { + compileReq->mSink.diagnose(SourceLoc(), Diagnostics::tooManyShaderRecordConstantBuffers, numShaderRecordRegs); + return; + } + } + } RefPtr specializeProgramLayout( -- cgit v1.2.3