diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-07-10 09:49:46 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-10 09:49:46 -0700 |
| commit | 8abdf2dddd10feb9794c86cdf6b2159a2b6383e4 (patch) | |
| tree | df7d790f33f7e4c8adc1b9b747c7c908d8bab0d4 /source/slang/parameter-binding.cpp | |
| parent | 68df74b58a56b0a1fb19b9ec4ff0282969cd6a12 (diff) | |
| parent | 5b7c254d24653fd1c19157e8d5ef68a7e787ff58 (diff) | |
Merge pull request #65 from tfoleyNV/falcor-work
Falcor work
Diffstat (limited to 'source/slang/parameter-binding.cpp')
| -rw-r--r-- | source/slang/parameter-binding.cpp | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 5811fd9fa..0683c7f8c 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -137,9 +137,6 @@ struct SharedParameterBindingContext // The program layout we are trying to construct RefPtr<ProgramLayout> programLayout; - // The source language we are trying to use - SourceLanguage sourceLanguage; - // Information on what ranges of "registers" have already // been claimed, for each resource type UsedRanges usedResourceRanges[kLayoutResourceKindCount]; @@ -160,6 +157,9 @@ struct ParameterBindingContext // What stage (if any) are we compiling for? Stage stage; + + // The source language we are trying to use + SourceLanguage sourceLanguage; }; struct LayoutSemanticInfo @@ -398,7 +398,7 @@ getTypeLayoutForGlobalShaderParameter( ParameterBindingContext* context, VarDeclBase* varDecl) { - switch( context->shared->sourceLanguage ) + switch( context->sourceLanguage ) { case SourceLanguage::Slang: case SourceLanguage::HLSL: @@ -788,6 +788,7 @@ static RefPtr<TypeLayout> processSimpleEntryPointParameter( ParameterBindingContext* context, RefPtr<ExpressionType> type, EntryPointParameterState const& inState, + RefPtr<VarLayout> varLayout, int semanticSlotCount = 1) { EntryPointParameterState state = inState; @@ -817,6 +818,13 @@ static RefPtr<TypeLayout> processSimpleEntryPointParameter( } } + // Remember the system-value semantic so that we can query it later + if (varLayout) + { + varLayout->systemValueSemantic = semanticName; + varLayout->systemValueSemanticIndex = semanticIndex; + } + // TODO: add some kind of usage information for system input/output } else @@ -847,13 +855,15 @@ static RefPtr<TypeLayout> processSimpleEntryPointParameter( static RefPtr<TypeLayout> processEntryPointParameter( ParameterBindingContext* context, RefPtr<ExpressionType> type, - EntryPointParameterState const& state); + EntryPointParameterState const& state, + RefPtr<VarLayout> varLayout); static RefPtr<TypeLayout> processEntryPointParameterWithPossibleSemantic( ParameterBindingContext* context, Decl* declForSemantic, RefPtr<ExpressionType> type, - EntryPointParameterState const& state) + EntryPointParameterState const& state, + RefPtr<VarLayout> varLayout) { // If there is no explicit semantic already in effect, *and* we find an explicit // semantic on the associated declaration, then we'll use it. @@ -868,7 +878,7 @@ static RefPtr<TypeLayout> processEntryPointParameterWithPossibleSemantic( subState.optSemanticName = &semanticInfo.name; subState.ioSemanticIndex = &semanticIndex; - processEntryPointParameter(context, type, subState); + processEntryPointParameter(context, type, subState, varLayout); } } @@ -876,29 +886,30 @@ static RefPtr<TypeLayout> processEntryPointParameterWithPossibleSemantic( // *or* we couldn't find an explicit semantic to apply on the given // declaration, so we will just recursive with whatever we have at // the moment. - return processEntryPointParameter(context, type, state); + return processEntryPointParameter(context, type, state, varLayout); } static RefPtr<TypeLayout> processEntryPointParameter( ParameterBindingContext* context, RefPtr<ExpressionType> type, - EntryPointParameterState const& state) + EntryPointParameterState const& state, + RefPtr<VarLayout> varLayout) { // Scalar and vector types are treated as outputs directly if(auto basicType = type->As<BasicExpressionType>()) { - return processSimpleEntryPointParameter(context, basicType, state); + return processSimpleEntryPointParameter(context, basicType, state, varLayout); } else if(auto vectorType = type->As<VectorExpressionType>()) { - return processSimpleEntryPointParameter(context, vectorType, state); + return processSimpleEntryPointParameter(context, vectorType, state, varLayout); } // A matrix is processed as if it was an array of rows else if( auto matrixType = type->As<MatrixExpressionType>() ) { auto rowCount = GetIntVal(matrixType->getRowCount()); - return processSimpleEntryPointParameter(context, matrixType, state, (int) rowCount); + return processSimpleEntryPointParameter(context, matrixType, state, varLayout, (int) rowCount); } else if( auto arrayType = type->As<ArrayExpressionType>() ) { @@ -908,13 +919,13 @@ static RefPtr<TypeLayout> processEntryPointParameter( auto elementCount = (UInt) GetIntVal(arrayType->ArrayLength); // We use the first element to derive the layout for the element type - auto elementTypeLayout = processEntryPointParameter(context, arrayType->BaseType, state); + auto elementTypeLayout = processEntryPointParameter(context, arrayType->BaseType, state, varLayout); // We still walk over subsequent elements to make sure they consume resources // as needed for( UInt ii = 1; ii < elementCount; ++ii ) { - processEntryPointParameter(context, arrayType->BaseType, state); + processEntryPointParameter(context, arrayType->BaseType, state, nullptr); } RefPtr<ArrayTypeLayout> arrayTypeLayout = new ArrayTypeLayout(); @@ -946,14 +957,16 @@ static RefPtr<TypeLayout> processEntryPointParameter( // Need to recursively walk the fields of the structure now... for( auto field : GetFields(structDeclRef) ) { + RefPtr<VarLayout> fieldVarLayout = new VarLayout(); + fieldVarLayout->varDecl = field; + auto fieldTypeLayout = processEntryPointParameterWithPossibleSemantic( context, field.getDecl(), GetType(field), - state); + state, + fieldVarLayout); - RefPtr<VarLayout> fieldVarLayout = new VarLayout(); - fieldVarLayout->varDecl = field; fieldVarLayout->typeLayout = fieldTypeLayout; for (auto rr : fieldTypeLayout->resourceInfos) @@ -1045,7 +1058,7 @@ static void collectEntryPointParameters( // We have an entry-point parameter, and need to figure out what to do with it. // TODO: need to handle `uniform`-qualified parameters here - if (paramDecl->HasModifier<UniformModifier>()) + if (paramDecl->HasModifier<HLSLUniformModifier>()) continue; state.directionMask = 0; @@ -1062,14 +1075,16 @@ static void collectEntryPointParameters( state.directionMask |= kEntryPointParameterDirection_Output; } + RefPtr<VarLayout> paramVarLayout = new VarLayout(); + paramVarLayout->varDecl = makeDeclRef(paramDecl.Ptr()); + auto paramTypeLayout = processEntryPointParameterWithPossibleSemantic( context, paramDecl.Ptr(), paramDecl->Type.type, - state); + state, + paramVarLayout); - RefPtr<VarLayout> paramVarLayout = new VarLayout(); - paramVarLayout->varDecl = makeDeclRef(paramDecl.Ptr()); paramVarLayout->typeLayout = paramTypeLayout; for (auto rr : paramTypeLayout->resourceInfos) @@ -1089,13 +1104,15 @@ static void collectEntryPointParameters( { state.directionMask = kEntryPointParameterDirection_Output; + RefPtr<VarLayout> resultLayout = new VarLayout(); + auto resultTypeLayout = processEntryPointParameterWithPossibleSemantic( context, entryPointFuncDecl, resultType, - state); + state, + resultLayout); - RefPtr<VarLayout> resultLayout = new VarLayout(); resultLayout->typeLayout = resultTypeLayout; for (auto rr : resultTypeLayout->resourceInfos) @@ -1167,6 +1184,7 @@ static void collectParameters( for( auto& translationUnit : request->translationUnits ) { context->stage = inferStageForTranslationUnit(translationUnit.Ptr()); + context->sourceLanguage = translationUnit->sourceLanguage; // First look at global-scope parameters collectGlobalScopeParameters(context, translationUnit->SyntaxNode.Ptr()); @@ -1189,31 +1207,13 @@ static void collectParameters( void generateParameterBindings( CompileRequest* request) { - // TODO: infer a language or set of language rules to use based on the - // source files and entry points given - auto language = SourceLanguage::Unknown; - for( auto& translationUnit : request->translationUnits ) - { - auto translationUnitLanguage = translationUnit->sourceLanguage; - if( language == SourceLanguage::Unknown ) - { - language = translationUnitLanguage; - } - else if( language == translationUnitLanguage ) - { - // same language: nothing to do... - } - else - { - // mismatch! - // TODO(tfoley): emit a diagnostic - } - } + // Try to find rules based on the selected code-generation target + auto rules = GetLayoutRulesFamilyImpl(request->Target); - // TODO(tfoley): We should really be picking layout rules - // based on the *target* language, and not the source... - auto rules = GetLayoutRulesFamilyImpl(language); - assert(rules); + // If there was no target, or there are no rules for the target, + // then bail out here. + if (!rules) + return; RefPtr<ProgramLayout> programLayout = new ProgramLayout; @@ -1222,7 +1222,6 @@ void generateParameterBindings( SharedParameterBindingContext sharedContext; sharedContext.defaultLayoutRules = rules; sharedContext.programLayout = programLayout; - sharedContext.sourceLanguage = language; // Create a sub-context to collect parameters that get // declared into the global scope |
