2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// Copyright (C) 2016 Google, Inc.
|
|
|
|
|
// Copyright (C) 2016 LunarG, Inc.
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// All rights reserved.
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
|
// modification, are permitted provided that the following conditions
|
|
|
|
|
// are met:
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Redistributions of source code must retain the above copyright
|
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
|
//
|
|
|
|
|
// Redistributions in binary form must reproduce the above
|
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
|
// with the distribution.
|
|
|
|
|
//
|
|
|
|
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
|
//
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "hlslParseHelper.h"
|
|
|
|
|
#include "hlslScanContext.h"
|
|
|
|
|
#include "hlslGrammar.h"
|
2016-10-20 19:07:10 +00:00
|
|
|
|
#include "hlslAttributes.h"
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
#include "../glslang/MachineIndependent/Scan.h"
|
|
|
|
|
#include "../glslang/MachineIndependent/preprocessor/PpContext.h"
|
|
|
|
|
|
|
|
|
|
#include "../glslang/OSDependent/osinclude.h"
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
#include <functional>
|
2016-11-01 16:31:42 +00:00
|
|
|
|
#include <cctype>
|
2016-12-28 17:03:58 +00:00
|
|
|
|
#include <array>
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
#include <set>
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
namespace glslang {
|
|
|
|
|
|
2016-11-05 16:15:53 +00:00
|
|
|
|
HlslParseContext::HlslParseContext(TSymbolTable& symbolTable, TIntermediate& interm, bool parsingBuiltins,
|
2017-07-28 22:20:13 +00:00
|
|
|
|
int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language,
|
|
|
|
|
TInfoSink& infoSink,
|
2016-10-31 21:13:43 +00:00
|
|
|
|
const TString sourceEntryPointName,
|
2016-03-13 03:11:22 +00:00
|
|
|
|
bool forwardCompatible, EShMessages messages) :
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TParseContextBase(symbolTable, interm, parsingBuiltins, version, profile, spvVersion, language, infoSink,
|
|
|
|
|
forwardCompatible, messages),
|
2017-06-07 01:19:45 +00:00
|
|
|
|
annotationNestingLevel(0),
|
2017-04-21 20:16:43 +00:00
|
|
|
|
inputPatch(nullptr),
|
2017-01-08 22:21:17 +00:00
|
|
|
|
nextInLocation(0), nextOutLocation(0),
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
sourceEntryPointName(sourceEntryPointName),
|
|
|
|
|
entryPointFunction(nullptr),
|
2017-03-30 02:01:13 +00:00
|
|
|
|
entryPointFunctionBody(nullptr),
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
gsStreamOutput(nullptr),
|
|
|
|
|
clipDistanceOutput(nullptr),
|
|
|
|
|
cullDistanceOutput(nullptr)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
globalUniformDefaults.clear();
|
2016-09-26 02:25:06 +00:00
|
|
|
|
globalUniformDefaults.layoutMatrix = ElmRowMajor;
|
2016-06-17 02:59:42 +00:00
|
|
|
|
globalUniformDefaults.layoutPacking = ElpStd140;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
globalBufferDefaults.clear();
|
2016-09-26 02:25:06 +00:00
|
|
|
|
globalBufferDefaults.layoutMatrix = ElmRowMajor;
|
2016-06-17 02:59:42 +00:00
|
|
|
|
globalBufferDefaults.layoutPacking = ElpStd430;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
globalInputDefaults.clear();
|
|
|
|
|
globalOutputDefaults.clear();
|
|
|
|
|
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
clipSemanticNSize.fill(0);
|
|
|
|
|
cullSemanticNSize.fill(0);
|
|
|
|
|
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// "Shaders in the transform
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// feedback capturing mode have an initial global default of
|
|
|
|
|
// layout(xfb_buffer = 0) out;"
|
|
|
|
|
if (language == EShLangVertex ||
|
|
|
|
|
language == EShLangTessControl ||
|
|
|
|
|
language == EShLangTessEvaluation ||
|
|
|
|
|
language == EShLangGeometry)
|
|
|
|
|
globalOutputDefaults.layoutXfbBuffer = 0;
|
|
|
|
|
|
|
|
|
|
if (language == EShLangGeometry)
|
|
|
|
|
globalOutputDefaults.layoutStream = 0;
|
2016-09-09 17:43:11 +00:00
|
|
|
|
|
|
|
|
|
if (spvVersion.spv == 0 || spvVersion.vulkan == 0)
|
|
|
|
|
infoSink.info << "ERROR: HLSL currently only supported when requesting SPIR-V for Vulkan.\n";
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HlslParseContext::~HlslParseContext()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-23 02:46:03 +00:00
|
|
|
|
void HlslParseContext::initializeExtensionBehavior()
|
|
|
|
|
{
|
|
|
|
|
TParseContextBase::initializeExtensionBehavior();
|
|
|
|
|
|
|
|
|
|
// HLSL allows #line by default.
|
|
|
|
|
extensionBehavior[E_GL_GOOGLE_cpp_style_line_directive] = EBhEnable;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
void HlslParseContext::setLimits(const TBuiltInResource& r)
|
|
|
|
|
{
|
|
|
|
|
resources = r;
|
|
|
|
|
intermediate.setLimits(resources);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Parse an array of strings using the parser in HlslRules.
|
|
|
|
|
//
|
|
|
|
|
// Returns true for successful acceptance of the shader, false if any errors.
|
|
|
|
|
//
|
|
|
|
|
bool HlslParseContext::parseShaderStrings(TPpContext& ppContext, TInputScanner& input, bool versionWillBeError)
|
|
|
|
|
{
|
|
|
|
|
currentScanner = &input;
|
|
|
|
|
ppContext.setInput(input, versionWillBeError);
|
|
|
|
|
|
|
|
|
|
HlslScanContext scanContext(*this, ppContext);
|
|
|
|
|
HlslGrammar grammar(scanContext, *this);
|
2016-09-16 04:49:31 +00:00
|
|
|
|
if (!grammar.parse()) {
|
2016-08-23 23:51:13 +00:00
|
|
|
|
// Print a message formated such that if you click on the message it will take you right to
|
|
|
|
|
// the line through most UIs.
|
2016-08-21 16:29:08 +00:00
|
|
|
|
const glslang::TSourceLoc& sourceLoc = input.getSourceLoc();
|
2017-07-28 22:20:13 +00:00
|
|
|
|
infoSink.info << sourceLoc.name << "(" << sourceLoc.line << "): error at column " << sourceLoc.column
|
|
|
|
|
<< ", HLSL parsing failed.\n";
|
2016-09-19 20:56:55 +00:00
|
|
|
|
++numErrors;
|
2016-09-16 04:49:31 +00:00
|
|
|
|
return false;
|
2016-08-21 16:29:08 +00:00
|
|
|
|
}
|
2016-09-16 04:49:31 +00:00
|
|
|
|
|
2016-11-05 16:15:53 +00:00
|
|
|
|
finish();
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return numErrors == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-10 16:00:14 +00:00
|
|
|
|
//
|
|
|
|
|
// Return true if this l-value node should be converted in some manner.
|
|
|
|
|
// For instance: turning a load aggregate into a store in an l-value.
|
|
|
|
|
//
|
2016-10-08 01:35:40 +00:00
|
|
|
|
bool HlslParseContext::shouldConvertLValue(const TIntermNode* node) const
|
|
|
|
|
{
|
2017-06-02 22:28:39 +00:00
|
|
|
|
if (node == nullptr || node->getAsTyped() == nullptr)
|
2016-10-08 01:35:40 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const TIntermAggregate* lhsAsAggregate = node->getAsAggregate();
|
2016-12-28 17:03:58 +00:00
|
|
|
|
const TIntermBinary* lhsAsBinary = node->getAsBinaryNode();
|
|
|
|
|
|
|
|
|
|
// If it's a swizzled/indexed aggregate, look at the left node instead.
|
|
|
|
|
if (lhsAsBinary != nullptr &&
|
|
|
|
|
(lhsAsBinary->getOp() == EOpVectorSwizzle || lhsAsBinary->getOp() == EOpIndexDirect))
|
|
|
|
|
lhsAsAggregate = lhsAsBinary->getLeft()->getAsAggregate();
|
2016-10-08 01:35:40 +00:00
|
|
|
|
if (lhsAsAggregate != nullptr && lhsAsAggregate->getOp() == EOpImageLoad)
|
|
|
|
|
return true;
|
|
|
|
|
|
2017-06-02 22:28:39 +00:00
|
|
|
|
// If it's a syntactic write to a sampler, we will use that to establish
|
|
|
|
|
// a compile-time alias.
|
|
|
|
|
if (node->getAsTyped()->getBasicType() == EbtSampler)
|
|
|
|
|
return true;
|
|
|
|
|
|
2016-10-08 01:35:40 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-28 22:20:13 +00:00
|
|
|
|
void HlslParseContext::growGlobalUniformBlock(const TSourceLoc& loc, TType& memberType, const TString& memberName,
|
|
|
|
|
TTypeList* newTypeList)
|
2017-02-03 21:06:36 +00:00
|
|
|
|
{
|
2017-02-07 01:44:52 +00:00
|
|
|
|
newTypeList = nullptr;
|
2017-02-06 03:27:30 +00:00
|
|
|
|
correctUniform(memberType.getQualifier());
|
2017-02-07 01:44:52 +00:00
|
|
|
|
if (memberType.isStruct()) {
|
|
|
|
|
auto it = ioTypeMap.find(memberType.getStruct());
|
|
|
|
|
if (it != ioTypeMap.end() && it->second.uniform)
|
|
|
|
|
newTypeList = it->second.uniform;
|
|
|
|
|
}
|
|
|
|
|
TParseContextBase::growGlobalUniformBlock(loc, memberType, memberName, newTypeList);
|
2017-02-03 21:06:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-10 21:24:57 +00:00
|
|
|
|
//
|
|
|
|
|
// Return a TLayoutFormat corresponding to the given texture type.
|
|
|
|
|
//
|
|
|
|
|
TLayoutFormat HlslParseContext::getLayoutFromTxType(const TSourceLoc& loc, const TType& txType)
|
|
|
|
|
{
|
|
|
|
|
const int components = txType.getVectorSize();
|
|
|
|
|
|
2016-10-28 15:57:25 +00:00
|
|
|
|
const auto selectFormat = [this,&components](TLayoutFormat v1, TLayoutFormat v2, TLayoutFormat v4) -> TLayoutFormat {
|
2016-10-15 00:36:42 +00:00
|
|
|
|
if (intermediate.getNoStorageFormat())
|
|
|
|
|
return ElfNone;
|
|
|
|
|
|
2016-10-10 21:24:57 +00:00
|
|
|
|
return components == 1 ? v1 :
|
|
|
|
|
components == 2 ? v2 : v4;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch (txType.getBasicType()) {
|
2016-10-14 22:40:32 +00:00
|
|
|
|
case EbtFloat: return selectFormat(ElfR32f, ElfRg32f, ElfRgba32f);
|
|
|
|
|
case EbtInt: return selectFormat(ElfR32i, ElfRg32i, ElfRgba32i);
|
|
|
|
|
case EbtUint: return selectFormat(ElfR32ui, ElfRg32ui, ElfRgba32ui);
|
2016-10-10 21:24:57 +00:00
|
|
|
|
default:
|
|
|
|
|
error(loc, "unknown basic type in image format", "", "");
|
|
|
|
|
return ElfNone;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 16:54:52 +00:00
|
|
|
|
//
|
|
|
|
|
// Both test and if necessary, spit out an error, to see if the node is really
|
|
|
|
|
// an l-value that can be operated on this way.
|
|
|
|
|
//
|
|
|
|
|
// Returns true if there was an error.
|
|
|
|
|
//
|
|
|
|
|
bool HlslParseContext::lValueErrorCheck(const TSourceLoc& loc, const char* op, TIntermTyped* node)
|
|
|
|
|
{
|
|
|
|
|
if (shouldConvertLValue(node)) {
|
|
|
|
|
// if we're writing to a texture, it must be an RW form.
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* lhsAsAggregate = node->getAsAggregate();
|
|
|
|
|
TIntermTyped* object = lhsAsAggregate->getSequence()[0]->getAsTyped();
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-10-08 16:54:52 +00:00
|
|
|
|
if (!object->getType().getSampler().isImage()) {
|
|
|
|
|
error(loc, "operator[] on a non-RW texture must be an r-value", "", "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Let the base class check errors
|
|
|
|
|
return TParseContextBase::lValueErrorCheck(loc, op, node);
|
|
|
|
|
}
|
2016-10-08 01:35:40 +00:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// This function handles l-value conversions and verifications. It uses, but is not synonymous
|
|
|
|
|
// with lValueErrorCheck. That function accepts an l-value directly, while this one must be
|
|
|
|
|
// given the surrounding tree - e.g, with an assignment, so we can convert the assign into a
|
|
|
|
|
// series of other image operations.
|
|
|
|
|
//
|
|
|
|
|
// Most things are passed through unmodified, except for error checking.
|
2017-01-06 07:34:48 +00:00
|
|
|
|
//
|
2017-06-02 22:28:39 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::handleLvalue(const TSourceLoc& loc, const char* op, TIntermTyped*& node)
|
2016-10-08 01:35:40 +00:00
|
|
|
|
{
|
2016-10-10 16:00:14 +00:00
|
|
|
|
if (node == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
2016-10-08 01:35:40 +00:00
|
|
|
|
TIntermBinary* nodeAsBinary = node->getAsBinaryNode();
|
|
|
|
|
TIntermUnary* nodeAsUnary = node->getAsUnaryNode();
|
|
|
|
|
TIntermAggregate* sequence = nullptr;
|
|
|
|
|
|
|
|
|
|
TIntermTyped* lhs = nodeAsUnary ? nodeAsUnary->getOperand() :
|
|
|
|
|
nodeAsBinary ? nodeAsBinary->getLeft() :
|
|
|
|
|
nullptr;
|
|
|
|
|
|
|
|
|
|
// Early bail out if there is no conversion to apply
|
|
|
|
|
if (!shouldConvertLValue(lhs)) {
|
2016-10-08 16:54:52 +00:00
|
|
|
|
if (lhs != nullptr)
|
|
|
|
|
if (lValueErrorCheck(loc, op, lhs))
|
|
|
|
|
return nullptr;
|
2016-10-08 01:35:40 +00:00
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// *** If we get here, we're going to apply some conversion to an l-value.
|
|
|
|
|
|
2017-06-02 22:28:39 +00:00
|
|
|
|
// Spin off sampler aliasing
|
|
|
|
|
if (node->getAsTyped()->getBasicType() == EbtSampler)
|
|
|
|
|
return handleSamplerLvalue(loc, op, node);
|
|
|
|
|
|
2016-10-08 01:35:40 +00:00
|
|
|
|
// Helper to create a load.
|
|
|
|
|
const auto makeLoad = [&](TIntermSymbol* rhsTmp, TIntermTyped* object, TIntermTyped* coord, const TType& derefType) {
|
|
|
|
|
TIntermAggregate* loadOp = new TIntermAggregate(EOpImageLoad);
|
|
|
|
|
loadOp->setLoc(loc);
|
|
|
|
|
loadOp->getSequence().push_back(object);
|
|
|
|
|
loadOp->getSequence().push_back(intermediate.addSymbol(*coord->getAsSymbolNode()));
|
|
|
|
|
loadOp->setType(derefType);
|
|
|
|
|
|
|
|
|
|
sequence = intermediate.growAggregate(sequence,
|
|
|
|
|
intermediate.addAssign(EOpAssign, rhsTmp, loadOp, loc),
|
|
|
|
|
loc);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Helper to create a store.
|
|
|
|
|
const auto makeStore = [&](TIntermTyped* object, TIntermTyped* coord, TIntermSymbol* rhsTmp) {
|
|
|
|
|
TIntermAggregate* storeOp = new TIntermAggregate(EOpImageStore);
|
|
|
|
|
storeOp->getSequence().push_back(object);
|
|
|
|
|
storeOp->getSequence().push_back(coord);
|
|
|
|
|
storeOp->getSequence().push_back(intermediate.addSymbol(*rhsTmp));
|
|
|
|
|
storeOp->setLoc(loc);
|
|
|
|
|
storeOp->setType(TType(EbtVoid));
|
|
|
|
|
|
|
|
|
|
sequence = intermediate.growAggregate(sequence, storeOp);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Helper to create an assign.
|
2016-10-12 18:38:12 +00:00
|
|
|
|
const auto makeBinary = [&](TOperator op, TIntermTyped* lhs, TIntermTyped* rhs) {
|
2016-10-08 01:35:40 +00:00
|
|
|
|
sequence = intermediate.growAggregate(sequence,
|
2016-10-12 18:38:12 +00:00
|
|
|
|
intermediate.addBinaryNode(op, lhs, rhs, loc, lhs->getType()),
|
2016-10-08 01:35:40 +00:00
|
|
|
|
loc);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Helper to complete sequence by adding trailing variable, so we evaluate to the right value.
|
2016-10-28 15:57:25 +00:00
|
|
|
|
const auto finishSequence = [&](TIntermSymbol* rhsTmp, const TType& derefType) -> TIntermAggregate* {
|
2016-10-08 01:35:40 +00:00
|
|
|
|
// Add a trailing use of the temp, so the sequence returns the proper value.
|
|
|
|
|
sequence = intermediate.growAggregate(sequence, intermediate.addSymbol(*rhsTmp));
|
|
|
|
|
sequence->setOperator(EOpSequence);
|
|
|
|
|
sequence->setLoc(loc);
|
|
|
|
|
sequence->setType(derefType);
|
|
|
|
|
|
|
|
|
|
return sequence;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Helper to add unary op
|
2016-10-12 18:38:12 +00:00
|
|
|
|
const auto makeUnary = [&](TOperator op, TIntermSymbol* rhsTmp) {
|
2016-10-08 01:35:40 +00:00
|
|
|
|
sequence = intermediate.growAggregate(sequence,
|
2016-10-12 18:38:12 +00:00
|
|
|
|
intermediate.addUnaryNode(op, intermediate.addSymbol(*rhsTmp), loc,
|
|
|
|
|
rhsTmp->getType()),
|
2016-10-08 01:35:40 +00:00
|
|
|
|
loc);
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-28 17:03:58 +00:00
|
|
|
|
// Return true if swizzle or index writes all components of the given variable.
|
|
|
|
|
const auto writesAllComponents = [&](TIntermSymbol* var, TIntermBinary* swizzle) -> bool {
|
|
|
|
|
if (swizzle == nullptr) // not a swizzle or index
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Track which components are being set.
|
|
|
|
|
std::array<bool, 4> compIsSet;
|
|
|
|
|
compIsSet.fill(false);
|
|
|
|
|
|
|
|
|
|
const TIntermConstantUnion* asConst = swizzle->getRight()->getAsConstantUnion();
|
|
|
|
|
const TIntermAggregate* asAggregate = swizzle->getRight()->getAsAggregate();
|
|
|
|
|
|
|
|
|
|
// This could be either a direct index, or a swizzle.
|
|
|
|
|
if (asConst) {
|
|
|
|
|
compIsSet[asConst->getConstArray()[0].getIConst()] = true;
|
|
|
|
|
} else if (asAggregate) {
|
|
|
|
|
const TIntermSequence& seq = asAggregate->getSequence();
|
|
|
|
|
for (int comp=0; comp<int(seq.size()); ++comp)
|
|
|
|
|
compIsSet[seq[comp]->getAsConstantUnion()->getConstArray()[0].getIConst()] = true;
|
|
|
|
|
} else {
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return true if all components are being set by the index or swizzle
|
|
|
|
|
return std::all_of(compIsSet.begin(), compIsSet.begin() + var->getType().getVectorSize(),
|
|
|
|
|
[](bool isSet) { return isSet; } );
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Create swizzle matching input swizzle
|
|
|
|
|
const auto addSwizzle = [&](TIntermSymbol* var, TIntermBinary* swizzle) -> TIntermTyped* {
|
|
|
|
|
if (swizzle)
|
|
|
|
|
return intermediate.addBinaryNode(swizzle->getOp(), var, swizzle->getRight(), loc, swizzle->getType());
|
|
|
|
|
else
|
|
|
|
|
return var;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TIntermBinary* lhsAsBinary = lhs->getAsBinaryNode();
|
2016-10-08 01:35:40 +00:00
|
|
|
|
TIntermAggregate* lhsAsAggregate = lhs->getAsAggregate();
|
2016-12-28 17:03:58 +00:00
|
|
|
|
bool lhsIsSwizzle = false;
|
|
|
|
|
|
|
|
|
|
// If it's a swizzled L-value, remember the swizzle, and use the LHS.
|
|
|
|
|
if (lhsAsBinary != nullptr && (lhsAsBinary->getOp() == EOpVectorSwizzle || lhsAsBinary->getOp() == EOpIndexDirect)) {
|
|
|
|
|
lhsAsAggregate = lhsAsBinary->getLeft()->getAsAggregate();
|
|
|
|
|
lhsIsSwizzle = true;
|
|
|
|
|
}
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-10-08 01:35:40 +00:00
|
|
|
|
TIntermTyped* object = lhsAsAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* coord = lhsAsAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
|
2016-10-14 22:40:32 +00:00
|
|
|
|
const TSampler& texSampler = object->getType().getSampler();
|
|
|
|
|
|
|
|
|
|
const TType objDerefType(texSampler.type, EvqTemporary, texSampler.vectorSize);
|
2016-10-08 01:35:40 +00:00
|
|
|
|
|
|
|
|
|
if (nodeAsBinary) {
|
|
|
|
|
TIntermTyped* rhs = nodeAsBinary->getRight();
|
|
|
|
|
const TOperator assignOp = nodeAsBinary->getOp();
|
|
|
|
|
|
|
|
|
|
bool isModifyOp = false;
|
|
|
|
|
|
|
|
|
|
switch (assignOp) {
|
|
|
|
|
case EOpAddAssign:
|
|
|
|
|
case EOpSubAssign:
|
|
|
|
|
case EOpMulAssign:
|
|
|
|
|
case EOpVectorTimesMatrixAssign:
|
|
|
|
|
case EOpVectorTimesScalarAssign:
|
|
|
|
|
case EOpMatrixTimesScalarAssign:
|
|
|
|
|
case EOpMatrixTimesMatrixAssign:
|
|
|
|
|
case EOpDivAssign:
|
|
|
|
|
case EOpModAssign:
|
|
|
|
|
case EOpAndAssign:
|
|
|
|
|
case EOpInclusiveOrAssign:
|
|
|
|
|
case EOpExclusiveOrAssign:
|
|
|
|
|
case EOpLeftShiftAssign:
|
|
|
|
|
case EOpRightShiftAssign:
|
|
|
|
|
isModifyOp = true;
|
|
|
|
|
// fall through...
|
|
|
|
|
case EOpAssign:
|
|
|
|
|
{
|
2017-07-28 22:20:13 +00:00
|
|
|
|
// Since this is an lvalue, we'll convert an image load to a sequence like this
|
|
|
|
|
// (to still provide the value):
|
2016-10-08 01:35:40 +00:00
|
|
|
|
// OpSequence
|
|
|
|
|
// OpImageStore(object, lhs, rhs)
|
|
|
|
|
// rhs
|
2017-07-28 22:20:13 +00:00
|
|
|
|
// But if it's not a simple symbol RHS (say, a fn call), we don't want to duplicate the RHS,
|
|
|
|
|
// so we'll convert instead to this:
|
2016-10-08 01:35:40 +00:00
|
|
|
|
// OpSequence
|
|
|
|
|
// rhsTmp = rhs
|
|
|
|
|
// OpImageStore(object, coord, rhsTmp)
|
|
|
|
|
// rhsTmp
|
|
|
|
|
// If this is a read-modify-write op, like +=, we issue:
|
|
|
|
|
// OpSequence
|
|
|
|
|
// coordtmp = load's param1
|
|
|
|
|
// rhsTmp = OpImageLoad(object, coordTmp)
|
2017-01-05 17:45:32 +00:00
|
|
|
|
// rhsTmp op= rhs
|
2016-10-08 01:35:40 +00:00
|
|
|
|
// OpImageStore(object, coordTmp, rhsTmp)
|
|
|
|
|
// rhsTmp
|
2016-12-28 17:03:58 +00:00
|
|
|
|
//
|
|
|
|
|
// If the lvalue is swizzled, we apply that when writing the temp variable, like so:
|
|
|
|
|
// ...
|
|
|
|
|
// rhsTmp.some_swizzle = ...
|
|
|
|
|
// For partial writes, an error is generated.
|
2016-10-08 01:35:40 +00:00
|
|
|
|
|
|
|
|
|
TIntermSymbol* rhsTmp = rhs->getAsSymbolNode();
|
|
|
|
|
TIntermTyped* coordTmp = coord;
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-12-28 17:03:58 +00:00
|
|
|
|
if (rhsTmp == nullptr || isModifyOp || lhsIsSwizzle) {
|
2017-04-04 17:47:42 +00:00
|
|
|
|
rhsTmp = makeInternalVariableNode(loc, "storeTemp", objDerefType);
|
2016-10-08 01:35:40 +00:00
|
|
|
|
|
2016-12-28 17:03:58 +00:00
|
|
|
|
// Partial updates not yet supported
|
|
|
|
|
if (!writesAllComponents(rhsTmp, lhsAsBinary)) {
|
|
|
|
|
error(loc, "unimplemented: partial image updates", "", "");
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 01:35:40 +00:00
|
|
|
|
// Assign storeTemp = rhs
|
|
|
|
|
if (isModifyOp) {
|
|
|
|
|
// We have to make a temp var for the coordinate, to avoid evaluating it twice.
|
2017-04-04 17:47:42 +00:00
|
|
|
|
coordTmp = makeInternalVariableNode(loc, "coordTemp", coord->getType());
|
2016-10-12 18:38:12 +00:00
|
|
|
|
makeBinary(EOpAssign, coordTmp, coord); // coordtmp = load[param1]
|
2016-10-08 01:35:40 +00:00
|
|
|
|
makeLoad(rhsTmp, object, coordTmp, objDerefType); // rhsTmp = OpImageLoad(object, coordTmp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// rhsTmp op= rhs.
|
2016-12-28 17:03:58 +00:00
|
|
|
|
makeBinary(assignOp, addSwizzle(intermediate.addSymbol(*rhsTmp), lhsAsBinary), rhs);
|
2016-10-08 01:35:40 +00:00
|
|
|
|
}
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-10-08 01:35:40 +00:00
|
|
|
|
makeStore(object, coordTmp, rhsTmp); // add a store
|
|
|
|
|
return finishSequence(rhsTmp, objDerefType); // return rhsTmp from sequence
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nodeAsUnary) {
|
|
|
|
|
const TOperator assignOp = nodeAsUnary->getOp();
|
|
|
|
|
|
|
|
|
|
switch (assignOp) {
|
|
|
|
|
case EOpPreIncrement:
|
|
|
|
|
case EOpPreDecrement:
|
|
|
|
|
{
|
|
|
|
|
// We turn this into:
|
|
|
|
|
// OpSequence
|
|
|
|
|
// coordtmp = load's param1
|
|
|
|
|
// rhsTmp = OpImageLoad(object, coordTmp)
|
|
|
|
|
// rhsTmp op
|
|
|
|
|
// OpImageStore(object, coordTmp, rhsTmp)
|
|
|
|
|
// rhsTmp
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2017-04-04 17:47:42 +00:00
|
|
|
|
TIntermSymbol* rhsTmp = makeInternalVariableNode(loc, "storeTemp", objDerefType);
|
|
|
|
|
TIntermTyped* coordTmp = makeInternalVariableNode(loc, "coordTemp", coord->getType());
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-10-12 18:38:12 +00:00
|
|
|
|
makeBinary(EOpAssign, coordTmp, coord); // coordtmp = load[param1]
|
2016-10-08 01:35:40 +00:00
|
|
|
|
makeLoad(rhsTmp, object, coordTmp, objDerefType); // rhsTmp = OpImageLoad(object, coordTmp)
|
2016-10-12 18:38:12 +00:00
|
|
|
|
makeUnary(assignOp, rhsTmp); // op rhsTmp
|
2016-10-08 01:35:40 +00:00
|
|
|
|
makeStore(object, coordTmp, rhsTmp); // OpImageStore(object, coordTmp, rhsTmp)
|
|
|
|
|
return finishSequence(rhsTmp, objDerefType); // return rhsTmp from sequence
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpPostIncrement:
|
|
|
|
|
case EOpPostDecrement:
|
|
|
|
|
{
|
|
|
|
|
// We turn this into:
|
|
|
|
|
// OpSequence
|
|
|
|
|
// coordtmp = load's param1
|
|
|
|
|
// rhsTmp1 = OpImageLoad(object, coordTmp)
|
|
|
|
|
// rhsTmp2 = rhsTmp1
|
|
|
|
|
// rhsTmp2 op
|
|
|
|
|
// OpImageStore(object, coordTmp, rhsTmp2)
|
|
|
|
|
// rhsTmp1 (pre-op value)
|
2017-04-04 17:47:42 +00:00
|
|
|
|
TIntermSymbol* rhsTmp1 = makeInternalVariableNode(loc, "storeTempPre", objDerefType);
|
|
|
|
|
TIntermSymbol* rhsTmp2 = makeInternalVariableNode(loc, "storeTempPost", objDerefType);
|
|
|
|
|
TIntermTyped* coordTmp = makeInternalVariableNode(loc, "coordTemp", coord->getType());
|
2016-10-08 01:35:40 +00:00
|
|
|
|
|
2016-10-12 18:38:12 +00:00
|
|
|
|
makeBinary(EOpAssign, coordTmp, coord); // coordtmp = load[param1]
|
2016-10-08 01:35:40 +00:00
|
|
|
|
makeLoad(rhsTmp1, object, coordTmp, objDerefType); // rhsTmp1 = OpImageLoad(object, coordTmp)
|
2016-10-12 18:38:12 +00:00
|
|
|
|
makeBinary(EOpAssign, rhsTmp2, rhsTmp1); // rhsTmp2 = rhsTmp1
|
|
|
|
|
makeUnary(assignOp, rhsTmp2); // rhsTmp op
|
2016-10-08 01:35:40 +00:00
|
|
|
|
makeStore(object, coordTmp, rhsTmp2); // OpImageStore(object, coordTmp, rhsTmp2)
|
|
|
|
|
return finishSequence(rhsTmp1, objDerefType); // return rhsTmp from sequence
|
|
|
|
|
}
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-10-08 01:35:40 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 16:54:52 +00:00
|
|
|
|
if (lhs)
|
|
|
|
|
if (lValueErrorCheck(loc, op, lhs))
|
|
|
|
|
return nullptr;
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-10-08 01:35:40 +00:00
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-02 22:28:39 +00:00
|
|
|
|
// Deal with sampler aliasing: turning assignments into aliases
|
2017-07-16 11:46:13 +00:00
|
|
|
|
// Return a placeholder node for higher-level code that think assignments must
|
|
|
|
|
// generate code.
|
2017-06-02 22:28:39 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::handleSamplerLvalue(const TSourceLoc& loc, const char* op, TIntermTyped*& node)
|
|
|
|
|
{
|
|
|
|
|
// Can only alias an assignment: "s1 = s2"
|
|
|
|
|
TIntermBinary* binary = node->getAsBinaryNode();
|
|
|
|
|
if (binary == nullptr || node->getAsOperator()->getOp() != EOpAssign ||
|
2017-07-16 11:46:13 +00:00
|
|
|
|
binary->getLeft()->getAsSymbolNode() == nullptr ||
|
2017-06-02 22:28:39 +00:00
|
|
|
|
binary->getRight()->getAsSymbolNode() == nullptr) {
|
|
|
|
|
error(loc, "can't modify sampler", op, "");
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 01:19:45 +00:00
|
|
|
|
if (controlFlowNestingLevel > 0)
|
2017-06-07 01:52:55 +00:00
|
|
|
|
warn(loc, "sampler or image aliased under control flow; consumption must be in same path", op, "");
|
2017-06-07 01:19:45 +00:00
|
|
|
|
|
2017-07-16 11:46:13 +00:00
|
|
|
|
TIntermTyped* set = setOpaqueLvalue(binary->getLeft(), binary->getRight());
|
|
|
|
|
if (set == nullptr)
|
|
|
|
|
warn(loc, "could not create alias for sampler", op, "");
|
|
|
|
|
else
|
|
|
|
|
node = set;
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Do an opaque assignment that needs to turn into an alias.
|
|
|
|
|
// Return nullptr if it can't be done, otherwise return a placeholder
|
|
|
|
|
// node for higher-level code that think assignments must generate code.
|
|
|
|
|
TIntermTyped* HlslParseContext::setOpaqueLvalue(TIntermTyped* leftTyped, TIntermTyped* rightTyped)
|
|
|
|
|
{
|
2017-06-02 22:28:39 +00:00
|
|
|
|
// Best is if we are aliasing a flattened struct member "S.s1 = s2",
|
|
|
|
|
// in which case we want to update the flattening information with the alias,
|
|
|
|
|
// making everything else work seamlessly.
|
2017-07-16 11:46:13 +00:00
|
|
|
|
TIntermSymbol* left = leftTyped->getAsSymbolNode();
|
|
|
|
|
TIntermSymbol* right = rightTyped->getAsSymbolNode();
|
2017-06-02 22:28:39 +00:00
|
|
|
|
for (auto fit = flattenMap.begin(); fit != flattenMap.end(); ++fit) {
|
|
|
|
|
for (auto mit = fit->second.members.begin(); mit != fit->second.members.end(); ++mit) {
|
|
|
|
|
if ((*mit)->getUniqueId() == left->getId()) {
|
|
|
|
|
// found it: update with alias to the existing variable, and don't emit any code
|
|
|
|
|
(*mit) = new TVariable(&right->getName(), right->getType());
|
|
|
|
|
(*mit)->setUniqueId(right->getId());
|
|
|
|
|
// replace node (rest of compiler expects either an error or code to generate)
|
|
|
|
|
// with pointless access
|
2017-07-16 11:46:13 +00:00
|
|
|
|
return right;
|
2017-06-02 22:28:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-16 11:46:13 +00:00
|
|
|
|
return nullptr;
|
2017-06-02 22:28:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
void HlslParseContext::handlePragma(const TSourceLoc& loc, const TVector<TString>& tokens)
|
|
|
|
|
{
|
|
|
|
|
if (pragmaCallback)
|
|
|
|
|
pragmaCallback(loc.line, tokens);
|
|
|
|
|
|
|
|
|
|
if (tokens.size() == 0)
|
|
|
|
|
return;
|
2017-08-07 18:08:50 +00:00
|
|
|
|
|
|
|
|
|
// These pragmas are case insensitive in HLSL, so we'll compare in lower case.
|
|
|
|
|
TVector<TString> lowerTokens = tokens;
|
|
|
|
|
|
|
|
|
|
for (auto it = lowerTokens.begin(); it != lowerTokens.end(); ++it)
|
|
|
|
|
std::transform(it->begin(), it->end(), it->begin(), ::tolower);
|
|
|
|
|
|
|
|
|
|
// Handle pack_matrix
|
|
|
|
|
if (tokens.size() == 4 && lowerTokens[0] == "pack_matrix" && tokens[1] == "(" && tokens[3] == ")") {
|
|
|
|
|
// Note that HLSL semantic order is Mrc, not Mcr like SPIR-V, so we reverse the sense.
|
|
|
|
|
// Row major becomes column major and vice versa.
|
|
|
|
|
|
|
|
|
|
if (lowerTokens[2] == "row_major") {
|
|
|
|
|
globalUniformDefaults.layoutMatrix = globalBufferDefaults.layoutMatrix = ElmColumnMajor;
|
|
|
|
|
} else if (lowerTokens[2] == "column_major") {
|
|
|
|
|
globalUniformDefaults.layoutMatrix = globalBufferDefaults.layoutMatrix = ElmRowMajor;
|
|
|
|
|
} else {
|
|
|
|
|
// unknown majorness strings are treated as (HLSL column major)==(SPIR-V row major)
|
|
|
|
|
warn(loc, "unknown pack_matrix pragma value", tokens[2].c_str(), "");
|
|
|
|
|
globalUniformDefaults.layoutMatrix = globalBufferDefaults.layoutMatrix = ElmRowMajor;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2017-01-14 02:34:22 +00:00
|
|
|
|
// Look at a '.' matrix selector string and change it into components
|
2017-01-12 23:51:18 +00:00
|
|
|
|
// for a matrix. There are two types:
|
|
|
|
|
//
|
|
|
|
|
// _21 second row, first column (one based)
|
|
|
|
|
// _m21 third row, second column (zero based)
|
|
|
|
|
//
|
|
|
|
|
// Returns true if there is no error.
|
|
|
|
|
//
|
2017-01-14 02:34:22 +00:00
|
|
|
|
bool HlslParseContext::parseMatrixSwizzleSelector(const TSourceLoc& loc, const TString& fields, int cols, int rows,
|
|
|
|
|
TSwizzleSelectors<TMatrixSelector>& components)
|
2017-01-12 23:51:18 +00:00
|
|
|
|
{
|
2017-01-14 03:22:00 +00:00
|
|
|
|
int startPos[MaxSwizzleSelectors];
|
2017-01-12 23:51:18 +00:00
|
|
|
|
int numComps = 0;
|
|
|
|
|
TString compString = fields;
|
|
|
|
|
|
|
|
|
|
// Find where each component starts,
|
|
|
|
|
// recording the first character position after the '_'.
|
|
|
|
|
for (size_t c = 0; c < compString.size(); ++c) {
|
|
|
|
|
if (compString[c] == '_') {
|
2017-01-14 03:22:00 +00:00
|
|
|
|
if (numComps >= MaxSwizzleSelectors) {
|
2017-01-12 23:51:18 +00:00
|
|
|
|
error(loc, "matrix component swizzle has too many components", compString.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-01-12 23:51:18 +00:00
|
|
|
|
if (c > compString.size() - 3 ||
|
|
|
|
|
((compString[c+1] == 'm' || compString[c+1] == 'M') && c > compString.size() - 4)) {
|
|
|
|
|
error(loc, "matrix component swizzle missing", compString.c_str(), "");
|
|
|
|
|
return false;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
2017-02-17 18:05:14 +00:00
|
|
|
|
startPos[numComps++] = (int)c + 1;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
2017-01-12 23:51:18 +00:00
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
2017-01-12 23:51:18 +00:00
|
|
|
|
// Process each component
|
|
|
|
|
for (int i = 0; i < numComps; ++i) {
|
|
|
|
|
int pos = startPos[i];
|
|
|
|
|
int bias = -1;
|
|
|
|
|
if (compString[pos] == 'm' || compString[pos] == 'M') {
|
|
|
|
|
bias = 0;
|
|
|
|
|
++pos;
|
|
|
|
|
}
|
2017-01-14 02:34:22 +00:00
|
|
|
|
TMatrixSelector comp;
|
2017-01-12 23:51:18 +00:00
|
|
|
|
comp.coord1 = compString[pos+0] - '0' + bias;
|
|
|
|
|
comp.coord2 = compString[pos+1] - '0' + bias;
|
|
|
|
|
if (comp.coord1 < 0 || comp.coord1 >= cols) {
|
|
|
|
|
error(loc, "matrix row component out of range", compString.c_str(), "");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (comp.coord2 < 0 || comp.coord2 >= rows) {
|
|
|
|
|
error(loc, "matrix column component out of range", compString.c_str(), "");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
components.push_back(comp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the 'comps' express a column of a matrix,
|
|
|
|
|
// return the column. Column means the first coords all match.
|
|
|
|
|
//
|
|
|
|
|
// Otherwise, return -1.
|
|
|
|
|
//
|
2017-01-14 02:34:22 +00:00
|
|
|
|
int HlslParseContext::getMatrixComponentsColumn(int rows, const TSwizzleSelectors<TMatrixSelector>& selector)
|
2017-01-12 23:51:18 +00:00
|
|
|
|
{
|
|
|
|
|
int col = -1;
|
|
|
|
|
|
|
|
|
|
// right number of comps?
|
2017-01-14 02:34:22 +00:00
|
|
|
|
if (selector.size() != rows)
|
2017-01-12 23:51:18 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
// all comps in the same column?
|
|
|
|
|
// rows in order?
|
2017-01-14 02:34:22 +00:00
|
|
|
|
col = selector[0].coord1;
|
2017-01-12 23:51:18 +00:00
|
|
|
|
for (int i = 0; i < rows; ++i) {
|
2017-01-14 02:34:22 +00:00
|
|
|
|
if (col != selector[i].coord1)
|
2017-01-12 23:51:18 +00:00
|
|
|
|
return -1;
|
2017-01-14 02:34:22 +00:00
|
|
|
|
if (i != selector[i].coord2)
|
2017-01-12 23:51:18 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return col;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Handle seeing a variable identifier in the grammar.
|
|
|
|
|
//
|
2017-03-22 00:35:04 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::handleVariable(const TSourceLoc& loc, const TString* string)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
2017-03-22 05:56:40 +00:00
|
|
|
|
int thisDepth;
|
|
|
|
|
TSymbol* symbol = symbolTable.find(*string, thisDepth);
|
2016-06-11 22:43:14 +00:00
|
|
|
|
if (symbol && symbol->getAsVariable() && symbol->getAsVariable()->isUserType()) {
|
|
|
|
|
error(loc, "expected symbol, not user-defined type", string->c_str(), "");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
// Error check for requiring specific extensions present.
|
|
|
|
|
if (symbol && symbol->getNumExtensions())
|
|
|
|
|
requireExtensions(loc, symbol->getNumExtensions(), symbol->getExtensions(), symbol->getName().c_str());
|
|
|
|
|
|
2017-03-22 05:56:40 +00:00
|
|
|
|
const TVariable* variable = nullptr;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
const TAnonMember* anon = symbol ? symbol->getAsAnonMember() : nullptr;
|
2016-06-11 22:43:14 +00:00
|
|
|
|
TIntermTyped* node = nullptr;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (anon) {
|
2017-03-22 05:56:40 +00:00
|
|
|
|
// It was a member of an anonymous container, which could be a 'this' structure.
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
// Create a subtree for its dereference.
|
2017-03-22 05:56:40 +00:00
|
|
|
|
if (thisDepth > 0) {
|
|
|
|
|
variable = getImplicitThis(thisDepth);
|
|
|
|
|
if (variable == nullptr)
|
|
|
|
|
error(loc, "cannot access member variables (static member function?)", "this", "");
|
|
|
|
|
}
|
|
|
|
|
if (variable == nullptr)
|
|
|
|
|
variable = anon->getAnonContainer().getAsVariable();
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
TIntermTyped* container = intermediate.addSymbol(*variable, loc);
|
|
|
|
|
TIntermTyped* constNode = intermediate.addConstantUnion(anon->getMemberNumber(), loc);
|
|
|
|
|
node = intermediate.addIndex(EOpIndexDirectStruct, container, constNode, loc);
|
|
|
|
|
|
|
|
|
|
node->setType(*(*variable->getType().getStruct())[anon->getMemberNumber()].type);
|
|
|
|
|
if (node->getType().hiddenMember())
|
|
|
|
|
error(loc, "member of nameless block was not redeclared", string->c_str(), "");
|
|
|
|
|
} else {
|
|
|
|
|
// Not a member of an anonymous container.
|
|
|
|
|
|
|
|
|
|
// The symbol table search was done in the lexical phase.
|
|
|
|
|
// See if it was a variable.
|
|
|
|
|
variable = symbol ? symbol->getAsVariable() : nullptr;
|
|
|
|
|
if (variable) {
|
|
|
|
|
if ((variable->getType().getBasicType() == EbtBlock ||
|
|
|
|
|
variable->getType().getBasicType() == EbtStruct) && variable->getType().getStruct() == nullptr) {
|
|
|
|
|
error(loc, "cannot be used (maybe an instance name is needed)", string->c_str(), "");
|
|
|
|
|
variable = nullptr;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (symbol)
|
|
|
|
|
error(loc, "variable name expected", string->c_str(), "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Recovery, if it wasn't found or was not a variable.
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (variable == nullptr) {
|
2016-12-15 00:02:32 +00:00
|
|
|
|
error(loc, "unknown variable", string->c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
variable = new TVariable(string, TType(EbtVoid));
|
2016-12-15 00:02:32 +00:00
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
if (variable->getType().getQualifier().isFrontEndConstant())
|
|
|
|
|
node = intermediate.addConstantUnion(variable->getConstArray(), variable->getType(), loc);
|
|
|
|
|
else
|
|
|
|
|
node = intermediate.addSymbol(*variable, loc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (variable->getType().getQualifier().isIo())
|
|
|
|
|
intermediate.addIoAccessed(*string);
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-07 02:12:24 +00:00
|
|
|
|
//
|
|
|
|
|
// Handle operator[] on any objects it applies to. Currently:
|
|
|
|
|
// Textures
|
|
|
|
|
// Buffers
|
|
|
|
|
//
|
|
|
|
|
TIntermTyped* HlslParseContext::handleBracketOperator(const TSourceLoc& loc, TIntermTyped* base, TIntermTyped* index)
|
|
|
|
|
{
|
|
|
|
|
// handle r-value operator[] on textures and images. l-values will be processed later.
|
|
|
|
|
if (base->getType().getBasicType() == EbtSampler && !base->isArray()) {
|
|
|
|
|
const TSampler& sampler = base->getType().getSampler();
|
|
|
|
|
if (sampler.isImage() || sampler.isTexture()) {
|
2017-05-12 23:14:31 +00:00
|
|
|
|
if (! mipsOperatorMipArg.empty() && mipsOperatorMipArg.back().mipLevel == nullptr) {
|
|
|
|
|
// The first operator[] to a .mips[] sequence is the mip level. We'll remember it.
|
|
|
|
|
mipsOperatorMipArg.back().mipLevel = index;
|
|
|
|
|
return base; // next [] index is to the same base.
|
|
|
|
|
} else {
|
|
|
|
|
TIntermAggregate* load = new TIntermAggregate(sampler.isImage() ? EOpImageLoad : EOpTextureFetch);
|
|
|
|
|
|
|
|
|
|
load->setType(TType(sampler.type, EvqTemporary, sampler.vectorSize));
|
|
|
|
|
load->setLoc(loc);
|
|
|
|
|
load->getSequence().push_back(base);
|
|
|
|
|
load->getSequence().push_back(index);
|
|
|
|
|
|
|
|
|
|
// Textures need a MIP. If we saw one go by, use it. Otherwise, use zero.
|
|
|
|
|
if (sampler.isTexture()) {
|
|
|
|
|
if (! mipsOperatorMipArg.empty()) {
|
|
|
|
|
load->getSequence().push_back(mipsOperatorMipArg.back().mipLevel);
|
|
|
|
|
mipsOperatorMipArg.pop_back();
|
|
|
|
|
} else {
|
|
|
|
|
load->getSequence().push_back(intermediate.addConstantUnion(0, loc, true));
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-10 16:00:14 +00:00
|
|
|
|
|
2017-05-12 23:14:31 +00:00
|
|
|
|
return load;
|
|
|
|
|
}
|
2016-10-07 02:12:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-24 01:04:12 +00:00
|
|
|
|
// Handle operator[] on structured buffers: this indexes into the array element of the buffer.
|
|
|
|
|
// indexStructBufferContent returns nullptr if it isn't a structuredbuffer (SSBO).
|
|
|
|
|
TIntermTyped* sbArray = indexStructBufferContent(loc, base);
|
|
|
|
|
if (sbArray != nullptr) {
|
|
|
|
|
if (sbArray == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
// Now we'll apply the [] index to that array
|
|
|
|
|
const TOperator idxOp = (index->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
|
|
|
|
|
|
|
|
|
|
TIntermTyped* element = intermediate.addIndex(idxOp, sbArray, index, loc);
|
|
|
|
|
const TType derefType(sbArray->getType(), 0);
|
|
|
|
|
element->setType(derefType);
|
|
|
|
|
return element;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-07 02:12:24 +00:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
2017-04-20 15:00:56 +00:00
|
|
|
|
// Cast index value to a uint if it isn't already (for operator[], load indexes, etc)
|
|
|
|
|
TIntermTyped* HlslParseContext::makeIntegerIndex(TIntermTyped* index)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
2017-04-07 02:22:20 +00:00
|
|
|
|
const TBasicType indexBasicType = index->getType().getBasicType();
|
2017-04-20 15:00:56 +00:00
|
|
|
|
const int vecSize = index->getType().getVectorSize();
|
|
|
|
|
|
|
|
|
|
// We can use int types directly as the index
|
|
|
|
|
if (indexBasicType == EbtInt || indexBasicType == EbtUint ||
|
|
|
|
|
indexBasicType == EbtInt64 || indexBasicType == EbtUint64)
|
|
|
|
|
return index;
|
2017-04-07 02:22:20 +00:00
|
|
|
|
|
|
|
|
|
// Cast index to unsigned integer if it isn't one.
|
2017-04-20 15:00:56 +00:00
|
|
|
|
return intermediate.addConversion(EOpConstructUint, TType(EbtUint, EvqTemporary, vecSize), index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Handle seeing a base[index] dereference in the grammar.
|
|
|
|
|
//
|
|
|
|
|
TIntermTyped* HlslParseContext::handleBracketDereference(const TSourceLoc& loc, TIntermTyped* base, TIntermTyped* index)
|
|
|
|
|
{
|
|
|
|
|
index = makeIntegerIndex(index);
|
2017-04-07 02:22:20 +00:00
|
|
|
|
|
|
|
|
|
if (index == nullptr) {
|
2017-06-20 19:19:53 +00:00
|
|
|
|
error(loc, " unknown index type ", "", "");
|
2017-04-07 02:22:20 +00:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-20 15:00:56 +00:00
|
|
|
|
TIntermTyped* result = handleBracketOperator(loc, base, index);
|
|
|
|
|
|
|
|
|
|
if (result != nullptr)
|
|
|
|
|
return result; // it was handled as an operator[]
|
|
|
|
|
|
2016-09-22 20:35:23 +00:00
|
|
|
|
bool flattened = false;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
int indexValue = 0;
|
|
|
|
|
if (index->getQualifier().storage == EvqConst) {
|
|
|
|
|
indexValue = index->getAsConstantUnion()->getConstArray()[0].getIConst();
|
|
|
|
|
checkIndex(loc, base->getType(), indexValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variableCheck(base);
|
|
|
|
|
if (! base->isArray() && ! base->isMatrix() && ! base->isVector()) {
|
|
|
|
|
if (base->getAsSymbolNode())
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, " left of '[' is not of type array, matrix, or vector ",
|
|
|
|
|
base->getAsSymbolNode()->getName().c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
else
|
|
|
|
|
error(loc, " left of '[' is not of type array, matrix, or vector ", "expression", "");
|
|
|
|
|
} else if (base->getType().getQualifier().storage == EvqConst && index->getQualifier().storage == EvqConst)
|
|
|
|
|
return intermediate.foldDereference(base, indexValue, loc);
|
|
|
|
|
else {
|
|
|
|
|
// at least one of base and index is variable...
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
if (base->getAsSymbolNode() && wasFlattened(base)) {
|
2016-09-16 19:26:37 +00:00
|
|
|
|
if (index->getQualifier().storage != EvqConst)
|
2016-12-19 22:48:01 +00:00
|
|
|
|
error(loc, "Invalid variable index to flattened array", base->getAsSymbolNode()->getName().c_str(), "");
|
2016-09-16 19:26:37 +00:00
|
|
|
|
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
result = flattenAccess(base, indexValue);
|
2016-09-22 20:35:23 +00:00
|
|
|
|
flattened = (result != base);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
} else {
|
2016-09-16 19:26:37 +00:00
|
|
|
|
if (index->getQualifier().storage == EvqConst) {
|
|
|
|
|
if (base->getType().isImplicitlySizedArray())
|
|
|
|
|
updateImplicitArraySize(loc, base, indexValue);
|
|
|
|
|
result = intermediate.addIndex(EOpIndexDirect, base, index, loc);
|
|
|
|
|
} else {
|
|
|
|
|
result = intermediate.addIndex(EOpIndexIndirect, base, index, loc);
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result == nullptr) {
|
|
|
|
|
// Insert dummy error-recovery result
|
|
|
|
|
result = intermediate.addConstantUnion(0.0, EbtFloat, loc);
|
|
|
|
|
} else {
|
2016-09-22 20:35:23 +00:00
|
|
|
|
// If the array reference was flattened, it has the correct type. E.g, if it was
|
|
|
|
|
// a uniform array, it was flattened INTO a set of scalar uniforms, not scalar temps.
|
|
|
|
|
// In that case, we preserve the qualifiers.
|
|
|
|
|
if (!flattened) {
|
|
|
|
|
// Insert valid dereferenced result
|
|
|
|
|
TType newType(base->getType(), 0); // dereferenced type
|
|
|
|
|
if (base->getType().getQualifier().storage == EvqConst && index->getQualifier().storage == EvqConst)
|
|
|
|
|
newType.getQualifier().storage = EvqConst;
|
|
|
|
|
else
|
|
|
|
|
newType.getQualifier().storage = EvqTemporary;
|
|
|
|
|
result->setType(newType);
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-09 04:09:10 +00:00
|
|
|
|
void HlslParseContext::checkIndex(const TSourceLoc& /*loc*/, const TType& /*type*/, int& /*index*/)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
// HLSL todo: any rules for index fixups?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle seeing a binary node with a math operation.
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::handleBinaryMath(const TSourceLoc& loc, const char* str, TOperator op,
|
|
|
|
|
TIntermTyped* left, TIntermTyped* right)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
TIntermTyped* result = intermediate.addBinaryMath(op, left, right, loc);
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (result == nullptr)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
binaryOpError(loc, str, left->getCompleteString(), right->getCompleteString());
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle seeing a unary node with a math operation.
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::handleUnaryMath(const TSourceLoc& loc, const char* str, TOperator op,
|
|
|
|
|
TIntermTyped* childNode)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
TIntermTyped* result = intermediate.addUnaryMath(op, childNode, loc);
|
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
return result;
|
|
|
|
|
else
|
|
|
|
|
unaryOpError(loc, str, childNode->getCompleteString());
|
|
|
|
|
|
|
|
|
|
return childNode;
|
|
|
|
|
}
|
2017-02-13 00:50:28 +00:00
|
|
|
|
//
|
|
|
|
|
// Return true if the name is a struct buffer method
|
|
|
|
|
//
|
|
|
|
|
bool HlslParseContext::isStructBufferMethod(const TString& name) const
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
name == "GetDimensions" ||
|
|
|
|
|
name == "Load" ||
|
|
|
|
|
name == "Load2" ||
|
|
|
|
|
name == "Load3" ||
|
|
|
|
|
name == "Load4" ||
|
|
|
|
|
name == "Store" ||
|
|
|
|
|
name == "Store2" ||
|
|
|
|
|
name == "Store3" ||
|
|
|
|
|
name == "Store4" ||
|
|
|
|
|
name == "InterlockedAdd" ||
|
|
|
|
|
name == "InterlockedAnd" ||
|
|
|
|
|
name == "InterlockedCompareExchange" ||
|
|
|
|
|
name == "InterlockedCompareStore" ||
|
|
|
|
|
name == "InterlockedExchange" ||
|
|
|
|
|
name == "InterlockedMax" ||
|
|
|
|
|
name == "InterlockedMin" ||
|
|
|
|
|
name == "InterlockedOr" ||
|
2017-04-10 14:19:21 +00:00
|
|
|
|
name == "InterlockedXor" ||
|
|
|
|
|
name == "IncrementCounter" ||
|
|
|
|
|
name == "DecrementCounter" ||
|
|
|
|
|
name == "Append" ||
|
|
|
|
|
name == "Consume";
|
2017-02-13 00:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
2017-03-09 03:09:03 +00:00
|
|
|
|
// Handle seeing a base.field dereference in the grammar, where 'field' is a
|
|
|
|
|
// swizzle or member variable.
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
TIntermTyped* HlslParseContext::handleDotDereference(const TSourceLoc& loc, TIntermTyped* base, const TString& field)
|
|
|
|
|
{
|
|
|
|
|
variableCheck(base);
|
|
|
|
|
|
|
|
|
|
if (base->isArray()) {
|
|
|
|
|
error(loc, "cannot apply to an array:", ".", field.c_str());
|
|
|
|
|
return base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermTyped* result = base;
|
2017-05-12 23:14:31 +00:00
|
|
|
|
|
|
|
|
|
if (base->getType().getBasicType() == EbtSampler) {
|
|
|
|
|
// Handle .mips[mipid][pos] operation on textures
|
|
|
|
|
const TSampler& sampler = base->getType().getSampler();
|
|
|
|
|
if (sampler.isTexture() && field == "mips") {
|
|
|
|
|
// Push a null to signify that we expect a mip level under operator[] next.
|
|
|
|
|
mipsOperatorMipArg.push_back(tMipsOperatorData(loc, nullptr));
|
|
|
|
|
// Keep 'result' pointing to 'base', since we expect an operator[] to go by next.
|
|
|
|
|
} else {
|
|
|
|
|
if (field == "mips")
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "unexpected texture type for .mips[][] operator:",
|
|
|
|
|
base->getType().getCompleteString().c_str(), "");
|
2017-05-12 23:14:31 +00:00
|
|
|
|
else
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "unexpected operator on texture type:", field.c_str(),
|
|
|
|
|
base->getType().getCompleteString().c_str());
|
2017-05-12 23:14:31 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (base->isVector() || base->isScalar()) {
|
2017-01-14 02:34:22 +00:00
|
|
|
|
TSwizzleSelectors<TVectorSelector> selectors;
|
|
|
|
|
parseSwizzleSelector(loc, field, base->getVectorSize(), selectors);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
if (base->isScalar()) {
|
2017-01-14 02:34:22 +00:00
|
|
|
|
if (selectors.size() == 1)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return result;
|
|
|
|
|
else {
|
2017-01-14 02:34:22 +00:00
|
|
|
|
TType type(base->getBasicType(), EvqTemporary, selectors.size());
|
2016-07-28 21:29:35 +00:00
|
|
|
|
return addConstructor(loc, base, type);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-03 04:21:25 +00:00
|
|
|
|
if (base->getVectorSize() == 1) {
|
|
|
|
|
TType scalarType(base->getBasicType(), EvqTemporary, 1);
|
2017-01-14 02:34:22 +00:00
|
|
|
|
if (selectors.size() == 1)
|
2016-09-03 04:21:25 +00:00
|
|
|
|
return addConstructor(loc, base, scalarType);
|
|
|
|
|
else {
|
2017-01-14 02:34:22 +00:00
|
|
|
|
TType vectorType(base->getBasicType(), EvqTemporary, selectors.size());
|
2016-09-03 04:21:25 +00:00
|
|
|
|
return addConstructor(loc, addConstructor(loc, base, scalarType), vectorType);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
if (base->getType().getQualifier().isFrontEndConstant())
|
2017-01-14 02:34:22 +00:00
|
|
|
|
result = intermediate.foldSwizzle(base, selectors, loc);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
else {
|
2017-01-14 02:34:22 +00:00
|
|
|
|
if (selectors.size() == 1) {
|
|
|
|
|
TIntermTyped* index = intermediate.addConstantUnion(selectors[0], loc);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
result = intermediate.addIndex(EOpIndexDirect, base, index, loc);
|
2016-08-02 01:44:00 +00:00
|
|
|
|
result->setType(TType(base->getBasicType(), EvqTemporary));
|
2016-03-13 03:11:22 +00:00
|
|
|
|
} else {
|
2017-01-14 02:34:22 +00:00
|
|
|
|
TIntermTyped* index = intermediate.addSwizzle(selectors, loc);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
result = intermediate.addIndex(EOpVectorSwizzle, base, index, loc);
|
2017-07-28 22:20:13 +00:00
|
|
|
|
result->setType(TType(base->getBasicType(), EvqTemporary, base->getType().getQualifier().precision,
|
|
|
|
|
selectors.size()));
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-12 23:51:18 +00:00
|
|
|
|
} else if (base->isMatrix()) {
|
2017-01-14 02:34:22 +00:00
|
|
|
|
TSwizzleSelectors<TMatrixSelector> selectors;
|
|
|
|
|
if (! parseMatrixSwizzleSelector(loc, field, base->getMatrixCols(), base->getMatrixRows(), selectors))
|
2017-01-12 23:51:18 +00:00
|
|
|
|
return result;
|
|
|
|
|
|
2017-01-14 02:34:22 +00:00
|
|
|
|
if (selectors.size() == 1) {
|
2017-01-12 23:51:18 +00:00
|
|
|
|
// Representable by m[c][r]
|
2017-01-13 19:27:52 +00:00
|
|
|
|
if (base->getType().getQualifier().isFrontEndConstant()) {
|
2017-01-14 02:34:22 +00:00
|
|
|
|
result = intermediate.foldDereference(base, selectors[0].coord1, loc);
|
|
|
|
|
result = intermediate.foldDereference(result, selectors[0].coord2, loc);
|
2017-01-12 23:51:18 +00:00
|
|
|
|
} else {
|
2017-07-28 22:20:13 +00:00
|
|
|
|
result = intermediate.addIndex(EOpIndexDirect, base,
|
|
|
|
|
intermediate.addConstantUnion(selectors[0].coord1, loc),
|
|
|
|
|
loc);
|
2017-01-12 23:51:18 +00:00
|
|
|
|
TType dereferencedCol(base->getType(), 0);
|
|
|
|
|
result->setType(dereferencedCol);
|
2017-07-28 22:20:13 +00:00
|
|
|
|
result = intermediate.addIndex(EOpIndexDirect, result,
|
|
|
|
|
intermediate.addConstantUnion(selectors[0].coord2, loc),
|
|
|
|
|
loc);
|
2017-01-12 23:51:18 +00:00
|
|
|
|
TType dereferenced(dereferencedCol, 0);
|
|
|
|
|
result->setType(dereferenced);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2017-01-14 02:34:22 +00:00
|
|
|
|
int column = getMatrixComponentsColumn(base->getMatrixRows(), selectors);
|
2017-01-12 23:51:18 +00:00
|
|
|
|
if (column >= 0) {
|
|
|
|
|
// Representable by m[c]
|
2017-01-13 19:27:52 +00:00
|
|
|
|
if (base->getType().getQualifier().isFrontEndConstant())
|
2017-01-12 23:51:18 +00:00
|
|
|
|
result = intermediate.foldDereference(base, column, loc);
|
|
|
|
|
else {
|
2017-07-28 22:20:13 +00:00
|
|
|
|
result = intermediate.addIndex(EOpIndexDirect, base, intermediate.addConstantUnion(column, loc),
|
|
|
|
|
loc);
|
2017-01-12 23:51:18 +00:00
|
|
|
|
TType dereferenced(base->getType(), 0);
|
|
|
|
|
result->setType(dereferenced);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// general case, not a column, not a single component
|
2017-01-14 02:34:22 +00:00
|
|
|
|
TIntermTyped* index = intermediate.addSwizzle(selectors, loc);
|
2017-01-13 19:27:52 +00:00
|
|
|
|
result = intermediate.addIndex(EOpMatrixSwizzle, base, index, loc);
|
2017-07-28 22:20:13 +00:00
|
|
|
|
result->setType(TType(base->getBasicType(), EvqTemporary, base->getType().getQualifier().precision,
|
|
|
|
|
selectors.size()));
|
2017-01-13 19:27:52 +00:00
|
|
|
|
}
|
2017-01-12 23:51:18 +00:00
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
} else if (base->getBasicType() == EbtStruct || base->getBasicType() == EbtBlock) {
|
|
|
|
|
const TTypeList* fields = base->getType().getStruct();
|
|
|
|
|
bool fieldFound = false;
|
|
|
|
|
int member;
|
|
|
|
|
for (member = 0; member < (int)fields->size(); ++member) {
|
|
|
|
|
if ((*fields)[member].type->getFieldName() == field) {
|
|
|
|
|
fieldFound = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (fieldFound) {
|
2017-07-30 22:54:02 +00:00
|
|
|
|
if (base->getAsSymbolNode() && wasFlattened(base)) {
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
result = flattenAccess(base, member);
|
|
|
|
|
} else {
|
2017-07-30 22:54:02 +00:00
|
|
|
|
if (base->getType().getQualifier().storage == EvqConst)
|
|
|
|
|
result = intermediate.foldDereference(base, member, loc);
|
|
|
|
|
else {
|
|
|
|
|
TIntermTyped* index = intermediate.addConstantUnion(member, loc);
|
|
|
|
|
result = intermediate.addIndex(EOpIndexDirectStruct, base, index, loc);
|
|
|
|
|
result->setType(*(*fields)[member].type);
|
2016-09-09 22:32:09 +00:00
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
error(loc, "no such field in structure", field.c_str(), "");
|
|
|
|
|
} else
|
|
|
|
|
error(loc, "does not apply to this type:", field.c_str(), base->getType().getCompleteString().c_str());
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-09 03:09:03 +00:00
|
|
|
|
//
|
2017-03-11 16:39:55 +00:00
|
|
|
|
// Return true if the field should be treated as a built-in method.
|
|
|
|
|
// Return false otherwise.
|
2017-03-09 03:09:03 +00:00
|
|
|
|
//
|
2017-03-20 00:12:37 +00:00
|
|
|
|
bool HlslParseContext::isBuiltInMethod(const TSourceLoc&, TIntermTyped* base, const TString& field)
|
2017-03-09 03:09:03 +00:00
|
|
|
|
{
|
2017-03-11 21:13:00 +00:00
|
|
|
|
if (base == nullptr)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-03-09 03:09:03 +00:00
|
|
|
|
variableCheck(base);
|
|
|
|
|
|
2017-03-11 16:39:55 +00:00
|
|
|
|
if (base->getType().getBasicType() == EbtSampler) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (isStructBufferType(base->getType()) && isStructBufferMethod(field)) {
|
|
|
|
|
return true;
|
2017-03-09 03:09:03 +00:00
|
|
|
|
} else if (field == "Append" ||
|
|
|
|
|
field == "RestartStrip") {
|
|
|
|
|
// We cannot check the type here: it may be sanitized if we're not compiling a geometry shader, but
|
|
|
|
|
// the code is around in the shader source.
|
2017-03-11 16:39:55 +00:00
|
|
|
|
return true;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
2017-03-09 03:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 05:40:05 +00:00
|
|
|
|
// Independently establish a built-in that is a member of a structure.
|
|
|
|
|
// 'arraySizes' are what's desired for the independent built-in, whatever
|
|
|
|
|
// the higher-level source/expression of them was.
|
|
|
|
|
void HlslParseContext::splitBuiltIn(const TString& baseName, const TType& memberType, const TArraySizes* arraySizes,
|
|
|
|
|
const TQualifier& outerQualifier)
|
|
|
|
|
{
|
2017-08-09 02:02:21 +00:00
|
|
|
|
// Because of arrays of structs, we might be asked more than once,
|
|
|
|
|
// but the arraySizes passed in should have captured the whole thing
|
|
|
|
|
// the first time.
|
|
|
|
|
// However, clip/cull rely on multiple updates.
|
|
|
|
|
if (!isClipOrCullDistance(memberType))
|
|
|
|
|
if (splitBuiltIns.find(tInterstageIoData(memberType.getQualifier().builtIn, outerQualifier.storage)) !=
|
|
|
|
|
splitBuiltIns.end())
|
|
|
|
|
return;
|
|
|
|
|
|
2017-08-09 20:29:29 +00:00
|
|
|
|
TVariable* ioVar = makeInternalVariable(baseName + "." + memberType.getFieldName(), memberType);
|
2017-08-09 02:02:21 +00:00
|
|
|
|
|
|
|
|
|
if (arraySizes != nullptr && !memberType.isArray())
|
2017-08-08 05:40:05 +00:00
|
|
|
|
ioVar->getWritableType().newArraySizes(*arraySizes);
|
|
|
|
|
|
|
|
|
|
fixBuiltInIoType(ioVar->getWritableType());
|
|
|
|
|
|
|
|
|
|
splitBuiltIns[tInterstageIoData(memberType.getQualifier().builtIn, outerQualifier.storage)] = ioVar;
|
|
|
|
|
if (!isClipOrCullDistance(ioVar->getType()))
|
|
|
|
|
trackLinkage(*ioVar);
|
|
|
|
|
|
|
|
|
|
// Merge qualifier from the user structure
|
|
|
|
|
mergeQualifiers(ioVar->getWritableType().getQualifier(), outerQualifier);
|
2017-08-09 02:02:21 +00:00
|
|
|
|
// But, not location, we're losing that
|
|
|
|
|
ioVar->getWritableType().getQualifier().layoutLocation = TQualifier::layoutLocationEnd;
|
2017-08-08 05:40:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// Split a type into
|
|
|
|
|
// 1. a struct of non-I/O members
|
2017-08-08 05:40:05 +00:00
|
|
|
|
// 2. a collection of independent I/O variables
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
void HlslParseContext::split(const TVariable& variable)
|
|
|
|
|
{
|
|
|
|
|
// Create a new variable:
|
2017-08-08 05:40:05 +00:00
|
|
|
|
const TType& clonedType = *variable.getType().clone();
|
|
|
|
|
const TType& splitType = split(clonedType, variable.getName(), clonedType.getQualifier());
|
2017-08-07 01:42:42 +00:00
|
|
|
|
splitNonIoVars[variable.getUniqueId()] = makeInternalVariable(variable.getName(), splitType);
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// Recursive implementation of split().
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
// Returns reference to the modified type.
|
2017-08-08 05:40:05 +00:00
|
|
|
|
const TType& HlslParseContext::split(const TType& type, const TString& name, const TQualifier& outerQualifier)
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
{
|
|
|
|
|
if (type.isStruct()) {
|
|
|
|
|
TTypeList* userStructure = type.getWritableStruct();
|
2017-08-02 23:08:43 +00:00
|
|
|
|
for (auto ioType = userStructure->begin(); ioType != userStructure->end(); ) {
|
2017-08-08 05:40:05 +00:00
|
|
|
|
if (ioType->type->isBuiltIn()) {
|
|
|
|
|
// move out the built-in
|
|
|
|
|
splitBuiltIn(name, *ioType->type, type.getArraySizes(), outerQualifier);
|
2017-08-02 23:08:43 +00:00
|
|
|
|
ioType = userStructure->erase(ioType);
|
|
|
|
|
} else {
|
2017-08-09 20:29:29 +00:00
|
|
|
|
split(*ioType->type, name + "." + ioType->type->getFieldName(), outerQualifier);
|
2017-08-02 23:08:43 +00:00
|
|
|
|
++ioType;
|
|
|
|
|
}
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 06:01:36 +00:00
|
|
|
|
// Is this a uniform array or structure which should be flattened?
|
|
|
|
|
bool HlslParseContext::shouldFlatten(const TType& type) const
|
2016-09-16 19:26:37 +00:00
|
|
|
|
{
|
|
|
|
|
const TStorageQualifier qualifier = type.getQualifier().storage;
|
|
|
|
|
|
2017-05-26 06:01:36 +00:00
|
|
|
|
return (qualifier == EvqUniform && type.isArray() && intermediate.getFlattenUniformArrays()) ||
|
2017-06-10 13:42:03 +00:00
|
|
|
|
(type.isStruct() && type.containsOpaque());
|
2016-09-16 19:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
// Top level variable flattening: construct data
|
2017-08-07 01:42:42 +00:00
|
|
|
|
void HlslParseContext::flatten(const TVariable& variable, bool linkage)
|
2016-09-16 19:26:37 +00:00
|
|
|
|
{
|
|
|
|
|
const TType& type = variable.getType();
|
|
|
|
|
|
2017-08-09 02:02:21 +00:00
|
|
|
|
// If it's a standalone built-in, there is nothing to flatten
|
|
|
|
|
if (type.isBuiltIn() && !type.isStruct())
|
|
|
|
|
return;
|
|
|
|
|
|
2017-01-20 13:46:39 +00:00
|
|
|
|
auto entry = flattenMap.insert(std::make_pair(variable.getUniqueId(),
|
2017-06-27 21:17:38 +00:00
|
|
|
|
TFlattenData(type.getQualifier().layoutBinding,
|
|
|
|
|
type.getQualifier().layoutLocation)));
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
|
2017-01-20 13:46:39 +00:00
|
|
|
|
// the item is a map pair, so first->second is the TFlattenData itself.
|
2017-08-09 20:29:29 +00:00
|
|
|
|
flatten(variable, type, entry.first->second, variable.getName(), linkage, type.getQualifier(), nullptr);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
}
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
// Recursively flatten the given variable at the provided type, building the flattenData as we go.
|
|
|
|
|
//
|
|
|
|
|
// This is mutually recursive with flattenStruct and flattenArray.
|
|
|
|
|
// We are going to flatten an arbitrarily nested composite structure into a linear sequence of
|
|
|
|
|
// members, and later on, we want to turn a path through the tree structure into a final
|
|
|
|
|
// location in this linear sequence.
|
|
|
|
|
//
|
|
|
|
|
// If the tree was N-ary, that can be directly calculated. However, we are dealing with
|
2017-01-05 17:45:32 +00:00
|
|
|
|
// arbitrary numbers - perhaps a struct of 7 members containing an array of 3. Thus, we must
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
// build a data structure to allow the sequence of bracket and dot operators on arrays and
|
|
|
|
|
// structs to arrive at the proper member.
|
|
|
|
|
//
|
|
|
|
|
// To avoid storing a tree with pointers, we are going to flatten the tree into a vector of integers.
|
|
|
|
|
// The leaves are the indexes into the flattened member array.
|
|
|
|
|
// Each level will have the next location for the Nth item stored sequentially, so for instance:
|
|
|
|
|
//
|
|
|
|
|
// struct { float2 a[2]; int b; float4 c[3] };
|
|
|
|
|
//
|
|
|
|
|
// This will produce the following flattened tree:
|
|
|
|
|
// Pos: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
|
|
|
|
|
// (3, 7, 8, 5, 6, 0, 1, 2, 11, 12, 13, 3, 4, 5}
|
|
|
|
|
//
|
|
|
|
|
// Given a reference to mystruct.c[1], the access chain is (2,1), so we traverse:
|
|
|
|
|
// (0+2) = 8 --> (8+1) = 12 --> 12 = 4
|
|
|
|
|
//
|
|
|
|
|
// so the 4th flattened member in traversal order is ours.
|
|
|
|
|
//
|
2017-07-31 05:39:48 +00:00
|
|
|
|
int HlslParseContext::flatten(const TVariable& variable, const TType& type,
|
2017-08-09 02:02:21 +00:00
|
|
|
|
TFlattenData& flattenData, TString name, bool linkage,
|
|
|
|
|
const TQualifier& outerQualifier,
|
|
|
|
|
const TArraySizes* builtInArraySizes)
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
{
|
|
|
|
|
// If something is an arrayed struct, the array flattener will recursively call flatten()
|
|
|
|
|
// to then flatten the struct, so this is an "if else": we don't do both.
|
2016-09-16 19:26:37 +00:00
|
|
|
|
if (type.isArray())
|
2017-08-09 02:02:21 +00:00
|
|
|
|
return flattenArray(variable, type, flattenData, name, linkage, outerQualifier);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
else if (type.isStruct())
|
2017-08-09 02:02:21 +00:00
|
|
|
|
return flattenStruct(variable, type, flattenData, name, linkage, outerQualifier, builtInArraySizes);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
else {
|
|
|
|
|
assert(0); // should never happen
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add a single flattened member to the flattened data being tracked for the composite
|
|
|
|
|
// Returns true for the final flattening level.
|
2017-07-31 05:39:48 +00:00
|
|
|
|
int HlslParseContext::addFlattenedMember(const TVariable& variable, const TType& type, TFlattenData& flattenData,
|
2017-08-09 02:02:21 +00:00
|
|
|
|
const TString& memberName, bool linkage,
|
|
|
|
|
const TQualifier& outerQualifier,
|
|
|
|
|
const TArraySizes* builtInArraySizes)
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (isFinalFlattening(type)) {
|
|
|
|
|
// This is as far as we flatten. Insert the variable.
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
TVariable* memberVariable = makeInternalVariable(memberName, type);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
mergeQualifiers(memberVariable->getWritableType().getQualifier(), variable.getType().getQualifier());
|
|
|
|
|
|
|
|
|
|
if (flattenData.nextBinding != TQualifier::layoutBindingEnd)
|
|
|
|
|
memberVariable->getWritableType().getQualifier().layoutBinding = flattenData.nextBinding++;
|
|
|
|
|
|
2017-08-11 06:17:26 +00:00
|
|
|
|
if (memberVariable->getType().isBuiltIn()) {
|
|
|
|
|
// inherited locations are nonsensical for built-ins (TODO: what if semantic had a number)
|
|
|
|
|
memberVariable->getWritableType().getQualifier().layoutLocation = TQualifier::layoutLocationEnd;
|
|
|
|
|
} else {
|
2017-06-27 21:17:38 +00:00
|
|
|
|
// inherited locations must be auto bumped, not replicated
|
2017-08-08 05:40:05 +00:00
|
|
|
|
if (flattenData.nextLocation != TQualifier::layoutLocationEnd) {
|
2017-06-27 21:17:38 +00:00
|
|
|
|
memberVariable->getWritableType().getQualifier().layoutLocation = flattenData.nextLocation;
|
|
|
|
|
flattenData.nextLocation += intermediate.computeTypeLocationSize(memberVariable->getType());
|
|
|
|
|
nextOutLocation = std::max(nextOutLocation, flattenData.nextLocation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-13 22:30:58 +00:00
|
|
|
|
flattenData.offsets.push_back(static_cast<int>(flattenData.members.size()));
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
flattenData.members.push_back(memberVariable);
|
|
|
|
|
|
2017-08-07 01:42:42 +00:00
|
|
|
|
if (linkage)
|
2017-01-19 22:41:47 +00:00
|
|
|
|
trackLinkage(*memberVariable);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
|
2017-08-07 01:42:42 +00:00
|
|
|
|
return static_cast<int>(flattenData.offsets.size()) - 1; // location of the member reference
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Further recursion required
|
2017-08-09 02:02:21 +00:00
|
|
|
|
return flatten(variable, type, flattenData, memberName, linkage, outerQualifier, builtInArraySizes);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
}
|
2016-09-16 19:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-19 05:10:22 +00:00
|
|
|
|
// Figure out the mapping between an aggregate's top members and an
|
2016-09-09 22:32:09 +00:00
|
|
|
|
// equivalent set of individual variables.
|
|
|
|
|
//
|
|
|
|
|
// Assumes shouldFlatten() or equivalent was called first.
|
2017-07-31 05:39:48 +00:00
|
|
|
|
int HlslParseContext::flattenStruct(const TVariable& variable, const TType& type,
|
2017-08-09 02:02:21 +00:00
|
|
|
|
TFlattenData& flattenData, TString name, bool linkage,
|
|
|
|
|
const TQualifier& outerQualifier,
|
|
|
|
|
const TArraySizes* builtInArraySizes)
|
2016-09-09 22:32:09 +00:00
|
|
|
|
{
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
assert(type.isStruct());
|
|
|
|
|
|
|
|
|
|
auto members = *type.getStruct();
|
|
|
|
|
|
|
|
|
|
// Reserve space for this tree level.
|
2016-12-13 22:30:58 +00:00
|
|
|
|
int start = static_cast<int>(flattenData.offsets.size());
|
2017-08-09 02:02:21 +00:00
|
|
|
|
int pos = start;
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
flattenData.offsets.resize(int(pos + members.size()), -1);
|
2016-09-09 22:32:09 +00:00
|
|
|
|
|
|
|
|
|
for (int member = 0; member < (int)members.size(); ++member) {
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
TType& dereferencedType = *members[member].type;
|
2017-08-09 02:02:21 +00:00
|
|
|
|
if (dereferencedType.isBuiltIn())
|
|
|
|
|
splitBuiltIn(variable.getName(), dereferencedType, builtInArraySizes, outerQualifier);
|
|
|
|
|
else {
|
2017-08-09 20:29:29 +00:00
|
|
|
|
const int mpos = addFlattenedMember(variable, dereferencedType, flattenData,
|
|
|
|
|
name + "." + dereferencedType.getFieldName(),
|
|
|
|
|
linkage, outerQualifier,
|
2017-08-09 02:02:21 +00:00
|
|
|
|
builtInArraySizes == nullptr && dereferencedType.isArray()
|
|
|
|
|
? &dereferencedType.getArraySizes()
|
|
|
|
|
: builtInArraySizes);
|
|
|
|
|
flattenData.offsets[pos++] = mpos;
|
|
|
|
|
}
|
2016-09-09 22:32:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
return start;
|
2016-09-09 22:32:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 19:26:37 +00:00
|
|
|
|
// Figure out mapping between an array's members and an
|
|
|
|
|
// equivalent set of individual variables.
|
|
|
|
|
//
|
|
|
|
|
// Assumes shouldFlatten() or equivalent was called first.
|
2017-07-31 05:39:48 +00:00
|
|
|
|
int HlslParseContext::flattenArray(const TVariable& variable, const TType& type,
|
2017-08-09 02:02:21 +00:00
|
|
|
|
TFlattenData& flattenData, TString name, bool linkage,
|
|
|
|
|
const TQualifier& outerQualifier)
|
2016-09-16 19:26:37 +00:00
|
|
|
|
{
|
2017-07-31 05:39:48 +00:00
|
|
|
|
assert(type.isArray() && !type.isImplicitlySizedArray());
|
2016-09-16 19:26:37 +00:00
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
const int size = type.getOuterArraySize();
|
2016-09-16 19:26:37 +00:00
|
|
|
|
const TType dereferencedType(type, 0);
|
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
if (name.empty())
|
|
|
|
|
name = variable.getName();
|
|
|
|
|
|
|
|
|
|
// Reserve space for this tree level.
|
2016-12-13 22:30:58 +00:00
|
|
|
|
int start = static_cast<int>(flattenData.offsets.size());
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
int pos = start;
|
|
|
|
|
flattenData.offsets.resize(int(pos + size), -1);
|
2016-09-16 19:26:37 +00:00
|
|
|
|
|
2017-01-06 07:34:48 +00:00
|
|
|
|
for (int element=0; element < size; ++element) {
|
2016-09-16 19:26:37 +00:00
|
|
|
|
char elementNumBuf[20]; // sufficient for MAXINT
|
|
|
|
|
snprintf(elementNumBuf, sizeof(elementNumBuf)-1, "[%d]", element);
|
2017-07-31 05:39:48 +00:00
|
|
|
|
const int mpos = addFlattenedMember(variable, dereferencedType, flattenData,
|
2017-08-09 02:02:21 +00:00
|
|
|
|
name + elementNumBuf, linkage, outerQualifier,
|
|
|
|
|
type.getArraySizes());
|
2016-09-16 19:26:37 +00:00
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
flattenData.offsets[pos++] = mpos;
|
2016-09-16 19:26:37 +00:00
|
|
|
|
}
|
2016-11-05 16:15:53 +00:00
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
return start;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return true if we have flattened this node.
|
|
|
|
|
bool HlslParseContext::wasFlattened(const TIntermTyped* node) const
|
|
|
|
|
{
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
return node != nullptr && node->getAsSymbolNode() != nullptr &&
|
2017-07-31 05:39:48 +00:00
|
|
|
|
wasFlattened(node->getAsSymbolNode()->getId());
|
2016-09-16 19:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
// Return true if we have split this structure
|
|
|
|
|
bool HlslParseContext::wasSplit(const TIntermTyped* node) const
|
|
|
|
|
{
|
|
|
|
|
return node != nullptr && node->getAsSymbolNode() != nullptr &&
|
2017-07-30 22:54:02 +00:00
|
|
|
|
wasSplit(node->getAsSymbolNode()->getId());
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 19:26:37 +00:00
|
|
|
|
// Turn an access into an aggregate that was flattened to instead be
|
|
|
|
|
// an access to the individual variable the member was flattened to.
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// Assumes wasFlattened() or equivalent was called first.
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::flattenAccess(TIntermTyped* base, int member)
|
2016-09-09 22:32:09 +00:00
|
|
|
|
{
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
const TType dereferencedType(base->getType(), member); // dereferenced type
|
2016-09-09 22:32:09 +00:00
|
|
|
|
const TIntermSymbol& symbolNode = *base->getAsSymbolNode();
|
2017-06-29 23:43:31 +00:00
|
|
|
|
TIntermTyped* flattened = flattenAccess(symbolNode.getId(), member, dereferencedType, symbolNode.getFlattenSubset());
|
2017-05-26 06:01:36 +00:00
|
|
|
|
|
|
|
|
|
return flattened ? flattened : base;
|
|
|
|
|
}
|
2017-06-29 23:43:31 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::flattenAccess(int uniqueId, int member, const TType& dereferencedType, int subset)
|
2017-05-26 06:01:36 +00:00
|
|
|
|
{
|
|
|
|
|
const auto flattenData = flattenMap.find(uniqueId);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
|
|
|
|
|
if (flattenData == flattenMap.end())
|
2017-05-26 06:01:36 +00:00
|
|
|
|
return nullptr;
|
2016-09-09 22:32:09 +00:00
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
// Calculate new cumulative offset from the packed tree
|
2017-06-29 23:43:31 +00:00
|
|
|
|
int newSubset = flattenData->second.offsets[subset >= 0 ? subset + member : member];
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
|
2017-06-29 23:43:31 +00:00
|
|
|
|
TIntermSymbol* subsetSymbol;
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
if (isFinalFlattening(dereferencedType)) {
|
|
|
|
|
// Finished flattening: create symbol for variable
|
2017-06-29 23:43:31 +00:00
|
|
|
|
member = flattenData->second.offsets[newSubset];
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
const TVariable* memberVariable = flattenData->second.members[member];
|
2017-06-29 23:43:31 +00:00
|
|
|
|
subsetSymbol = intermediate.addSymbol(*memberVariable);
|
|
|
|
|
subsetSymbol->setFlattenSubset(-1);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
} else {
|
2017-06-29 23:43:31 +00:00
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
// If this is not the final flattening, accumulate the position and return
|
|
|
|
|
// an object of the partially dereferenced type.
|
2017-06-29 23:43:31 +00:00
|
|
|
|
subsetSymbol = new TIntermSymbol(uniqueId, "flattenShadow", dereferencedType);
|
|
|
|
|
subsetSymbol->setFlattenSubset(newSubset);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
}
|
2017-06-29 23:43:31 +00:00
|
|
|
|
|
|
|
|
|
return subsetSymbol;
|
2016-09-09 22:32:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
// Find and return the split IO TVariable for id, or nullptr if none.
|
2017-08-07 01:42:42 +00:00
|
|
|
|
TVariable* HlslParseContext::getSplitNonIoVar(int id) const
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
{
|
2017-08-07 01:42:42 +00:00
|
|
|
|
const auto splitNonIoVar = splitNonIoVars.find(id);
|
|
|
|
|
if (splitNonIoVar == splitNonIoVars.end())
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
return nullptr;
|
|
|
|
|
|
2017-08-07 01:42:42 +00:00
|
|
|
|
return splitNonIoVar->second;
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// Pass through to base class after remembering built-in mappings.
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
void HlslParseContext::trackLinkage(TSymbol& symbol)
|
|
|
|
|
{
|
|
|
|
|
TBuiltInVariable biType = symbol.getType().getQualifier().builtIn;
|
2017-04-01 21:34:48 +00:00
|
|
|
|
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
if (biType != EbvNone)
|
2017-08-04 19:51:54 +00:00
|
|
|
|
builtInTessLinkageSymbols[biType] = symbol.clone();
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
|
|
|
|
TParseContextBase::trackLinkage(symbol);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// Returns true if the built-in is a clip or cull distance variable.
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
bool HlslParseContext::isClipOrCullDistance(TBuiltInVariable builtIn)
|
|
|
|
|
{
|
|
|
|
|
return builtIn == EbvClipDistance || builtIn == EbvCullDistance;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-18 00:51:05 +00:00
|
|
|
|
// Some types require fixed array sizes in SPIR-V, but can be scalars or
|
|
|
|
|
// arrays of sizes SPIR-V doesn't allow. For example, tessellation factors.
|
|
|
|
|
// This creates the right size. A conversion is performed when the internal
|
2017-04-05 17:03:02 +00:00
|
|
|
|
// type is copied to or from the external type. This corrects the externally
|
|
|
|
|
// facing input or output type to abide downstream semantics.
|
|
|
|
|
void HlslParseContext::fixBuiltInIoType(TType& type)
|
2017-03-18 00:51:05 +00:00
|
|
|
|
{
|
2017-04-05 17:03:02 +00:00
|
|
|
|
int requiredArraySize = 0;
|
2017-03-18 00:51:05 +00:00
|
|
|
|
|
|
|
|
|
switch (type.getQualifier().builtIn) {
|
2017-04-05 17:03:02 +00:00
|
|
|
|
case EbvTessLevelOuter: requiredArraySize = 4; break;
|
|
|
|
|
case EbvTessLevelInner: requiredArraySize = 2; break;
|
2017-06-22 18:08:00 +00:00
|
|
|
|
|
2017-04-05 17:03:02 +00:00
|
|
|
|
case EbvTessCoord:
|
|
|
|
|
{
|
|
|
|
|
// tesscoord is always a vec3 for the IO variable, no matter the shader's
|
|
|
|
|
// declared vector size.
|
|
|
|
|
TType tessCoordType(type.getBasicType(), type.getQualifier().storage, 3);
|
|
|
|
|
|
|
|
|
|
tessCoordType.getQualifier() = type.getQualifier();
|
|
|
|
|
type.shallowCopy(tessCoordType);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-03-18 00:51:05 +00:00
|
|
|
|
default:
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
if (isClipOrCullDistance(type)) {
|
|
|
|
|
if (type.getQualifier().builtIn == EbvClipDistance) {
|
|
|
|
|
clipSemanticNSize[type.getQualifier().layoutLocation] = type.getVectorSize();
|
|
|
|
|
} else {
|
|
|
|
|
cullSemanticNSize[type.getQualifier().layoutLocation] = type.getVectorSize();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-18 00:51:05 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 17:03:02 +00:00
|
|
|
|
// Alter or set array size as needed.
|
|
|
|
|
if (requiredArraySize > 0) {
|
2017-08-11 06:14:46 +00:00
|
|
|
|
if (!type.isArray() || type.getOuterArraySize() != requiredArraySize) {
|
2017-04-05 17:03:02 +00:00
|
|
|
|
TArraySizes arraySizes;
|
|
|
|
|
arraySizes.addInnerSize(requiredArraySize);
|
|
|
|
|
type.newArraySizes(arraySizes);
|
|
|
|
|
}
|
2017-03-18 00:51:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 07:44:43 +00:00
|
|
|
|
// Variables that correspond to the user-interface in and out of a stage
|
2017-06-20 09:20:59 +00:00
|
|
|
|
// (not the built-in interface) are
|
|
|
|
|
// - assigned locations
|
|
|
|
|
// - registered as a linkage node (part of the stage's external interface).
|
2016-09-16 07:44:43 +00:00
|
|
|
|
// Assumes it is called in the order in which locations should be assigned.
|
2017-06-20 09:20:59 +00:00
|
|
|
|
void HlslParseContext::assignToInterface(TVariable& variable)
|
2016-09-16 07:44:43 +00:00
|
|
|
|
{
|
|
|
|
|
const auto assignLocation = [&](TVariable& variable) {
|
2017-06-20 09:20:59 +00:00
|
|
|
|
TType& type = variable.getWritableType();
|
2017-08-04 00:41:48 +00:00
|
|
|
|
if (!type.isStruct() || type.getStruct()->size() > 0) {
|
|
|
|
|
TQualifier& qualifier = type.getQualifier();
|
|
|
|
|
if (qualifier.storage == EvqVaryingIn || qualifier.storage == EvqVaryingOut) {
|
|
|
|
|
if (qualifier.builtIn == EbvNone && !qualifier.hasLocation()) {
|
|
|
|
|
// Strip off the outer array dimension for those having an extra one.
|
|
|
|
|
int size;
|
|
|
|
|
if (type.isArray() && qualifier.isArrayedIo(language)) {
|
|
|
|
|
TType elementType(type, 0);
|
|
|
|
|
size = intermediate.computeTypeLocationSize(elementType);
|
|
|
|
|
} else
|
|
|
|
|
size = intermediate.computeTypeLocationSize(type);
|
|
|
|
|
|
|
|
|
|
if (qualifier.storage == EvqVaryingIn) {
|
|
|
|
|
variable.getWritableType().getQualifier().layoutLocation = nextInLocation;
|
|
|
|
|
nextInLocation += size;
|
|
|
|
|
} else {
|
|
|
|
|
variable.getWritableType().getQualifier().layoutLocation = nextOutLocation;
|
|
|
|
|
nextOutLocation += size;
|
|
|
|
|
}
|
2016-09-16 07:44:43 +00:00
|
|
|
|
}
|
2017-08-04 00:41:48 +00:00
|
|
|
|
trackLinkage(variable);
|
2016-09-16 07:44:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
if (wasFlattened(variable.getUniqueId())) {
|
|
|
|
|
auto& memberList = flattenMap[variable.getUniqueId()].members;
|
2016-09-16 07:44:43 +00:00
|
|
|
|
for (auto member = memberList.begin(); member != memberList.end(); ++member)
|
|
|
|
|
assignLocation(**member);
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
} else if (wasSplit(variable.getUniqueId())) {
|
2017-08-07 01:42:42 +00:00
|
|
|
|
TVariable* splitIoVar = getSplitNonIoVar(variable.getUniqueId());
|
2017-03-10 02:10:57 +00:00
|
|
|
|
assignLocation(*splitIoVar);
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
} else {
|
2016-09-16 07:44:43 +00:00
|
|
|
|
assignLocation(variable);
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
}
|
2016-09-16 07:44:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Handle seeing a function declarator in the grammar. This is the precursor
|
|
|
|
|
// to recognizing a function prototype or function definition.
|
|
|
|
|
//
|
2017-03-12 00:55:28 +00:00
|
|
|
|
void HlslParseContext::handleFunctionDeclarator(const TSourceLoc& loc, TFunction& function, bool prototype)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// Multiple declarations of the same function name are allowed.
|
|
|
|
|
//
|
|
|
|
|
// If this is a definition, the definition production code will check for redefinitions
|
|
|
|
|
// (we don't know at this point if it's a definition or not).
|
|
|
|
|
//
|
|
|
|
|
bool builtIn;
|
|
|
|
|
TSymbol* symbol = symbolTable.find(function.getMangledName(), &builtIn);
|
|
|
|
|
const TFunction* prevDec = symbol ? symbol->getAsFunction() : 0;
|
|
|
|
|
|
|
|
|
|
if (prototype) {
|
|
|
|
|
// All built-in functions are defined, even though they don't have a body.
|
|
|
|
|
// Count their prototype as a definition instead.
|
|
|
|
|
if (symbolTable.atBuiltInLevel())
|
|
|
|
|
function.setDefined();
|
|
|
|
|
else {
|
|
|
|
|
if (prevDec && ! builtIn)
|
|
|
|
|
symbol->getAsFunction()->setPrototyped(); // need a writable one, but like having prevDec as a const
|
|
|
|
|
function.setPrototyped();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This insert won't actually insert it if it's a duplicate signature, but it will still check for
|
|
|
|
|
// other forms of name collisions.
|
|
|
|
|
if (! symbolTable.insert(function))
|
|
|
|
|
error(loc, "function name is redeclaration of existing name", function.getName().c_str(), "");
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:22:32 +00:00
|
|
|
|
// For struct buffers with counters, we must pass the counter buffer as hidden parameter.
|
|
|
|
|
// This adds the hidden parameter to the parameter list in 'paramNodes' if needed.
|
|
|
|
|
// Otherwise, it's a no-op
|
2017-07-28 22:20:13 +00:00
|
|
|
|
void HlslParseContext::addStructBufferHiddenCounterParam(const TSourceLoc& loc, TParameter& param,
|
|
|
|
|
TIntermAggregate*& paramNodes)
|
2017-04-27 17:22:32 +00:00
|
|
|
|
{
|
|
|
|
|
if (! hasStructBuffCounter(*param.type))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const TString counterBlockName(getStructBuffCounterName(*param.name));
|
|
|
|
|
|
|
|
|
|
TType counterType;
|
|
|
|
|
counterBufferType(loc, counterType);
|
|
|
|
|
TVariable *variable = makeInternalVariable(counterBlockName, counterType);
|
|
|
|
|
|
|
|
|
|
if (! symbolTable.insert(*variable))
|
|
|
|
|
error(loc, "redefinition", variable->getName().c_str(), "");
|
|
|
|
|
|
|
|
|
|
paramNodes = intermediate.growAggregate(paramNodes,
|
|
|
|
|
intermediate.addSymbol(*variable, loc),
|
|
|
|
|
loc);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// Handle seeing the function prototype in front of a function definition in the grammar.
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// The body is handled after this function returns.
|
|
|
|
|
//
|
2017-03-08 03:44:09 +00:00
|
|
|
|
// Returns an aggregate of parameter-symbol nodes.
|
|
|
|
|
//
|
2017-01-06 07:34:48 +00:00
|
|
|
|
TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& loc, TFunction& function,
|
2017-07-28 22:20:13 +00:00
|
|
|
|
const TAttributeMap& attributes,
|
|
|
|
|
TIntermNode*& entryPointTree)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
currentCaller = function.getMangledName();
|
|
|
|
|
TSymbol* symbol = symbolTable.find(function.getMangledName());
|
|
|
|
|
TFunction* prevDec = symbol ? symbol->getAsFunction() : nullptr;
|
|
|
|
|
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (prevDec == nullptr)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
error(loc, "can't find function", function.getName().c_str(), "");
|
|
|
|
|
// Note: 'prevDec' could be 'function' if this is the first time we've seen function
|
|
|
|
|
// as it would have just been put in the symbol table. Otherwise, we're looking up
|
|
|
|
|
// an earlier occurrence.
|
|
|
|
|
|
|
|
|
|
if (prevDec && prevDec->isDefined()) {
|
|
|
|
|
// Then this function already has a body.
|
|
|
|
|
error(loc, "function already has a body", function.getName().c_str(), "");
|
|
|
|
|
}
|
|
|
|
|
if (prevDec && ! prevDec->isDefined()) {
|
|
|
|
|
prevDec->setDefined();
|
|
|
|
|
|
|
|
|
|
// Remember the return type for later checking for RETURN statements.
|
|
|
|
|
currentFunctionType = &(prevDec->getType());
|
|
|
|
|
} else
|
|
|
|
|
currentFunctionType = new TType(EbtVoid);
|
|
|
|
|
functionReturnsValue = false;
|
|
|
|
|
|
2017-01-18 23:45:02 +00:00
|
|
|
|
// Entry points need different I/O and other handling, transform it so the
|
|
|
|
|
// rest of this function doesn't care.
|
2017-01-19 22:41:47 +00:00
|
|
|
|
entryPointTree = transformEntryPoint(loc, function, attributes);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// New symbol table scope for body of function plus its arguments
|
|
|
|
|
//
|
2016-06-09 08:02:17 +00:00
|
|
|
|
pushScope();
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Insert parameters into the symbol table.
|
|
|
|
|
// If the parameter has no name, it's not an error, just don't insert it
|
|
|
|
|
// (could be used for unused args).
|
|
|
|
|
//
|
2016-09-16 07:44:43 +00:00
|
|
|
|
// Also, accumulate the list of parameters into the AST, so lower level code
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// knows where to find parameters.
|
|
|
|
|
//
|
|
|
|
|
TIntermAggregate* paramNodes = new TIntermAggregate;
|
|
|
|
|
for (int i = 0; i < function.getParamCount(); i++) {
|
|
|
|
|
TParameter& param = function[i];
|
|
|
|
|
if (param.name != nullptr) {
|
2017-01-19 22:41:47 +00:00
|
|
|
|
TVariable *variable = new TVariable(param.name, *param.type);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
2017-03-22 05:56:40 +00:00
|
|
|
|
if (i == 0 && function.hasImplicitThis()) {
|
2017-03-22 17:38:22 +00:00
|
|
|
|
// Anonymous 'this' members are already in a symbol-table level,
|
|
|
|
|
// and we need to know what function parameter to map them to.
|
2017-03-22 05:56:40 +00:00
|
|
|
|
symbolTable.makeInternalVariable(*variable);
|
|
|
|
|
pushImplicitThis(variable);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
2017-05-26 06:01:36 +00:00
|
|
|
|
|
2017-03-22 17:38:22 +00:00
|
|
|
|
// Insert the parameters with name in the symbol table.
|
|
|
|
|
if (! symbolTable.insert(*variable))
|
|
|
|
|
error(loc, "redefinition", variable->getName().c_str(), "");
|
2017-04-20 22:37:14 +00:00
|
|
|
|
|
2017-05-26 06:01:36 +00:00
|
|
|
|
// Add parameters to the AST list.
|
|
|
|
|
if (shouldFlatten(variable->getType())) {
|
|
|
|
|
// Expand the AST parameter nodes (but not the name mangling or symbol table view)
|
|
|
|
|
// for structures that need to be flattened.
|
2017-08-07 01:42:42 +00:00
|
|
|
|
flatten(*variable, false);
|
2017-05-26 06:01:36 +00:00
|
|
|
|
const TTypeList* structure = variable->getType().getStruct();
|
|
|
|
|
for (int mem = 0; mem < (int)structure->size(); ++mem) {
|
|
|
|
|
paramNodes = intermediate.growAggregate(paramNodes,
|
2017-07-28 22:20:13 +00:00
|
|
|
|
flattenAccess(variable->getUniqueId(), mem,
|
|
|
|
|
*(*structure)[mem].type),
|
2017-05-26 06:01:36 +00:00
|
|
|
|
loc);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Add the parameter to the AST
|
|
|
|
|
paramNodes = intermediate.growAggregate(paramNodes,
|
|
|
|
|
intermediate.addSymbol(*variable, loc),
|
|
|
|
|
loc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add hidden AST parameter for struct buffer counters, if needed.
|
2017-04-27 17:22:32 +00:00
|
|
|
|
addStructBufferHiddenCounterParam(loc, param, paramNodes);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
} else
|
2016-04-04 02:36:48 +00:00
|
|
|
|
paramNodes = intermediate.growAggregate(paramNodes, intermediate.addSymbol(*param.type, loc), loc);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
2017-03-22 05:56:40 +00:00
|
|
|
|
if (function.hasIllegalImplicitThis())
|
|
|
|
|
pushImplicitThis(nullptr);
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
intermediate.setAggregateOperator(paramNodes, EOpParameters, TType(EbtVoid), loc);
|
|
|
|
|
loopNestingLevel = 0;
|
|
|
|
|
controlFlowNestingLevel = 0;
|
2016-11-26 20:31:47 +00:00
|
|
|
|
postEntryPointReturn = false;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
2017-01-18 23:45:02 +00:00
|
|
|
|
return paramNodes;
|
|
|
|
|
}
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2017-01-18 23:45:02 +00:00
|
|
|
|
|
2017-03-23 00:39:25 +00:00
|
|
|
|
// Handle all [attrib] attribute for the shader entry point
|
2017-03-23 17:56:07 +00:00
|
|
|
|
void HlslParseContext::handleEntryPointAttributes(const TSourceLoc& loc, const TAttributeMap& attributes)
|
2017-03-23 00:39:25 +00:00
|
|
|
|
{
|
2017-01-19 22:41:47 +00:00
|
|
|
|
// Handle entry-point function attributes
|
2017-01-18 23:45:02 +00:00
|
|
|
|
const TIntermAggregate* numThreads = attributes[EatNumThreads];
|
|
|
|
|
if (numThreads != nullptr) {
|
|
|
|
|
const TIntermSequence& sequence = numThreads->getSequence();
|
|
|
|
|
|
|
|
|
|
for (int lid = 0; lid < int(sequence.size()); ++lid)
|
|
|
|
|
intermediate.setLocalSize(lid, sequence[lid]->getAsConstantUnion()->getConstArray()[0].getIConst());
|
|
|
|
|
}
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
|
|
|
|
// MaxVertexCount
|
2017-01-18 23:45:02 +00:00
|
|
|
|
const TIntermAggregate* maxVertexCount = attributes[EatMaxVertexCount];
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
if (maxVertexCount != nullptr) {
|
2017-07-28 22:20:13 +00:00
|
|
|
|
if (! intermediate.setVertices(maxVertexCount->getSequence()[0]->getAsConstantUnion()->
|
|
|
|
|
getConstArray()[0].getIConst())) {
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
error(loc, "cannot change previously set maxvertexcount attribute", "", "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle [patchconstantfunction("...")]
|
|
|
|
|
const TIntermAggregate* pcfAttr = attributes[EatPatchConstantFunc];
|
|
|
|
|
if (pcfAttr != nullptr) {
|
|
|
|
|
const TConstUnion& pcfName = pcfAttr->getSequence()[0]->getAsConstantUnion()->getConstArray()[0];
|
|
|
|
|
|
|
|
|
|
if (pcfName.getType() != EbtString) {
|
|
|
|
|
error(loc, "invalid patch constant function", "", "");
|
|
|
|
|
} else {
|
|
|
|
|
patchConstantFunctionName = *pcfName.getSConst();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle [domain("...")]
|
|
|
|
|
const TIntermAggregate* domainAttr = attributes[EatDomain];
|
|
|
|
|
if (domainAttr != nullptr) {
|
|
|
|
|
const TConstUnion& domainType = domainAttr->getSequence()[0]->getAsConstantUnion()->getConstArray()[0];
|
|
|
|
|
if (domainType.getType() != EbtString) {
|
|
|
|
|
error(loc, "invalid domain", "", "");
|
|
|
|
|
} else {
|
|
|
|
|
TString domainStr = *domainType.getSConst();
|
|
|
|
|
std::transform(domainStr.begin(), domainStr.end(), domainStr.begin(), ::tolower);
|
|
|
|
|
|
|
|
|
|
TLayoutGeometry domain = ElgNone;
|
|
|
|
|
|
|
|
|
|
if (domainStr == "tri") {
|
|
|
|
|
domain = ElgTriangles;
|
|
|
|
|
} else if (domainStr == "quad") {
|
|
|
|
|
domain = ElgQuads;
|
|
|
|
|
} else if (domainStr == "isoline") {
|
|
|
|
|
domain = ElgIsolines;
|
|
|
|
|
} else {
|
|
|
|
|
error(loc, "unsupported domain type", domainStr.c_str(), "");
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 00:39:25 +00:00
|
|
|
|
if (language == EShLangTessEvaluation) {
|
|
|
|
|
if (! intermediate.setInputPrimitive(domain))
|
|
|
|
|
error(loc, "cannot change previously set domain", TQualifier::getGeometryString(domain), "");
|
|
|
|
|
} else {
|
|
|
|
|
if (! intermediate.setOutputPrimitive(domain))
|
|
|
|
|
error(loc, "cannot change previously set domain", TQualifier::getGeometryString(domain), "");
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-26 23:52:22 +00:00
|
|
|
|
// Handle [outputtopology("...")]
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
const TIntermAggregate* topologyAttr = attributes[EatOutputTopology];
|
|
|
|
|
if (topologyAttr != nullptr) {
|
|
|
|
|
const TConstUnion& topoType = topologyAttr->getSequence()[0]->getAsConstantUnion()->getConstArray()[0];
|
|
|
|
|
if (topoType.getType() != EbtString) {
|
2017-06-26 23:52:22 +00:00
|
|
|
|
error(loc, "invalid outputtopology", "", "");
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
} else {
|
|
|
|
|
TString topologyStr = *topoType.getSConst();
|
|
|
|
|
std::transform(topologyStr.begin(), topologyStr.end(), topologyStr.begin(), ::tolower);
|
|
|
|
|
|
2017-06-26 23:52:22 +00:00
|
|
|
|
TVertexOrder vertexOrder = EvoNone;
|
|
|
|
|
TLayoutGeometry primitive = ElgNone;
|
|
|
|
|
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
if (topologyStr == "point") {
|
2017-06-26 23:52:22 +00:00
|
|
|
|
intermediate.setPointMode();
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
} else if (topologyStr == "line") {
|
2017-06-26 23:52:22 +00:00
|
|
|
|
primitive = ElgIsolines;
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
} else if (topologyStr == "triangle_cw") {
|
2017-06-26 23:52:22 +00:00
|
|
|
|
vertexOrder = EvoCw;
|
|
|
|
|
primitive = ElgTriangles;
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
} else if (topologyStr == "triangle_ccw") {
|
2017-06-26 23:52:22 +00:00
|
|
|
|
vertexOrder = EvoCcw;
|
|
|
|
|
primitive = ElgTriangles;
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
} else {
|
2017-06-26 23:52:22 +00:00
|
|
|
|
error(loc, "unsupported outputtopology type", topologyStr.c_str(), "");
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-26 23:52:22 +00:00
|
|
|
|
if (vertexOrder != EvoNone) {
|
|
|
|
|
if (! intermediate.setVertexOrder(vertexOrder)) {
|
|
|
|
|
error(loc, "cannot change previously set outputtopology",
|
|
|
|
|
TQualifier::getVertexOrderString(vertexOrder), "");
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-26 23:52:22 +00:00
|
|
|
|
if (primitive != ElgNone)
|
|
|
|
|
intermediate.setOutputPrimitive(primitive);
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle [partitioning("...")]
|
|
|
|
|
const TIntermAggregate* partitionAttr = attributes[EatPartitioning];
|
|
|
|
|
if (partitionAttr != nullptr) {
|
|
|
|
|
const TConstUnion& partType = partitionAttr->getSequence()[0]->getAsConstantUnion()->getConstArray()[0];
|
|
|
|
|
if (partType.getType() != EbtString) {
|
|
|
|
|
error(loc, "invalid partitioning", "", "");
|
|
|
|
|
} else {
|
|
|
|
|
TString partitionStr = *partType.getSConst();
|
|
|
|
|
std::transform(partitionStr.begin(), partitionStr.end(), partitionStr.begin(), ::tolower);
|
|
|
|
|
|
|
|
|
|
TVertexSpacing partitioning = EvsNone;
|
|
|
|
|
|
|
|
|
|
if (partitionStr == "integer") {
|
|
|
|
|
partitioning = EvsEqual;
|
|
|
|
|
} else if (partitionStr == "fractional_even") {
|
|
|
|
|
partitioning = EvsFractionalEven;
|
|
|
|
|
} else if (partitionStr == "fractional_odd") {
|
|
|
|
|
partitioning = EvsFractionalOdd;
|
|
|
|
|
//} else if (partition == "pow2") { // TODO: currently nothing to map this to.
|
|
|
|
|
} else {
|
|
|
|
|
error(loc, "unsupported partitioning type", partitionStr.c_str(), "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! intermediate.setVertexSpacing(partitioning))
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "cannot change previously set partitioning",
|
|
|
|
|
TQualifier::getVertexSpacingString(partitioning), "");
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle [outputcontrolpoints("...")]
|
|
|
|
|
const TIntermAggregate* outputControlPoints = attributes[EatOutputControlPoints];
|
|
|
|
|
if (outputControlPoints != nullptr) {
|
2017-07-28 22:20:13 +00:00
|
|
|
|
const TConstUnion& ctrlPointConst =
|
|
|
|
|
outputControlPoints->getSequence()[0]->getAsConstantUnion()->getConstArray()[0];
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
if (ctrlPointConst.getType() != EbtInt) {
|
|
|
|
|
error(loc, "invalid outputcontrolpoints", "", "");
|
|
|
|
|
} else {
|
|
|
|
|
const int ctrlPoints = ctrlPointConst.getIConst();
|
|
|
|
|
if (! intermediate.setVertices(ctrlPoints)) {
|
|
|
|
|
error(loc, "cannot change previously set outputcontrolpoints attribute", "", "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-23 00:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Do all special handling for the entry point, including wrapping
|
|
|
|
|
// the shader's entry point with the official entry point that will call it.
|
|
|
|
|
//
|
|
|
|
|
// The following:
|
|
|
|
|
//
|
|
|
|
|
// retType shaderEntryPoint(args...) // shader declared entry point
|
|
|
|
|
// { body }
|
|
|
|
|
//
|
|
|
|
|
// Becomes
|
|
|
|
|
//
|
|
|
|
|
// out retType ret;
|
|
|
|
|
// in iargs<that are input>...;
|
|
|
|
|
// out oargs<that are output> ...;
|
|
|
|
|
//
|
|
|
|
|
// void shaderEntryPoint() // synthesized, but official, entry point
|
|
|
|
|
// {
|
|
|
|
|
// args<that are input> = iargs...;
|
|
|
|
|
// ret = @shaderEntryPoint(args...);
|
|
|
|
|
// oargs = args<that are output>...;
|
|
|
|
|
// }
|
2017-06-20 09:20:59 +00:00
|
|
|
|
// retType @shaderEntryPoint(args...)
|
|
|
|
|
// { body }
|
2017-03-23 00:39:25 +00:00
|
|
|
|
//
|
|
|
|
|
// The symbol table will still map the original entry point name to the
|
2017-06-20 09:20:59 +00:00
|
|
|
|
// the modified function and its new name:
|
2017-03-23 00:39:25 +00:00
|
|
|
|
//
|
|
|
|
|
// symbol table: shaderEntryPoint -> @shaderEntryPoint
|
|
|
|
|
//
|
|
|
|
|
// Returns nullptr if no entry-point tree was built, otherwise, returns
|
|
|
|
|
// a subtree that creates the entry point.
|
|
|
|
|
//
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermNode* HlslParseContext::transformEntryPoint(const TSourceLoc& loc, TFunction& userFunction,
|
|
|
|
|
const TAttributeMap& attributes)
|
2017-03-23 00:39:25 +00:00
|
|
|
|
{
|
2017-04-03 15:27:53 +00:00
|
|
|
|
// Return true if this is a tessellation patch constant function input to a domain shader.
|
|
|
|
|
const auto isDsPcfInput = [this](const TType& type) {
|
|
|
|
|
return language == EShLangTessEvaluation &&
|
|
|
|
|
type.contains([](const TType* t) {
|
|
|
|
|
return t->getQualifier().builtIn == EbvTessLevelOuter ||
|
2017-08-04 00:41:48 +00:00
|
|
|
|
t->getQualifier().builtIn == EbvTessLevelInner;
|
2017-04-03 15:27:53 +00:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-03-23 00:39:25 +00:00
|
|
|
|
// if we aren't in the entry point, fix the IO as such and exit
|
|
|
|
|
if (userFunction.getName().compare(intermediate.getEntryPointName().c_str()) != 0) {
|
|
|
|
|
remapNonEntryPointIO(userFunction);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entryPointFunction = &userFunction; // needed in finish()
|
|
|
|
|
|
|
|
|
|
// Handle entry point attributes
|
2017-03-23 17:56:07 +00:00
|
|
|
|
handleEntryPointAttributes(loc, attributes);
|
2017-03-23 00:39:25 +00:00
|
|
|
|
|
|
|
|
|
// entry point logic...
|
2017-01-19 22:41:47 +00:00
|
|
|
|
|
|
|
|
|
// Move parameters and return value to shader in/out
|
|
|
|
|
TVariable* entryPointOutput; // gets created in remapEntryPointIO
|
|
|
|
|
TVector<TVariable*> inputs;
|
|
|
|
|
TVector<TVariable*> outputs;
|
|
|
|
|
remapEntryPointIO(userFunction, entryPointOutput, inputs, outputs);
|
|
|
|
|
|
|
|
|
|
// Further this return/in/out transform by flattening, splitting, and assigning locations
|
|
|
|
|
const auto makeVariableInOut = [&](TVariable& variable) {
|
|
|
|
|
if (variable.getType().isStruct()) {
|
2017-08-11 06:17:26 +00:00
|
|
|
|
if (variable.getType().getQualifier().isArrayedIo(language)) {
|
|
|
|
|
if (variable.getType().containsBuiltIn())
|
|
|
|
|
split(variable);
|
|
|
|
|
} else
|
2017-08-07 01:42:42 +00:00
|
|
|
|
flatten(variable, false /* don't track linkage here, it will be tracked in assignToInterface() */);
|
2017-01-19 22:41:47 +00:00
|
|
|
|
}
|
2017-08-11 06:17:26 +00:00
|
|
|
|
// TODO: flatten arrays too
|
|
|
|
|
// TODO: flatten everything in I/O
|
|
|
|
|
// TODO: replace all split with flatten, make all paths can create flattened I/O, then split code can be removed
|
2017-04-01 21:34:48 +00:00
|
|
|
|
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
// For clip and cull distance, multiple output variables potentially get merged
|
|
|
|
|
// into one in assignClipCullDistance. That code in assignClipCullDistance
|
|
|
|
|
// handles the interface logic, so we avoid it here in that case.
|
|
|
|
|
if (!isClipOrCullDistance(variable.getType()))
|
|
|
|
|
assignToInterface(variable);
|
2017-01-19 22:41:47 +00:00
|
|
|
|
};
|
2017-06-27 21:17:38 +00:00
|
|
|
|
if (entryPointOutput != nullptr)
|
2017-01-19 22:41:47 +00:00
|
|
|
|
makeVariableInOut(*entryPointOutput);
|
|
|
|
|
for (auto it = inputs.begin(); it != inputs.end(); ++it)
|
2017-08-04 18:04:44 +00:00
|
|
|
|
if (!isDsPcfInput((*it)->getType())) // wait until the end for PCF input (see comment below)
|
2017-04-03 15:27:53 +00:00
|
|
|
|
makeVariableInOut(*(*it));
|
2017-01-19 22:41:47 +00:00
|
|
|
|
for (auto it = outputs.begin(); it != outputs.end(); ++it)
|
|
|
|
|
makeVariableInOut(*(*it));
|
|
|
|
|
|
2017-04-03 15:27:53 +00:00
|
|
|
|
// In the domain shader, PCF input must be at the end of the linkage. That's because in the
|
|
|
|
|
// hull shader there is no ordering: the output comes from the separate PCF, which does not
|
|
|
|
|
// participate in the argument list. That is always put at the end of the HS linkage, so the
|
|
|
|
|
// input side of the DS must match. The argument may be in any position in the DS argument list
|
|
|
|
|
// however, so this ensures the linkage is built in the correct order regardless of argument order.
|
|
|
|
|
if (language == EShLangTessEvaluation) {
|
|
|
|
|
for (auto it = inputs.begin(); it != inputs.end(); ++it)
|
2017-08-04 18:04:44 +00:00
|
|
|
|
if (isDsPcfInput((*it)->getType()))
|
2017-04-03 15:27:53 +00:00
|
|
|
|
makeVariableInOut(*(*it));
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-19 22:41:47 +00:00
|
|
|
|
// Synthesize the call
|
|
|
|
|
|
|
|
|
|
pushScope(); // matches the one in handleFunctionBody()
|
|
|
|
|
|
|
|
|
|
// new signature
|
|
|
|
|
TType voidType(EbtVoid);
|
|
|
|
|
TFunction synthEntryPoint(&userFunction.getName(), voidType);
|
|
|
|
|
TIntermAggregate* synthParams = new TIntermAggregate();
|
|
|
|
|
intermediate.setAggregateOperator(synthParams, EOpParameters, voidType, loc);
|
|
|
|
|
intermediate.setEntryPointMangledName(synthEntryPoint.getMangledName().c_str());
|
|
|
|
|
intermediate.incrementEntryPointCount();
|
|
|
|
|
TFunction callee(&userFunction.getName(), voidType); // call based on old name, which is still in the symbol table
|
|
|
|
|
|
|
|
|
|
// change original name
|
|
|
|
|
userFunction.addPrefix("@"); // change the name in the function, but not in the symbol table
|
|
|
|
|
|
|
|
|
|
// Copy inputs (shader-in -> calling arg), while building up the call node
|
|
|
|
|
TVector<TVariable*> argVars;
|
|
|
|
|
TIntermAggregate* synthBody = new TIntermAggregate();
|
|
|
|
|
auto inputIt = inputs.begin();
|
|
|
|
|
TIntermTyped* callingArgs = nullptr;
|
2017-03-30 02:01:13 +00:00
|
|
|
|
|
2017-01-19 22:41:47 +00:00
|
|
|
|
for (int i = 0; i < userFunction.getParamCount(); i++) {
|
|
|
|
|
TParameter& param = userFunction[i];
|
|
|
|
|
argVars.push_back(makeInternalVariable(*param.name, *param.type));
|
|
|
|
|
argVars.back()->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
TIntermSymbol* arg = intermediate.addSymbol(*argVars.back());
|
|
|
|
|
handleFunctionArgument(&callee, callingArgs, arg);
|
|
|
|
|
if (param.type->getQualifier().isParamInput()) {
|
|
|
|
|
intermediate.growAggregate(synthBody, handleAssign(loc, EOpAssign, arg,
|
|
|
|
|
intermediate.addSymbol(**inputIt)));
|
|
|
|
|
inputIt++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call
|
|
|
|
|
currentCaller = synthEntryPoint.getMangledName();
|
|
|
|
|
TIntermTyped* callReturn = handleFunctionCall(loc, &callee, callingArgs);
|
|
|
|
|
currentCaller = userFunction.getMangledName();
|
|
|
|
|
|
|
|
|
|
// Return value
|
2017-03-23 00:39:25 +00:00
|
|
|
|
if (entryPointOutput) {
|
|
|
|
|
TIntermTyped* returnAssign;
|
|
|
|
|
|
2017-03-23 17:56:07 +00:00
|
|
|
|
// For hull shaders, the wrapped entry point return value is written to
|
|
|
|
|
// an array element as indexed by invocation ID, which we might have to make up.
|
|
|
|
|
// This is required to match SPIR-V semantics.
|
2017-03-23 00:39:25 +00:00
|
|
|
|
if (language == EShLangTessControl) {
|
2017-08-04 19:51:54 +00:00
|
|
|
|
TIntermSymbol* invocationIdSym = findTessLinkageSymbol(EbvInvocationId);
|
2017-03-23 00:39:25 +00:00
|
|
|
|
|
|
|
|
|
// If there is no user declared invocation ID, we must make one.
|
|
|
|
|
if (invocationIdSym == nullptr) {
|
|
|
|
|
TType invocationIdType(EbtUint, EvqIn, 1);
|
|
|
|
|
TString* invocationIdName = NewPoolTString("InvocationId");
|
|
|
|
|
invocationIdType.getQualifier().builtIn = EbvInvocationId;
|
|
|
|
|
|
|
|
|
|
TVariable* variable = makeInternalVariable(*invocationIdName, invocationIdType);
|
|
|
|
|
|
|
|
|
|
globalQualifierFix(loc, variable->getWritableType().getQualifier());
|
|
|
|
|
trackLinkage(*variable);
|
|
|
|
|
|
|
|
|
|
invocationIdSym = intermediate.addSymbol(*variable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermTyped* element = intermediate.addIndex(EOpIndexIndirect, intermediate.addSymbol(*entryPointOutput),
|
|
|
|
|
invocationIdSym, loc);
|
|
|
|
|
element->setType(callReturn->getType());
|
|
|
|
|
|
|
|
|
|
returnAssign = handleAssign(loc, EOpAssign, element, callReturn);
|
|
|
|
|
} else {
|
|
|
|
|
returnAssign = handleAssign(loc, EOpAssign, intermediate.addSymbol(*entryPointOutput), callReturn);
|
|
|
|
|
}
|
|
|
|
|
intermediate.growAggregate(synthBody, returnAssign);
|
|
|
|
|
} else
|
2017-01-19 22:41:47 +00:00
|
|
|
|
intermediate.growAggregate(synthBody, callReturn);
|
|
|
|
|
|
|
|
|
|
// Output copies
|
|
|
|
|
auto outputIt = outputs.begin();
|
|
|
|
|
for (int i = 0; i < userFunction.getParamCount(); i++) {
|
|
|
|
|
TParameter& param = userFunction[i];
|
2017-03-30 02:01:13 +00:00
|
|
|
|
|
|
|
|
|
// GS outputs are via emit, so we do not copy them here.
|
2017-01-19 22:41:47 +00:00
|
|
|
|
if (param.type->getQualifier().isParamOutput()) {
|
2017-04-24 01:44:28 +00:00
|
|
|
|
if (param.getDeclaredBuiltIn() == EbvGsOutputStream) {
|
2017-03-30 02:01:13 +00:00
|
|
|
|
// GS output stream does not assign outputs here: it's the Append() method
|
|
|
|
|
// which writes to the output, probably multiple times separated by Emit.
|
|
|
|
|
// We merely remember the output to use, here.
|
|
|
|
|
gsStreamOutput = *outputIt;
|
|
|
|
|
} else {
|
|
|
|
|
intermediate.growAggregate(synthBody, handleAssign(loc, EOpAssign,
|
|
|
|
|
intermediate.addSymbol(**outputIt),
|
|
|
|
|
intermediate.addSymbol(*argVars[i])));
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-19 22:41:47 +00:00
|
|
|
|
outputIt++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Put the pieces together to form a full function subtree
|
|
|
|
|
// for the synthesized entry point.
|
|
|
|
|
synthBody->setOperator(EOpSequence);
|
|
|
|
|
TIntermNode* synthFunctionDef = synthParams;
|
|
|
|
|
handleFunctionBody(loc, synthEntryPoint, synthBody, synthFunctionDef);
|
|
|
|
|
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
entryPointFunctionBody = synthBody;
|
|
|
|
|
|
2017-01-19 22:41:47 +00:00
|
|
|
|
return synthFunctionDef;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-28 22:20:13 +00:00
|
|
|
|
void HlslParseContext::handleFunctionBody(const TSourceLoc& loc, TFunction& function, TIntermNode* functionBody,
|
|
|
|
|
TIntermNode*& node)
|
2016-09-03 01:13:36 +00:00
|
|
|
|
{
|
|
|
|
|
node = intermediate.growAggregate(node, functionBody);
|
|
|
|
|
intermediate.setAggregateOperator(node, EOpFunction, function.getType(), loc);
|
|
|
|
|
node->getAsAggregate()->setName(function.getMangledName().c_str());
|
|
|
|
|
|
|
|
|
|
popScope();
|
2017-03-22 05:56:40 +00:00
|
|
|
|
if (function.hasImplicitThis())
|
|
|
|
|
popImplicitThis();
|
2016-09-03 01:13:36 +00:00
|
|
|
|
|
|
|
|
|
if (function.getType().getBasicType() != EbtVoid && ! functionReturnsValue)
|
|
|
|
|
error(loc, "function does not return a value:", "", function.getName().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-30 00:10:47 +00:00
|
|
|
|
// AST I/O is done through shader globals declared in the 'in' or 'out'
|
|
|
|
|
// storage class. An HLSL entry point has a return value, input parameters
|
|
|
|
|
// and output parameters. These need to get remapped to the AST I/O.
|
2017-02-04 00:57:55 +00:00
|
|
|
|
void HlslParseContext::remapEntryPointIO(TFunction& function, TVariable*& returnValue,
|
2017-01-19 22:41:47 +00:00
|
|
|
|
TVector<TVariable*>& inputs, TVector<TVariable*>& outputs)
|
2016-08-30 00:10:47 +00:00
|
|
|
|
{
|
2017-06-21 07:35:57 +00:00
|
|
|
|
// We might have in input structure type with no decorations that caused it
|
|
|
|
|
// to look like an input type, yet it has (e.g.) interpolation types that
|
|
|
|
|
// must be modified that turn it into an input type.
|
|
|
|
|
// Hence, a missing ioTypeMap for 'input' might need to be synthesized.
|
|
|
|
|
const auto synthesizeEditedInput = [this](TType& type) {
|
|
|
|
|
// True if a type needs to be 'flat'
|
|
|
|
|
const auto needsFlat = [](const TType& type) {
|
|
|
|
|
return type.containsBasicType(EbtInt) ||
|
|
|
|
|
type.containsBasicType(EbtUint) ||
|
|
|
|
|
type.containsBasicType(EbtInt64) ||
|
|
|
|
|
type.containsBasicType(EbtUint64) ||
|
|
|
|
|
type.containsBasicType(EbtBool) ||
|
|
|
|
|
type.containsBasicType(EbtDouble);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (language == EShLangFragment && needsFlat(type)) {
|
|
|
|
|
if (type.isStruct()) {
|
|
|
|
|
TTypeList* finalList = nullptr;
|
|
|
|
|
auto it = ioTypeMap.find(type.getStruct());
|
|
|
|
|
if (it == ioTypeMap.end() || it->second.input == nullptr) {
|
|
|
|
|
// Getting here means we have no input struct, but we need one.
|
|
|
|
|
auto list = new TTypeList;
|
|
|
|
|
for (auto member = type.getStruct()->begin(); member != type.getStruct()->end(); ++member) {
|
|
|
|
|
TType* newType = new TType;
|
|
|
|
|
newType->shallowCopy(*member->type);
|
|
|
|
|
TTypeLoc typeLoc = { newType, member->loc };
|
|
|
|
|
list->push_back(typeLoc);
|
|
|
|
|
}
|
|
|
|
|
// install the new input type
|
|
|
|
|
if (it == ioTypeMap.end()) {
|
|
|
|
|
tIoKinds newLists = { list, nullptr, nullptr };
|
|
|
|
|
ioTypeMap[type.getStruct()] = newLists;
|
|
|
|
|
} else
|
|
|
|
|
it->second.input = list;
|
|
|
|
|
finalList = list;
|
|
|
|
|
} else
|
|
|
|
|
finalList = it->second.input;
|
|
|
|
|
// edit for 'flat'
|
|
|
|
|
for (auto member = finalList->begin(); member != finalList->end(); ++member) {
|
|
|
|
|
if (needsFlat(*member->type)) {
|
|
|
|
|
member->type->getQualifier().clearInterpolation();
|
|
|
|
|
member->type->getQualifier().flat = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
type.getQualifier().clearInterpolation();
|
|
|
|
|
type.getQualifier().flat = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-02-06 03:27:30 +00:00
|
|
|
|
// Do the actual work to make a type be a shader input or output variable,
|
|
|
|
|
// and clear the original to be non-IO (for use as a normal function parameter/return).
|
2017-03-09 17:48:59 +00:00
|
|
|
|
const auto makeIoVariable = [this](const char* name, TType& type, TStorageQualifier storage) -> TVariable* {
|
2017-02-04 00:57:55 +00:00
|
|
|
|
TVariable* ioVariable = makeInternalVariable(name, type);
|
2017-02-06 03:27:30 +00:00
|
|
|
|
clearUniformInputOutput(type.getQualifier());
|
2017-06-21 07:35:57 +00:00
|
|
|
|
if (type.isStruct()) {
|
2017-02-06 03:27:30 +00:00
|
|
|
|
auto newLists = ioTypeMap.find(ioVariable->getType().getStruct());
|
|
|
|
|
if (newLists != ioTypeMap.end()) {
|
|
|
|
|
if (storage == EvqVaryingIn && newLists->second.input)
|
|
|
|
|
ioVariable->getWritableType().setStruct(newLists->second.input);
|
|
|
|
|
else if (storage == EvqVaryingOut && newLists->second.output)
|
|
|
|
|
ioVariable->getWritableType().setStruct(newLists->second.output);
|
|
|
|
|
}
|
2016-09-03 02:05:19 +00:00
|
|
|
|
}
|
2017-03-19 04:24:14 +00:00
|
|
|
|
if (storage == EvqVaryingIn) {
|
2017-02-06 03:27:30 +00:00
|
|
|
|
correctInput(ioVariable->getWritableType().getQualifier());
|
2017-03-19 04:24:14 +00:00
|
|
|
|
if (language == EShLangTessEvaluation)
|
|
|
|
|
if (!ioVariable->getType().isArray())
|
|
|
|
|
ioVariable->getWritableType().getQualifier().patch = true;
|
|
|
|
|
} else {
|
2017-02-06 03:27:30 +00:00
|
|
|
|
correctOutput(ioVariable->getWritableType().getQualifier());
|
2017-03-19 04:24:14 +00:00
|
|
|
|
}
|
2017-02-06 03:27:30 +00:00
|
|
|
|
ioVariable->getWritableType().getQualifier().storage = storage;
|
2017-04-01 21:34:48 +00:00
|
|
|
|
|
2017-04-05 17:03:02 +00:00
|
|
|
|
fixBuiltInIoType(ioVariable->getWritableType());
|
|
|
|
|
|
2017-02-04 00:57:55 +00:00
|
|
|
|
return ioVariable;
|
2016-09-03 02:05:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-30 00:10:47 +00:00
|
|
|
|
// return value is actually a shader-scoped output (out)
|
2017-03-23 00:39:25 +00:00
|
|
|
|
if (function.getType().getBasicType() == EbtVoid) {
|
2017-01-19 22:41:47 +00:00
|
|
|
|
returnValue = nullptr;
|
2017-03-23 00:39:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (language == EShLangTessControl) {
|
|
|
|
|
// tessellation evaluation in HLSL writes a per-ctrl-pt value, but it needs to be an
|
|
|
|
|
// array in SPIR-V semantics. We'll write to it indexed by invocation ID.
|
|
|
|
|
|
|
|
|
|
returnValue = makeIoVariable("@entryPointOutput", function.getWritableType(), EvqVaryingOut);
|
|
|
|
|
|
|
|
|
|
TType outputType;
|
|
|
|
|
outputType.shallowCopy(function.getType());
|
|
|
|
|
|
|
|
|
|
// vertices has necessarily already been set when handling entry point attributes.
|
|
|
|
|
TArraySizes arraySizes;
|
|
|
|
|
arraySizes.addInnerSize(intermediate.getVertices());
|
|
|
|
|
outputType.newArraySizes(arraySizes);
|
|
|
|
|
|
|
|
|
|
clearUniformInputOutput(function.getWritableType().getQualifier());
|
|
|
|
|
returnValue = makeIoVariable("@entryPointOutput", outputType, EvqVaryingOut);
|
|
|
|
|
} else {
|
|
|
|
|
returnValue = makeIoVariable("@entryPointOutput", function.getWritableType(), EvqVaryingOut);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-30 00:10:47 +00:00
|
|
|
|
|
|
|
|
|
// parameters are actually shader-scoped inputs and outputs (in or out)
|
|
|
|
|
for (int i = 0; i < function.getParamCount(); i++) {
|
2016-09-09 22:32:09 +00:00
|
|
|
|
TType& paramType = *function[i].type;
|
2017-01-19 22:41:47 +00:00
|
|
|
|
if (paramType.getQualifier().isParamInput()) {
|
2017-06-21 07:35:57 +00:00
|
|
|
|
synthesizeEditedInput(paramType);
|
2017-02-06 03:27:30 +00:00
|
|
|
|
TVariable* argAsGlobal = makeIoVariable(function[i].name->c_str(), paramType, EvqVaryingIn);
|
2017-01-19 22:41:47 +00:00
|
|
|
|
inputs.push_back(argAsGlobal);
|
2017-04-01 21:34:48 +00:00
|
|
|
|
|
2017-04-24 01:44:28 +00:00
|
|
|
|
if (function[i].getDeclaredBuiltIn() == EbvInputPatch)
|
2017-04-01 21:34:48 +00:00
|
|
|
|
inputPatch = argAsGlobal;
|
2017-01-19 22:41:47 +00:00
|
|
|
|
}
|
|
|
|
|
if (paramType.getQualifier().isParamOutput()) {
|
2017-02-06 03:27:30 +00:00
|
|
|
|
TVariable* argAsGlobal = makeIoVariable(function[i].name->c_str(), paramType, EvqVaryingOut);
|
2017-01-19 22:41:47 +00:00
|
|
|
|
outputs.push_back(argAsGlobal);
|
|
|
|
|
}
|
2016-08-30 00:10:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-03 02:23:27 +00:00
|
|
|
|
// An HLSL function that looks like an entry point, but is not,
|
|
|
|
|
// declares entry point IO built-ins, but these have to be undone.
|
2016-09-19 22:01:41 +00:00
|
|
|
|
void HlslParseContext::remapNonEntryPointIO(TFunction& function)
|
2016-09-03 02:23:27 +00:00
|
|
|
|
{
|
|
|
|
|
// return value
|
|
|
|
|
if (function.getType().getBasicType() != EbtVoid)
|
2017-02-06 03:27:30 +00:00
|
|
|
|
clearUniformInputOutput(function.getWritableType().getQualifier());
|
2016-09-03 02:23:27 +00:00
|
|
|
|
|
2017-02-24 01:04:12 +00:00
|
|
|
|
// parameters.
|
|
|
|
|
// References to structuredbuffer types are left unmodified
|
2016-09-03 02:23:27 +00:00
|
|
|
|
for (int i = 0; i < function.getParamCount(); i++)
|
2017-02-24 01:04:12 +00:00
|
|
|
|
if (!isReference(*function[i].type))
|
|
|
|
|
clearUniformInputOutput(function[i].type->getQualifier());
|
2016-09-03 02:23:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-09 17:28:03 +00:00
|
|
|
|
// Handle function returns, including type conversions to the function return type
|
|
|
|
|
// if necessary.
|
|
|
|
|
TIntermNode* HlslParseContext::handleReturnValue(const TSourceLoc& loc, TIntermTyped* value)
|
|
|
|
|
{
|
2016-09-03 01:13:36 +00:00
|
|
|
|
functionReturnsValue = true;
|
2016-08-28 21:00:23 +00:00
|
|
|
|
|
2016-08-09 17:28:03 +00:00
|
|
|
|
if (currentFunctionType->getBasicType() == EbtVoid) {
|
|
|
|
|
error(loc, "void function cannot return a value", "return", "");
|
|
|
|
|
return intermediate.addBranch(EOpReturn, loc);
|
|
|
|
|
} else if (*currentFunctionType != value->getType()) {
|
2016-10-06 22:56:54 +00:00
|
|
|
|
value = intermediate.addConversion(EOpReturn, *currentFunctionType, value);
|
|
|
|
|
if (value && *currentFunctionType != value->getType())
|
2017-04-19 03:07:05 +00:00
|
|
|
|
value = intermediate.addUniShapeConversion(EOpReturn, *currentFunctionType, value);
|
2016-10-06 22:56:54 +00:00
|
|
|
|
if (value == nullptr) {
|
2016-08-09 17:28:03 +00:00
|
|
|
|
error(loc, "type does not match, or is not convertible to, the function's return type", "return", "");
|
2016-10-06 22:56:54 +00:00
|
|
|
|
return value;
|
2016-08-09 17:28:03 +00:00
|
|
|
|
}
|
2016-08-28 21:00:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-19 22:41:47 +00:00
|
|
|
|
return intermediate.addBranch(EOpReturn, value, loc);
|
2016-08-09 17:28:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
void HlslParseContext::handleFunctionArgument(TFunction* function,
|
|
|
|
|
TIntermTyped*& arguments, TIntermTyped* newArg)
|
2016-03-13 17:24:20 +00:00
|
|
|
|
{
|
2016-12-24 01:56:57 +00:00
|
|
|
|
TParameter param = { 0, new TType, nullptr };
|
2016-05-13 15:33:42 +00:00
|
|
|
|
param.type->shallowCopy(newArg->getType());
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
|
2016-03-13 17:24:20 +00:00
|
|
|
|
function->addParameter(param);
|
2016-05-13 15:33:42 +00:00
|
|
|
|
if (arguments)
|
|
|
|
|
arguments = intermediate.growAggregate(arguments, newArg);
|
|
|
|
|
else
|
|
|
|
|
arguments = newArg;
|
2016-03-13 17:24:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-22 18:08:00 +00:00
|
|
|
|
// Clip and cull distance require special handling due to a semantic mismatch. In HLSL,
|
|
|
|
|
// these can be float scalar, float vector, or arrays of float scalar or float vector.
|
|
|
|
|
// In SPIR-V, they are arrays of scalar floats in all cases. We must copy individual components
|
|
|
|
|
// (e.g, both x and y components of a float2) out into the destination float array.
|
|
|
|
|
//
|
|
|
|
|
// The values are assigned to sequential members of the output array. The inner dimension
|
|
|
|
|
// is vector components. The outer dimension is array elements.
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
TIntermAggregate* HlslParseContext::assignClipCullDistance(const TSourceLoc& loc, TOperator op, int semanticId,
|
2017-06-22 18:08:00 +00:00
|
|
|
|
TIntermTyped* left, TIntermTyped* right)
|
|
|
|
|
{
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
TVariable** clipCullVar = nullptr;
|
2017-06-22 18:08:00 +00:00
|
|
|
|
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
const TBuiltInVariable builtInType = left->getQualifier().builtIn;
|
2017-06-22 18:08:00 +00:00
|
|
|
|
|
|
|
|
|
// array sizes, or 1 if it's not an array:
|
|
|
|
|
const int rhsArraySize = (right->getType().isArray() ? right->getType().getOuterArraySize() : 1);
|
|
|
|
|
// vector sizes:
|
|
|
|
|
const int rhsVectorSize = right->getType().getVectorSize();
|
|
|
|
|
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
decltype(clipSemanticNSize)* semanticNSize = nullptr;
|
|
|
|
|
|
|
|
|
|
// Refer to either the clip or the cull distance, depending on semantic.
|
|
|
|
|
switch (builtInType) {
|
|
|
|
|
case EbvClipDistance:
|
|
|
|
|
clipCullVar = &clipDistanceOutput;
|
|
|
|
|
semanticNSize = &clipSemanticNSize;
|
|
|
|
|
break;
|
|
|
|
|
case EbvCullDistance:
|
|
|
|
|
clipCullVar = &cullDistanceOutput;
|
|
|
|
|
semanticNSize = &cullSemanticNSize;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// called invalidly: we expected a clip or a cull distance.
|
|
|
|
|
// static compile time problem: should not happen.
|
|
|
|
|
default: assert(0); return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is the offset in the destination array of a given semantic's data
|
|
|
|
|
std::array<int, maxClipCullRegs> semanticOffset;
|
|
|
|
|
|
|
|
|
|
// Calculate offset of variable of semantic N in destination array
|
|
|
|
|
int arrayLoc = 0;
|
|
|
|
|
int vecItems = 0;
|
|
|
|
|
|
|
|
|
|
for (int x = 0; x < maxClipCullRegs; ++x) {
|
|
|
|
|
// See if we overflowed the vec4 packing
|
|
|
|
|
if ((vecItems + (*semanticNSize)[x]) > 4) {
|
|
|
|
|
arrayLoc = (arrayLoc + 3) & (~0x3); // round up to next multiple of 4
|
|
|
|
|
vecItems = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
semanticOffset[x] = arrayLoc;
|
|
|
|
|
vecItems += (*semanticNSize)[x];
|
|
|
|
|
arrayLoc += (*semanticNSize)[x];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-07-28 22:20:13 +00:00
|
|
|
|
// If we haven't created the output already, create it now.
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
if (*clipCullVar == nullptr) {
|
|
|
|
|
// ClipDistance and CullDistance are handled specially in the entry point output
|
|
|
|
|
// copy algorithm, because they may need to be unpacked from components of vectors
|
|
|
|
|
// (or a scalar) into a float array. Here, we make the array the right size and type,
|
|
|
|
|
// which depends on the incoming data, which has several potential dimensions:
|
|
|
|
|
// Semantic ID
|
|
|
|
|
// vector size
|
|
|
|
|
// array size
|
|
|
|
|
// Of those, semantic ID and array size cannot appear simultaneously.
|
|
|
|
|
|
|
|
|
|
const int requiredArraySize = arrayLoc * rhsArraySize;
|
|
|
|
|
|
|
|
|
|
TType clipCullType(EbtFloat, left->getType().getQualifier().storage, 1);
|
|
|
|
|
clipCullType.getQualifier() = left->getType().getQualifier();
|
|
|
|
|
|
|
|
|
|
// Create required array dimension
|
|
|
|
|
TArraySizes arraySizes;
|
|
|
|
|
arraySizes.addInnerSize(requiredArraySize);
|
|
|
|
|
clipCullType.newArraySizes(arraySizes);
|
|
|
|
|
|
|
|
|
|
// Obtain symbol name: we'll use that for the symbol we introduce.
|
|
|
|
|
TIntermSymbol* sym = left->getAsSymbolNode();
|
|
|
|
|
assert(sym != nullptr);
|
|
|
|
|
|
|
|
|
|
// We are moving the semantic ID from the layout location, so it is no longer needed or
|
|
|
|
|
// desired there.
|
|
|
|
|
clipCullType.getQualifier().layoutLocation = TQualifier::layoutLocationEnd;
|
|
|
|
|
|
|
|
|
|
// Create variable and track its linkage
|
|
|
|
|
*clipCullVar = makeInternalVariable(sym->getName().c_str(), clipCullType);
|
|
|
|
|
|
|
|
|
|
trackLinkage(**clipCullVar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create symbol for the clip or cull variable.
|
|
|
|
|
left = intermediate.addSymbol(**clipCullVar);
|
|
|
|
|
|
|
|
|
|
// array sizes, or 1 if it's not an array:
|
|
|
|
|
const int lhsArraySize = (left->getType().isArray() ? left->getType().getOuterArraySize() : 1);
|
|
|
|
|
// vector sizes:
|
|
|
|
|
const int lhsVectorSize = left->getType().getVectorSize();
|
|
|
|
|
|
|
|
|
|
// left has got to be an array of scalar floats, per SPIR-V semantics.
|
|
|
|
|
// fixBuiltInIoType() should have handled that upstream.
|
|
|
|
|
assert(left->getType().isArray());
|
|
|
|
|
assert(left->getType().getVectorSize() == 1);
|
|
|
|
|
assert(left->getType().getBasicType() == EbtFloat);
|
|
|
|
|
|
2017-06-22 18:08:00 +00:00
|
|
|
|
// We may be creating multiple sub-assignments. This is an aggregate to hold them.
|
|
|
|
|
// TODO: it would be possible to be clever sometimes and avoid the sequence node if not needed.
|
|
|
|
|
TIntermAggregate* assignList = nullptr;
|
|
|
|
|
|
|
|
|
|
// If the types are homomorphic, use a simple assign. No need to mess about with
|
|
|
|
|
// individual components.
|
|
|
|
|
if (left->getType().isArray() == right->getType().isArray() &&
|
|
|
|
|
lhsArraySize == rhsArraySize &&
|
|
|
|
|
lhsVectorSize == rhsVectorSize) {
|
|
|
|
|
assignList = intermediate.growAggregate(assignList, intermediate.addAssign(op, left, right, loc));
|
|
|
|
|
assignList->setOperator(EOpSequence);
|
|
|
|
|
return assignList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We are going to copy each component of the right (per array element if indicated) to sequential
|
|
|
|
|
// array elements of the left. This tracks the lhs element we're writing to as we go along.
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
// We may be starting in the middle - e.g, for a non-zero semantic ID calculated above.
|
|
|
|
|
int lhsArrayPos = semanticOffset[semanticId];
|
2017-06-22 18:08:00 +00:00
|
|
|
|
|
|
|
|
|
// Loop through every component of every element of the RHS, and copy to LHS elements in turn.
|
|
|
|
|
for (int rhsArrayPos = 0; rhsArrayPos < rhsArraySize; ++rhsArrayPos) {
|
|
|
|
|
for (int rhsComponent = 0; rhsComponent < rhsVectorSize; ++rhsComponent) {
|
|
|
|
|
// LHS array member to write to:
|
|
|
|
|
TIntermTyped* lhsMember = intermediate.addIndex(EOpIndexDirect, left,
|
|
|
|
|
intermediate.addConstantUnion(lhsArrayPos++, loc), loc);
|
|
|
|
|
|
|
|
|
|
TIntermTyped* rhsMember = right;
|
|
|
|
|
|
|
|
|
|
// If right is an array, extract the element of interest
|
|
|
|
|
if (right->getType().isArray()) {
|
|
|
|
|
const TType derefType(rhsMember->getType(), 0);
|
|
|
|
|
rhsMember = intermediate.addIndex(EOpIndexDirect, rhsMember,
|
|
|
|
|
intermediate.addConstantUnion(rhsArrayPos, loc), loc);
|
|
|
|
|
rhsMember->setType(derefType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If right is a vector, extract the component of interest.
|
|
|
|
|
if (right->getType().isVector()) {
|
|
|
|
|
const TType derefType(rhsMember->getType(), 0);
|
|
|
|
|
rhsMember = intermediate.addIndex(EOpIndexDirect, rhsMember,
|
|
|
|
|
intermediate.addConstantUnion(rhsComponent, loc), loc);
|
|
|
|
|
rhsMember->setType(derefType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Assign: to the proper lhs member.
|
|
|
|
|
assignList = intermediate.growAggregate(assignList,
|
|
|
|
|
intermediate.addAssign(op, lhsMember, rhsMember, loc));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(assignList != nullptr);
|
|
|
|
|
assignList->setOperator(EOpSequence);
|
|
|
|
|
|
|
|
|
|
return assignList;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-16 11:46:13 +00:00
|
|
|
|
// For a declaration with an initializer, where the initialized symbol is flattened,
|
|
|
|
|
// and possibly contains opaque values, such that the initializer should never exist
|
|
|
|
|
// as emitted code, because even creating the initializer would write opaques.
|
|
|
|
|
//
|
|
|
|
|
// Decompose this into individual member-wise assignments, which themselves are
|
|
|
|
|
// expected to then not exist for opaque types, because they will turn into aliases.
|
|
|
|
|
//
|
|
|
|
|
// Return a node that contains the non-aliased assignments that must continue to exist.
|
2017-07-30 22:54:02 +00:00
|
|
|
|
TIntermAggregate* HlslParseContext::executeFlattenedInitializer(const TSourceLoc& loc, TIntermSymbol* symbol,
|
|
|
|
|
const TIntermAggregate& initializer)
|
2017-07-16 11:46:13 +00:00
|
|
|
|
{
|
|
|
|
|
TIntermAggregate* initList = nullptr;
|
|
|
|
|
// synthesize an access to each member, and then an assignment to it
|
|
|
|
|
const TTypeList& typeList = *symbol->getType().getStruct();
|
|
|
|
|
for (int member = 0; member < (int)typeList.size(); ++member) {
|
|
|
|
|
TIntermTyped* memberInitializer = initializer.getSequence()[member]->getAsTyped();
|
|
|
|
|
TIntermTyped* flattenedMember = flattenAccess(symbol, member);
|
|
|
|
|
if (flattenedMember->getType().containsOpaque())
|
|
|
|
|
setOpaqueLvalue(flattenedMember, memberInitializer);
|
|
|
|
|
else
|
|
|
|
|
initList = intermediate.growAggregate(initList, handleAssign(loc, EOpAssign, flattenedMember,
|
|
|
|
|
memberInitializer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (initList)
|
|
|
|
|
initList->setOperator(EOpSequence);
|
|
|
|
|
return initList;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 09:05:12 +00:00
|
|
|
|
// Some simple source assignments need to be flattened to a sequence
|
2017-01-13 19:27:52 +00:00
|
|
|
|
// of AST assignments. Catch these and flatten, otherwise, pass through
|
2016-09-16 09:05:12 +00:00
|
|
|
|
// to intermediate.addAssign().
|
2017-01-13 19:27:52 +00:00
|
|
|
|
//
|
|
|
|
|
// Also, assignment to matrix swizzles requires multiple component assignments,
|
|
|
|
|
// intercept those as well.
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::handleAssign(const TSourceLoc& loc, TOperator op, TIntermTyped* left,
|
|
|
|
|
TIntermTyped* right)
|
2016-09-16 09:05:12 +00:00
|
|
|
|
{
|
2016-10-08 01:35:40 +00:00
|
|
|
|
if (left == nullptr || right == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
2017-01-13 19:27:52 +00:00
|
|
|
|
if (left->getAsOperator() && left->getAsOperator()->getOp() == EOpMatrixSwizzle)
|
|
|
|
|
return handleAssignToMatrixSwizzle(loc, op, left, right);
|
|
|
|
|
|
2016-12-19 22:48:01 +00:00
|
|
|
|
const bool isSplitLeft = wasSplit(left);
|
|
|
|
|
const bool isSplitRight = wasSplit(right);
|
2016-09-17 01:44:00 +00:00
|
|
|
|
|
2016-12-19 22:48:01 +00:00
|
|
|
|
const bool isFlattenLeft = wasFlattened(left);
|
|
|
|
|
const bool isFlattenRight = wasFlattened(right);
|
2016-09-17 01:44:00 +00:00
|
|
|
|
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
// OK to do a single assign if both are split, or both are unsplit. But if one is and the other
|
2017-01-13 19:27:52 +00:00
|
|
|
|
// isn't, we fall back to a member-wise copy.
|
2017-07-31 05:39:48 +00:00
|
|
|
|
if (!isFlattenLeft && !isFlattenRight && !isSplitLeft && !isSplitRight) {
|
2017-06-22 18:08:00 +00:00
|
|
|
|
// Clip and cull distance requires more processing. See comment above assignClipCullDistance.
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
if (isClipOrCullDistance(left->getType())) {
|
|
|
|
|
const int semanticId = left->getType().getQualifier().layoutLocation;
|
|
|
|
|
return assignClipCullDistance(loc, op, semanticId, left, right);
|
|
|
|
|
}
|
2017-06-22 18:08:00 +00:00
|
|
|
|
|
2016-09-16 09:05:12 +00:00
|
|
|
|
return intermediate.addAssign(op, left, right, loc);
|
2017-06-22 18:08:00 +00:00
|
|
|
|
}
|
2016-09-16 09:05:12 +00:00
|
|
|
|
|
2016-09-16 19:26:37 +00:00
|
|
|
|
TIntermAggregate* assignList = nullptr;
|
|
|
|
|
const TVector<TVariable*>* leftVariables = nullptr;
|
|
|
|
|
const TVector<TVariable*>* rightVariables = nullptr;
|
|
|
|
|
|
2016-10-03 04:13:22 +00:00
|
|
|
|
// A temporary to store the right node's value, so we don't keep indirecting into it
|
|
|
|
|
// if it's not a simple symbol.
|
2017-07-16 11:46:13 +00:00
|
|
|
|
TVariable* rhsTempVar = nullptr;
|
2016-10-03 04:13:22 +00:00
|
|
|
|
|
|
|
|
|
// If the RHS is a simple symbol node, we'll copy it for each member.
|
|
|
|
|
TIntermSymbol* cloneSymNode = nullptr;
|
|
|
|
|
|
|
|
|
|
int memberCount = 0;
|
|
|
|
|
|
|
|
|
|
// Track how many items there are to copy.
|
|
|
|
|
if (left->getType().isStruct())
|
2016-10-09 01:07:20 +00:00
|
|
|
|
memberCount = (int)left->getType().getStruct()->size();
|
2016-10-03 04:13:22 +00:00
|
|
|
|
if (left->getType().isArray())
|
|
|
|
|
memberCount = left->getType().getCumulativeArraySize();
|
|
|
|
|
|
2016-12-19 22:48:01 +00:00
|
|
|
|
if (isFlattenLeft)
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
leftVariables = &flattenMap.find(left->getAsSymbolNode()->getId())->second.members;
|
2016-10-03 04:13:22 +00:00
|
|
|
|
|
2016-12-19 22:48:01 +00:00
|
|
|
|
if (isFlattenRight) {
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
rightVariables = &flattenMap.find(right->getAsSymbolNode()->getId())->second.members;
|
2016-10-03 04:13:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
// The RHS is not flattened. There are several cases:
|
|
|
|
|
// 1. 1 item to copy: Use the RHS directly.
|
|
|
|
|
// 2. >1 item, simple symbol RHS: we'll create a new TIntermSymbol node for each, but no assign to temp.
|
|
|
|
|
// 3. >1 item, complex RHS: assign it to a new temp variable, and create a TIntermSymbol for each member.
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-10-03 04:13:22 +00:00
|
|
|
|
if (memberCount <= 1) {
|
|
|
|
|
// case 1: we'll use the symbol directly below. Nothing to do.
|
|
|
|
|
} else {
|
|
|
|
|
if (right->getAsSymbolNode() != nullptr) {
|
|
|
|
|
// case 2: we'll copy the symbol per iteration below.
|
|
|
|
|
cloneSymNode = right->getAsSymbolNode();
|
|
|
|
|
} else {
|
|
|
|
|
// case 3: assign to a temp, and indirect into that.
|
|
|
|
|
rhsTempVar = makeInternalVariable("flattenTemp", right->getType());
|
|
|
|
|
rhsTempVar->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
TIntermTyped* noFlattenRHS = intermediate.addSymbol(*rhsTempVar, loc);
|
|
|
|
|
|
|
|
|
|
// Add this to the aggregate being built.
|
2017-06-30 00:23:31 +00:00
|
|
|
|
assignList = intermediate.growAggregate(assignList,
|
|
|
|
|
intermediate.addAssign(op, noFlattenRHS, right, loc), loc);
|
2016-10-03 04:13:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-16 19:26:37 +00:00
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
int memberIdx = 0;
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// When dealing with split arrayed structures of built-ins, the arrayness is moved to the extracted built-in
|
2017-02-02 23:32:02 +00:00
|
|
|
|
// variables, which is awkward when copying between split and unsplit structures. This variable tracks
|
|
|
|
|
// array indirections so they can be percolated from outer structs to inner variables.
|
|
|
|
|
std::vector <int> arrayElement;
|
|
|
|
|
|
2016-12-19 22:48:01 +00:00
|
|
|
|
// We track the outer-most aggregate, so that we can use its storage class later.
|
|
|
|
|
const TIntermTyped* outerLeft = left;
|
|
|
|
|
const TIntermTyped* outerRight = right;
|
|
|
|
|
|
2017-06-30 00:23:31 +00:00
|
|
|
|
const auto getMember = [&](bool isLeft, TIntermTyped* node, int member, TIntermTyped* splitNode, int splitMember)
|
|
|
|
|
-> TIntermTyped * {
|
2017-07-31 05:39:48 +00:00
|
|
|
|
const bool flattened = isLeft ? isFlattenLeft : isFlattenRight;
|
|
|
|
|
const bool split = isLeft ? isSplitLeft : isSplitRight;
|
2017-03-18 00:51:05 +00:00
|
|
|
|
|
2017-07-31 05:39:48 +00:00
|
|
|
|
TIntermTyped* subTree;
|
2016-12-19 22:48:01 +00:00
|
|
|
|
const TType derefType(node->getType(), member);
|
2017-08-09 02:02:21 +00:00
|
|
|
|
const TVariable* builtInVar = nullptr;
|
|
|
|
|
if ((flattened || split) && derefType.isBuiltIn()) {
|
2017-07-31 05:39:48 +00:00
|
|
|
|
const TIntermTyped* outer = isLeft ? outerLeft : outerRight;
|
2017-08-09 02:02:21 +00:00
|
|
|
|
auto splitPair = splitBuiltIns.find(HlslParseContext::tInterstageIoData(
|
|
|
|
|
derefType.getQualifier().builtIn,
|
|
|
|
|
outer->getType().getQualifier().storage));
|
|
|
|
|
if (splitPair != splitBuiltIns.end())
|
|
|
|
|
builtInVar = splitPair->second;
|
|
|
|
|
}
|
|
|
|
|
if (builtInVar != nullptr) {
|
|
|
|
|
// copy from interstage IO built-in if needed
|
|
|
|
|
subTree = intermediate.addSymbol(*builtInVar);
|
2017-02-02 23:32:02 +00:00
|
|
|
|
|
2017-06-30 00:23:31 +00:00
|
|
|
|
// Arrayness of builtIn symbols isn't handled by the normal recursion:
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// it's been extracted and moved to the built-in.
|
2017-02-02 23:32:02 +00:00
|
|
|
|
if (subTree->getType().isArray() && !arrayElement.empty()) {
|
|
|
|
|
const TType splitDerefType(subTree->getType(), arrayElement.back());
|
2017-06-30 00:23:31 +00:00
|
|
|
|
subTree = intermediate.addIndex(EOpIndexDirect, subTree,
|
|
|
|
|
intermediate.addConstantUnion(arrayElement.back(), loc), loc);
|
2017-02-02 23:32:02 +00:00
|
|
|
|
subTree->setType(splitDerefType);
|
|
|
|
|
}
|
2016-12-19 22:48:01 +00:00
|
|
|
|
} else if (flattened && isFinalFlattening(derefType)) {
|
2017-07-31 05:39:48 +00:00
|
|
|
|
const TVector<TVariable*>& flatVariables = isLeft ? *leftVariables : *rightVariables;
|
2016-12-19 22:48:01 +00:00
|
|
|
|
subTree = intermediate.addSymbol(*flatVariables[memberIdx++]);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
} else {
|
2017-07-31 05:39:48 +00:00
|
|
|
|
// Index operator if it's an aggregate, else EOpNull
|
|
|
|
|
const TOperator accessOp = node->getType().isArray() ? EOpIndexDirect
|
|
|
|
|
: node->getType().isStruct() ? EOpIndexDirectStruct
|
|
|
|
|
: EOpNull;
|
|
|
|
|
if (accessOp == EOpNull) {
|
2017-03-18 00:51:05 +00:00
|
|
|
|
subTree = splitNode;
|
|
|
|
|
} else {
|
2017-07-31 05:39:48 +00:00
|
|
|
|
subTree = intermediate.addIndex(accessOp, splitNode, intermediate.addConstantUnion(splitMember, loc),
|
|
|
|
|
loc);
|
2017-03-18 00:51:05 +00:00
|
|
|
|
const TType splitDerefType(splitNode->getType(), splitMember);
|
|
|
|
|
subTree->setType(splitDerefType);
|
|
|
|
|
}
|
2016-09-17 01:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return subTree;
|
|
|
|
|
};
|
2016-09-16 19:26:37 +00:00
|
|
|
|
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
// Use the proper RHS node: a new symbol from a TVariable, copy
|
|
|
|
|
// of an TIntermSymbol node, or sometimes the right node directly.
|
2017-06-30 00:23:31 +00:00
|
|
|
|
right = rhsTempVar != nullptr ? intermediate.addSymbol(*rhsTempVar, loc) :
|
|
|
|
|
cloneSymNode != nullptr ? intermediate.addSymbol(*cloneSymNode) :
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
right;
|
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
// Cannot use auto here, because this is recursive, and auto can't work out the type without seeing the
|
|
|
|
|
// whole thing. So, we'll resort to an explicit type via std::function.
|
2016-12-19 22:48:01 +00:00
|
|
|
|
const std::function<void(TIntermTyped* left, TIntermTyped* right, TIntermTyped* splitLeft, TIntermTyped* splitRight)>
|
|
|
|
|
traverse = [&](TIntermTyped* left, TIntermTyped* right, TIntermTyped* splitLeft, TIntermTyped* splitRight) -> void {
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
// If we get here, we are assigning to or from a whole array or struct that must be
|
2016-09-16 19:26:37 +00:00
|
|
|
|
// flattened, so have to do member-by-member assignment:
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
|
2017-03-18 00:51:05 +00:00
|
|
|
|
if (left->getType().isArray() || right->getType().isArray()) {
|
2017-07-31 05:39:48 +00:00
|
|
|
|
const int elementsL = left->getType().isArray() ? left->getType().getOuterArraySize() : 1;
|
2017-03-18 00:51:05 +00:00
|
|
|
|
const int elementsR = right->getType().isArray() ? right->getType().getOuterArraySize() : 1;
|
|
|
|
|
|
|
|
|
|
// The arrays may not be the same size, e.g, if the size has been forced for EbvTessLevelInner or Outer.
|
|
|
|
|
const int elementsToCopy = std::min(elementsL, elementsR);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
|
2016-12-19 22:48:01 +00:00
|
|
|
|
// array case
|
2017-05-26 06:01:36 +00:00
|
|
|
|
for (int element = 0; element < elementsToCopy; ++element) {
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
arrayElement.push_back(element);
|
|
|
|
|
|
2017-02-02 23:32:02 +00:00
|
|
|
|
// Add a new AST symbol node if we have a temp variable holding a complex RHS.
|
2016-12-19 22:48:01 +00:00
|
|
|
|
TIntermTyped* subLeft = getMember(true, left, element, left, element);
|
|
|
|
|
TIntermTyped* subRight = getMember(false, right, element, right, element);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
|
2017-06-30 00:23:31 +00:00
|
|
|
|
TIntermTyped* subSplitLeft = isSplitLeft ? getMember(true, left, element, splitLeft, element)
|
|
|
|
|
: subLeft;
|
|
|
|
|
TIntermTyped* subSplitRight = isSplitRight ? getMember(false, right, element, splitRight, element)
|
|
|
|
|
: subRight;
|
2017-01-19 22:18:00 +00:00
|
|
|
|
|
2017-03-18 00:51:05 +00:00
|
|
|
|
traverse(subLeft, subRight, subSplitLeft, subSplitRight);
|
2017-02-02 23:32:02 +00:00
|
|
|
|
|
|
|
|
|
arrayElement.pop_back();
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (left->getType().isStruct()) {
|
|
|
|
|
// struct case
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
const auto& membersL = *left->getType().getStruct();
|
|
|
|
|
const auto& membersR = *right->getType().getStruct();
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
|
2016-12-19 22:48:01 +00:00
|
|
|
|
// These track the members in the split structures corresponding to the same in the unsplit structures,
|
|
|
|
|
// which we traverse in parallel.
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
int memberL = 0;
|
|
|
|
|
int memberR = 0;
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
|
2017-03-24 14:56:37 +00:00
|
|
|
|
// Handle empty structure assignment
|
|
|
|
|
if (int(membersL.size()) == 0 && int(membersR.size()) == 0)
|
|
|
|
|
assignList = intermediate.growAggregate(assignList, intermediate.addAssign(op, left, right, loc), loc);
|
|
|
|
|
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
for (int member = 0; member < int(membersL.size()); ++member) {
|
|
|
|
|
const TType& typeL = *membersL[member].type;
|
|
|
|
|
const TType& typeR = *membersR[member].type;
|
|
|
|
|
|
2016-12-19 22:48:01 +00:00
|
|
|
|
TIntermTyped* subLeft = getMember(true, left, member, left, member);
|
|
|
|
|
TIntermTyped* subRight = getMember(false, right, member, right, member);
|
|
|
|
|
|
|
|
|
|
// If there is no splitting, use the same values to avoid inefficiency.
|
2017-06-30 00:23:31 +00:00
|
|
|
|
TIntermTyped* subSplitLeft = isSplitLeft ? getMember(true, left, member, splitLeft, memberL)
|
|
|
|
|
: subLeft;
|
|
|
|
|
TIntermTyped* subSplitRight = isSplitRight ? getMember(false, right, member, splitRight, memberR)
|
|
|
|
|
: subRight;
|
2016-12-19 22:48:01 +00:00
|
|
|
|
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
if (isClipOrCullDistance(subSplitLeft->getType())) {
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// Clip and cull distance built-in assignment is complex in its own right, and is handled in
|
2017-06-22 18:08:00 +00:00
|
|
|
|
// a separate function dedicated to that task. See comment above assignClipCullDistance;
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// Since all clip/cull semantics boil down to the same built-in type, we need to get the
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
// semantic ID from the dereferenced type's layout location, to avoid an N-1 mapping.
|
|
|
|
|
const TType derefType(left->getType(), member);
|
|
|
|
|
const int semanticId = derefType.getQualifier().layoutLocation;
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* clipCullAssign = assignClipCullDistance(loc, op, semanticId,
|
|
|
|
|
subSplitLeft, subSplitRight);
|
|
|
|
|
|
|
|
|
|
assignList = intermediate.growAggregate(assignList, clipCullAssign, loc);
|
|
|
|
|
|
2017-06-30 00:23:31 +00:00
|
|
|
|
} else if (!isFlattenLeft && !isFlattenRight &&
|
2017-08-02 23:08:43 +00:00
|
|
|
|
!typeL.containsBuiltIn() &&
|
|
|
|
|
!typeR.containsBuiltIn()) {
|
2017-06-30 00:23:31 +00:00
|
|
|
|
// If this is the final flattening (no nested types below to flatten)
|
|
|
|
|
// we'll copy the member, else recurse into the type hierarchy.
|
|
|
|
|
// However, if splitting the struct, that means we can copy a whole
|
|
|
|
|
// subtree here IFF it does not itself contain any interstage built-in
|
|
|
|
|
// IO variables, so we only have to recurse into it if there's something
|
|
|
|
|
// for splitting to do. That can save a lot of AST verbosity for
|
2017-06-22 18:08:00 +00:00
|
|
|
|
// a bunch of memberwise copies.
|
|
|
|
|
|
2017-06-30 00:23:31 +00:00
|
|
|
|
assignList = intermediate.growAggregate(assignList,
|
|
|
|
|
intermediate.addAssign(op, subSplitLeft, subSplitRight, loc),
|
|
|
|
|
loc);
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
} else {
|
2016-12-19 22:48:01 +00:00
|
|
|
|
traverse(subLeft, subRight, subSplitLeft, subSplitRight);
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
}
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
|
2017-08-02 23:08:43 +00:00
|
|
|
|
memberL += (typeL.isBuiltIn() ? 0 : 1);
|
|
|
|
|
memberR += (typeR.isBuiltIn() ? 0 : 1);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2017-03-18 00:51:05 +00:00
|
|
|
|
// Member copy
|
|
|
|
|
assignList = intermediate.growAggregate(assignList, intermediate.addAssign(op, left, right, loc), loc);
|
2016-09-16 19:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
};
|
2016-09-16 19:26:37 +00:00
|
|
|
|
|
2016-12-19 22:48:01 +00:00
|
|
|
|
TIntermTyped* splitLeft = left;
|
|
|
|
|
TIntermTyped* splitRight = right;
|
|
|
|
|
|
|
|
|
|
// If either left or right was a split structure, we must read or write it, but still have to
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// parallel-recurse through the unsplit structure to identify the built-in IO vars.
|
2016-12-19 22:48:01 +00:00
|
|
|
|
if (isSplitLeft)
|
2017-08-07 01:42:42 +00:00
|
|
|
|
splitLeft = intermediate.addSymbol(*getSplitNonIoVar(left->getAsSymbolNode()->getId()), loc);
|
2016-12-19 22:48:01 +00:00
|
|
|
|
|
|
|
|
|
if (isSplitRight)
|
2017-08-07 01:42:42 +00:00
|
|
|
|
splitRight = intermediate.addSymbol(*getSplitNonIoVar(right->getAsSymbolNode()->getId()), loc);
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
|
|
|
|
|
// This makes the whole assignment, recursing through subtypes as needed.
|
2016-12-19 22:48:01 +00:00
|
|
|
|
traverse(left, right, splitLeft, splitRight);
|
2016-09-16 19:26:37 +00:00
|
|
|
|
|
|
|
|
|
assert(assignList != nullptr);
|
2016-09-16 09:05:12 +00:00
|
|
|
|
assignList->setOperator(EOpSequence);
|
|
|
|
|
|
|
|
|
|
return assignList;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-13 19:27:52 +00:00
|
|
|
|
// An assignment to matrix swizzle must be decomposed into individual assignments.
|
|
|
|
|
// These must be selected component-wise from the RHS and stored component-wise
|
|
|
|
|
// into the LHS.
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::handleAssignToMatrixSwizzle(const TSourceLoc& loc, TOperator op, TIntermTyped* left,
|
|
|
|
|
TIntermTyped* right)
|
2017-01-13 19:27:52 +00:00
|
|
|
|
{
|
|
|
|
|
assert(left->getAsOperator() && left->getAsOperator()->getOp() == EOpMatrixSwizzle);
|
|
|
|
|
|
|
|
|
|
if (op != EOpAssign)
|
|
|
|
|
error(loc, "only simple assignment to non-simple matrix swizzle is supported", "assign", "");
|
|
|
|
|
|
|
|
|
|
// isolate the matrix and swizzle nodes
|
|
|
|
|
TIntermTyped* matrix = left->getAsBinaryNode()->getLeft()->getAsTyped();
|
|
|
|
|
const TIntermSequence& swizzle = left->getAsBinaryNode()->getRight()->getAsAggregate()->getSequence();
|
|
|
|
|
|
|
|
|
|
// if the RHS isn't already a simple vector, let's store into one
|
|
|
|
|
TIntermSymbol* vector = right->getAsSymbolNode();
|
|
|
|
|
TIntermTyped* vectorAssign = nullptr;
|
|
|
|
|
if (vector == nullptr) {
|
|
|
|
|
// create a new intermediate vector variable to assign to
|
2017-02-17 18:05:14 +00:00
|
|
|
|
TType vectorType(matrix->getBasicType(), EvqTemporary, matrix->getQualifier().precision, (int)swizzle.size()/2);
|
2017-01-13 19:27:52 +00:00
|
|
|
|
vector = intermediate.addSymbol(*makeInternalVariable("intermVec", vectorType), loc);
|
|
|
|
|
|
|
|
|
|
// assign the right to the new vector
|
|
|
|
|
vectorAssign = handleAssign(loc, op, vector, right);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Assign the vector components to the matrix components.
|
|
|
|
|
// Store this as a sequence, so a single aggregate node represents this
|
|
|
|
|
// entire operation.
|
|
|
|
|
TIntermAggregate* result = intermediate.makeAggregate(vectorAssign);
|
|
|
|
|
TType columnType(matrix->getType(), 0);
|
|
|
|
|
TType componentType(columnType, 0);
|
|
|
|
|
TType indexType(EbtInt);
|
|
|
|
|
for (int i = 0; i < (int)swizzle.size(); i += 2) {
|
|
|
|
|
// the right component, single index into the RHS vector
|
|
|
|
|
TIntermTyped* rightComp = intermediate.addIndex(EOpIndexDirect, vector,
|
|
|
|
|
intermediate.addConstantUnion(i/2, loc), loc);
|
|
|
|
|
|
|
|
|
|
// the left component, double index into the LHS matrix
|
|
|
|
|
TIntermTyped* leftComp = intermediate.addIndex(EOpIndexDirect, matrix,
|
|
|
|
|
intermediate.addConstantUnion(swizzle[i]->getAsConstantUnion()->getConstArray(),
|
|
|
|
|
indexType, loc),
|
|
|
|
|
loc);
|
|
|
|
|
leftComp->setType(columnType);
|
|
|
|
|
leftComp = intermediate.addIndex(EOpIndexDirect, leftComp,
|
|
|
|
|
intermediate.addConstantUnion(swizzle[i+1]->getAsConstantUnion()->getConstArray(),
|
|
|
|
|
indexType, loc),
|
|
|
|
|
loc);
|
|
|
|
|
leftComp->setType(componentType);
|
|
|
|
|
|
|
|
|
|
// Add the assignment to the aggregate
|
|
|
|
|
result = intermediate.growAggregate(result, intermediate.addAssign(op, leftComp, rightComp, loc));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result->setOp(EOpSequence);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-13 15:22:28 +00:00
|
|
|
|
//
|
|
|
|
|
// HLSL atomic operations have slightly different arguments than
|
|
|
|
|
// GLSL/AST/SPIRV. The semantics are converted below in decomposeIntrinsic.
|
|
|
|
|
// This provides the post-decomposition equivalent opcode.
|
|
|
|
|
//
|
|
|
|
|
TOperator HlslParseContext::mapAtomicOp(const TSourceLoc& loc, TOperator op, bool isImage)
|
|
|
|
|
{
|
|
|
|
|
switch (op) {
|
2016-10-19 16:15:25 +00:00
|
|
|
|
case EOpInterlockedAdd: return isImage ? EOpImageAtomicAdd : EOpAtomicAdd;
|
|
|
|
|
case EOpInterlockedAnd: return isImage ? EOpImageAtomicAnd : EOpAtomicAnd;
|
2016-06-13 15:22:28 +00:00
|
|
|
|
case EOpInterlockedCompareExchange: return isImage ? EOpImageAtomicCompSwap : EOpAtomicCompSwap;
|
2016-10-19 16:15:25 +00:00
|
|
|
|
case EOpInterlockedMax: return isImage ? EOpImageAtomicMax : EOpAtomicMax;
|
|
|
|
|
case EOpInterlockedMin: return isImage ? EOpImageAtomicMin : EOpAtomicMin;
|
|
|
|
|
case EOpInterlockedOr: return isImage ? EOpImageAtomicOr : EOpAtomicOr;
|
|
|
|
|
case EOpInterlockedXor: return isImage ? EOpImageAtomicXor : EOpAtomicXor;
|
2016-06-13 15:22:28 +00:00
|
|
|
|
case EOpInterlockedExchange: return isImage ? EOpImageAtomicExchange : EOpAtomicExchange;
|
2017-01-06 07:34:48 +00:00
|
|
|
|
case EOpInterlockedCompareStore: // TODO: ...
|
2016-06-13 15:22:28 +00:00
|
|
|
|
default:
|
|
|
|
|
error(loc, "unknown atomic operation", "unknown op", "");
|
|
|
|
|
return EOpNull;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 19:26:59 +00:00
|
|
|
|
//
|
2016-07-14 20:45:14 +00:00
|
|
|
|
// Create a combined sampler/texture from separate sampler and texture.
|
2016-06-20 19:26:59 +00:00
|
|
|
|
//
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermAggregate* HlslParseContext::handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex,
|
|
|
|
|
TIntermTyped* argSampler)
|
2016-07-14 20:45:14 +00:00
|
|
|
|
{
|
|
|
|
|
TIntermAggregate* txcombine = new TIntermAggregate(EOpConstructTextureSampler);
|
|
|
|
|
|
|
|
|
|
txcombine->getSequence().push_back(argTex);
|
|
|
|
|
txcombine->getSequence().push_back(argSampler);
|
|
|
|
|
|
|
|
|
|
TSampler samplerType = argTex->getType().getSampler();
|
|
|
|
|
samplerType.combined = true;
|
2016-07-19 20:28:05 +00:00
|
|
|
|
samplerType.shadow = argSampler->getType().getSampler().shadow;
|
2016-07-14 20:45:14 +00:00
|
|
|
|
|
|
|
|
|
txcombine->setType(TType(samplerType, EvqTemporary));
|
|
|
|
|
txcombine->setLoc(loc);
|
|
|
|
|
|
|
|
|
|
return txcombine;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 14:19:21 +00:00
|
|
|
|
// Return true if this a buffer type that has an associated counter buffer.
|
2017-04-24 01:44:28 +00:00
|
|
|
|
bool HlslParseContext::hasStructBuffCounter(const TType& type) const
|
2017-04-10 14:19:21 +00:00
|
|
|
|
{
|
2017-04-24 01:44:28 +00:00
|
|
|
|
switch (type.getQualifier().declaredBuiltIn) {
|
2017-04-10 14:19:21 +00:00
|
|
|
|
case EbvAppendConsume: // fall through...
|
|
|
|
|
case EbvRWStructuredBuffer: // ...
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
2017-05-26 06:01:36 +00:00
|
|
|
|
return false; // the other structuredbuffer types do not have a counter.
|
2017-04-10 14:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:22:32 +00:00
|
|
|
|
void HlslParseContext::counterBufferType(const TSourceLoc& loc, TType& type)
|
|
|
|
|
{
|
|
|
|
|
// Counter type
|
|
|
|
|
TType* counterType = new TType(EbtInt, EvqBuffer);
|
|
|
|
|
counterType->setFieldName("@count");
|
|
|
|
|
|
|
|
|
|
TTypeList* blockStruct = new TTypeList;
|
|
|
|
|
TTypeLoc member = { counterType, loc };
|
|
|
|
|
blockStruct->push_back(member);
|
|
|
|
|
|
|
|
|
|
TType blockType(blockStruct, "", counterType->getQualifier());
|
|
|
|
|
blockType.getQualifier().storage = EvqBuffer;
|
|
|
|
|
|
|
|
|
|
type.shallowCopy(blockType);
|
|
|
|
|
shareStructBufferType(type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// knowledge of how to construct block name, in one place instead of N places.
|
|
|
|
|
TString HlslParseContext::getStructBuffCounterName(const TString& blockName) const
|
|
|
|
|
{
|
|
|
|
|
return blockName + "@count";
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 14:19:21 +00:00
|
|
|
|
// declare counter for a structured buffer type
|
|
|
|
|
void HlslParseContext::declareStructBufferCounter(const TSourceLoc& loc, const TType& bufferType, const TString& name)
|
|
|
|
|
{
|
|
|
|
|
// Bail out if not a struct buffer
|
|
|
|
|
if (! isStructBufferType(bufferType))
|
|
|
|
|
return;
|
|
|
|
|
|
2017-04-24 01:44:28 +00:00
|
|
|
|
if (! hasStructBuffCounter(bufferType))
|
2017-04-10 14:19:21 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2017-04-27 17:22:32 +00:00
|
|
|
|
TType blockType;
|
|
|
|
|
counterBufferType(loc, blockType);
|
2017-04-10 14:19:21 +00:00
|
|
|
|
|
2017-04-27 17:22:32 +00:00
|
|
|
|
TString* blockName = new TString(getStructBuffCounterName(name));
|
2017-04-10 14:19:21 +00:00
|
|
|
|
|
2017-04-27 17:22:32 +00:00
|
|
|
|
// Counter buffer does not have its own counter buffer. TODO: there should be a better way to track this.
|
2017-04-10 14:19:21 +00:00
|
|
|
|
structBufferCounter[*blockName] = false;
|
|
|
|
|
|
|
|
|
|
shareStructBufferType(blockType);
|
|
|
|
|
declareBlock(loc, blockType, blockName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// return the counter that goes with a given structuredbuffer
|
|
|
|
|
TIntermTyped* HlslParseContext::getStructBufferCounter(const TSourceLoc& loc, TIntermTyped* buffer)
|
|
|
|
|
{
|
|
|
|
|
// Bail out if not a struct buffer
|
|
|
|
|
if (buffer == nullptr || ! isStructBufferType(buffer->getType()))
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
2017-04-27 17:22:32 +00:00
|
|
|
|
const TString counterBlockName(getStructBuffCounterName(buffer->getAsSymbolNode()->getName()));
|
2017-04-10 14:19:21 +00:00
|
|
|
|
|
|
|
|
|
// Mark the counter as being used
|
2017-04-27 17:22:32 +00:00
|
|
|
|
structBufferCounter[counterBlockName] = true;
|
2017-04-10 14:19:21 +00:00
|
|
|
|
|
2017-04-27 17:22:32 +00:00
|
|
|
|
TIntermTyped* counterVar = handleVariable(loc, &counterBlockName); // find the block structure
|
2017-04-10 14:19:21 +00:00
|
|
|
|
TIntermTyped* index = intermediate.addConstantUnion(0, loc); // index to counter inside block struct
|
|
|
|
|
|
|
|
|
|
TIntermTyped* counterMember = intermediate.addIndex(EOpIndexDirectStruct, counterVar, index, loc);
|
|
|
|
|
counterMember->setType(TType(EbtInt));
|
|
|
|
|
return counterMember;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-02-13 00:50:28 +00:00
|
|
|
|
//
|
|
|
|
|
// Decompose structure buffer methods into AST
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::decomposeStructBufferMethods(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments)
|
|
|
|
|
{
|
2017-04-10 14:19:21 +00:00
|
|
|
|
if (node == nullptr || node->getAsOperator() == nullptr || arguments == nullptr)
|
2017-02-13 00:50:28 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const TOperator op = node->getAsOperator()->getOp();
|
2017-04-10 14:19:21 +00:00
|
|
|
|
TIntermAggregate* argAggregate = arguments->getAsAggregate();
|
2017-03-31 18:47:34 +00:00
|
|
|
|
|
2017-02-24 01:04:12 +00:00
|
|
|
|
// Buffer is the object upon which method is called, so always arg 0
|
2017-04-10 14:19:21 +00:00
|
|
|
|
TIntermTyped* bufferObj = nullptr;
|
|
|
|
|
|
|
|
|
|
// The parameters can be an aggregate, or just a the object as a symbol if there are no fn params.
|
|
|
|
|
if (argAggregate) {
|
|
|
|
|
if (argAggregate->getSequence().empty())
|
|
|
|
|
return;
|
|
|
|
|
bufferObj = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
} else {
|
|
|
|
|
bufferObj = arguments->getAsSymbolNode();
|
|
|
|
|
}
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
2017-04-14 00:42:58 +00:00
|
|
|
|
if (bufferObj == nullptr || bufferObj->getAsSymbolNode() == nullptr)
|
2017-02-24 01:04:12 +00:00
|
|
|
|
return;
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
2017-04-14 00:42:58 +00:00
|
|
|
|
// Some methods require a hidden internal counter, obtained via getStructBufferCounter().
|
|
|
|
|
// This lambda adds something to it and returns the old value.
|
|
|
|
|
const auto incDecCounter = [&](int incval) -> TIntermTyped* {
|
|
|
|
|
TIntermTyped* incrementValue = intermediate.addConstantUnion(incval, loc, true);
|
|
|
|
|
TIntermTyped* counter = getStructBufferCounter(loc, bufferObj); // obtain the counter member
|
|
|
|
|
|
|
|
|
|
if (counter == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* counterIncrement = new TIntermAggregate(EOpAtomicAdd);
|
|
|
|
|
counterIncrement->setType(TType(EbtUint, EvqTemporary));
|
|
|
|
|
counterIncrement->setLoc(loc);
|
|
|
|
|
counterIncrement->getSequence().push_back(counter);
|
|
|
|
|
counterIncrement->getSequence().push_back(incrementValue);
|
|
|
|
|
|
|
|
|
|
return counterIncrement;
|
|
|
|
|
};
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
2017-02-24 01:04:12 +00:00
|
|
|
|
// Index to obtain the runtime sized array out of the buffer.
|
|
|
|
|
TIntermTyped* argArray = indexStructBufferContent(loc, bufferObj);
|
|
|
|
|
if (argArray == nullptr)
|
|
|
|
|
return; // It might not be a struct buffer method.
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case EOpMethodLoad:
|
|
|
|
|
{
|
2017-04-20 15:00:56 +00:00
|
|
|
|
TIntermTyped* argIndex = makeIntegerIndex(argAggregate->getSequence()[1]->getAsTyped()); // index
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
2017-04-20 22:37:14 +00:00
|
|
|
|
const TType& bufferType = bufferObj->getType();
|
|
|
|
|
|
2017-04-24 01:44:28 +00:00
|
|
|
|
const TBuiltInVariable builtInType = bufferType.getQualifier().declaredBuiltIn;
|
|
|
|
|
|
2017-02-13 00:50:28 +00:00
|
|
|
|
// Byte address buffers index in bytes (only multiples of 4 permitted... not so much a byte address
|
|
|
|
|
// buffer then, but that's what it calls itself.
|
2017-04-20 22:37:14 +00:00
|
|
|
|
const bool isByteAddressBuffer = (builtInType == EbvByteAddressBuffer ||
|
2017-04-24 01:44:28 +00:00
|
|
|
|
builtInType == EbvRWByteAddressBuffer);
|
2017-04-20 22:37:14 +00:00
|
|
|
|
|
2017-04-14 00:42:58 +00:00
|
|
|
|
|
2017-02-13 00:50:28 +00:00
|
|
|
|
if (isByteAddressBuffer)
|
2017-07-28 22:20:13 +00:00
|
|
|
|
argIndex = intermediate.addBinaryNode(EOpRightShift, argIndex,
|
|
|
|
|
intermediate.addConstantUnion(2, loc, true),
|
2017-02-13 00:50:28 +00:00
|
|
|
|
loc, TType(EbtInt));
|
|
|
|
|
|
|
|
|
|
// Index into the array to find the item being loaded.
|
|
|
|
|
const TOperator idxOp = (argIndex->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
|
|
|
|
|
|
|
|
|
|
node = intermediate.addIndex(idxOp, argArray, argIndex, loc);
|
|
|
|
|
|
|
|
|
|
const TType derefType(argArray->getType(), 0);
|
|
|
|
|
node->setType(derefType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EOpMethodLoad2:
|
|
|
|
|
case EOpMethodLoad3:
|
|
|
|
|
case EOpMethodLoad4:
|
|
|
|
|
{
|
2017-04-20 15:00:56 +00:00
|
|
|
|
TIntermTyped* argIndex = makeIntegerIndex(argAggregate->getSequence()[1]->getAsTyped()); // index
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
|
|
|
|
TOperator constructOp = EOpNull;
|
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case EOpMethodLoad2: size = 2; constructOp = EOpConstructVec2; break;
|
|
|
|
|
case EOpMethodLoad3: size = 3; constructOp = EOpConstructVec3; break;
|
|
|
|
|
case EOpMethodLoad4: size = 4; constructOp = EOpConstructVec4; break;
|
|
|
|
|
default: assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermTyped* body = nullptr;
|
|
|
|
|
|
|
|
|
|
// First, we'll store the address in a variable to avoid multiple shifts
|
|
|
|
|
// (we must convert the byte address to an item address)
|
|
|
|
|
TIntermTyped* byteAddrIdx = intermediate.addBinaryNode(EOpRightShift, argIndex,
|
2017-07-28 22:20:13 +00:00
|
|
|
|
intermediate.addConstantUnion(2, loc, true),
|
|
|
|
|
loc, TType(EbtInt));
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
|
|
|
|
TVariable* byteAddrSym = makeInternalVariable("byteAddrTemp", TType(EbtInt, EvqTemporary));
|
|
|
|
|
TIntermTyped* byteAddrIdxVar = intermediate.addSymbol(*byteAddrSym, loc);
|
|
|
|
|
|
|
|
|
|
body = intermediate.growAggregate(body, intermediate.addAssign(EOpAssign, byteAddrIdxVar, byteAddrIdx, loc));
|
|
|
|
|
|
|
|
|
|
TIntermTyped* vec = nullptr;
|
|
|
|
|
|
|
|
|
|
// These are only valid on (rw)byteaddressbuffers, so we can always perform the >>2
|
|
|
|
|
// address conversion.
|
|
|
|
|
for (int idx=0; idx<size; ++idx) {
|
|
|
|
|
TIntermTyped* offsetIdx = byteAddrIdxVar;
|
|
|
|
|
|
|
|
|
|
// add index offset
|
|
|
|
|
if (idx != 0)
|
2017-07-28 22:20:13 +00:00
|
|
|
|
offsetIdx = intermediate.addBinaryNode(EOpAdd, offsetIdx,
|
|
|
|
|
intermediate.addConstantUnion(idx, loc, true),
|
2017-02-13 00:50:28 +00:00
|
|
|
|
loc, TType(EbtInt));
|
|
|
|
|
|
2017-07-28 22:20:13 +00:00
|
|
|
|
const TOperator idxOp = (offsetIdx->getQualifier().storage == EvqConst) ? EOpIndexDirect
|
|
|
|
|
: EOpIndexIndirect;
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
|
|
|
|
vec = intermediate.growAggregate(vec, intermediate.addIndex(idxOp, argArray, offsetIdx, loc));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vec->setType(TType(argArray->getBasicType(), EvqTemporary, size));
|
|
|
|
|
vec->getAsAggregate()->setOperator(constructOp);
|
|
|
|
|
|
|
|
|
|
body = intermediate.growAggregate(body, vec);
|
|
|
|
|
body->setType(vec->getType());
|
|
|
|
|
body->getAsAggregate()->setOperator(EOpSequence);
|
|
|
|
|
|
|
|
|
|
node = body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EOpMethodStore:
|
|
|
|
|
case EOpMethodStore2:
|
|
|
|
|
case EOpMethodStore3:
|
|
|
|
|
case EOpMethodStore4:
|
|
|
|
|
{
|
2017-04-20 15:00:56 +00:00
|
|
|
|
TIntermTyped* argIndex = makeIntegerIndex(argAggregate->getSequence()[1]->getAsTyped()); // index
|
2017-02-13 00:50:28 +00:00
|
|
|
|
TIntermTyped* argValue = argAggregate->getSequence()[2]->getAsTyped(); // value
|
|
|
|
|
|
|
|
|
|
// Index into the array to find the item being loaded.
|
|
|
|
|
// Byte address buffers index in bytes (only multiples of 4 permitted... not so much a byte address
|
|
|
|
|
// buffer then, but that's what it calls itself.
|
|
|
|
|
|
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case EOpMethodStore: size = 1; break;
|
|
|
|
|
case EOpMethodStore2: size = 2; break;
|
|
|
|
|
case EOpMethodStore3: size = 3; break;
|
|
|
|
|
case EOpMethodStore4: size = 4; break;
|
|
|
|
|
default: assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* body = nullptr;
|
|
|
|
|
|
|
|
|
|
// First, we'll store the address in a variable to avoid multiple shifts
|
|
|
|
|
// (we must convert the byte address to an item address)
|
|
|
|
|
TIntermTyped* byteAddrIdx = intermediate.addBinaryNode(EOpRightShift, argIndex,
|
|
|
|
|
intermediate.addConstantUnion(2, loc, true), loc, TType(EbtInt));
|
|
|
|
|
|
|
|
|
|
TVariable* byteAddrSym = makeInternalVariable("byteAddrTemp", TType(EbtInt, EvqTemporary));
|
|
|
|
|
TIntermTyped* byteAddrIdxVar = intermediate.addSymbol(*byteAddrSym, loc);
|
|
|
|
|
|
|
|
|
|
body = intermediate.growAggregate(body, intermediate.addAssign(EOpAssign, byteAddrIdxVar, byteAddrIdx, loc));
|
|
|
|
|
|
|
|
|
|
for (int idx=0; idx<size; ++idx) {
|
|
|
|
|
TIntermTyped* offsetIdx = byteAddrIdxVar;
|
|
|
|
|
TIntermTyped* idxConst = intermediate.addConstantUnion(idx, loc, true);
|
|
|
|
|
|
|
|
|
|
// add index offset
|
|
|
|
|
if (idx != 0)
|
|
|
|
|
offsetIdx = intermediate.addBinaryNode(EOpAdd, offsetIdx, idxConst, loc, TType(EbtInt));
|
|
|
|
|
|
2017-07-28 22:20:13 +00:00
|
|
|
|
const TOperator idxOp = (offsetIdx->getQualifier().storage == EvqConst) ? EOpIndexDirect
|
|
|
|
|
: EOpIndexIndirect;
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
|
|
|
|
TIntermTyped* lValue = intermediate.addIndex(idxOp, argArray, offsetIdx, loc);
|
|
|
|
|
TIntermTyped* rValue = (size == 1) ? argValue :
|
|
|
|
|
intermediate.addIndex(EOpIndexDirect, argValue, idxConst, loc);
|
|
|
|
|
|
|
|
|
|
TIntermTyped* assign = intermediate.addAssign(EOpAssign, lValue, rValue, loc);
|
|
|
|
|
|
|
|
|
|
body = intermediate.growAggregate(body, assign);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
body->setOperator(EOpSequence);
|
|
|
|
|
node = body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EOpMethodGetDimensions:
|
|
|
|
|
{
|
2017-02-28 14:01:43 +00:00
|
|
|
|
const int numArgs = (int)argAggregate->getSequence().size();
|
2017-02-13 00:50:28 +00:00
|
|
|
|
TIntermTyped* argNumItems = argAggregate->getSequence()[1]->getAsTyped(); // out num items
|
|
|
|
|
TIntermTyped* argStride = numArgs > 2 ? argAggregate->getSequence()[2]->getAsTyped() : nullptr; // out stride
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* body = nullptr;
|
|
|
|
|
|
|
|
|
|
// Length output:
|
|
|
|
|
if (argArray->getType().isRuntimeSizedArray()) {
|
|
|
|
|
TIntermTyped* lengthCall = intermediate.addBuiltInFunctionCall(loc, EOpArrayLength, true, argArray,
|
|
|
|
|
argNumItems->getType());
|
|
|
|
|
TIntermTyped* assign = intermediate.addAssign(EOpAssign, argNumItems, lengthCall, loc);
|
|
|
|
|
body = intermediate.growAggregate(body, assign, loc);
|
|
|
|
|
} else {
|
|
|
|
|
const int length = argArray->getType().getOuterArraySize();
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermTyped* assign = intermediate.addAssign(EOpAssign, argNumItems,
|
|
|
|
|
intermediate.addConstantUnion(length, loc, true), loc);
|
2017-02-13 00:50:28 +00:00
|
|
|
|
body = intermediate.growAggregate(body, assign, loc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Stride output:
|
|
|
|
|
if (argStride != nullptr) {
|
|
|
|
|
int size;
|
|
|
|
|
int stride;
|
|
|
|
|
intermediate.getBaseAlignment(argArray->getType(), size, stride, false,
|
|
|
|
|
argArray->getType().getQualifier().layoutMatrix == ElmRowMajor);
|
|
|
|
|
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermTyped* assign = intermediate.addAssign(EOpAssign, argStride,
|
|
|
|
|
intermediate.addConstantUnion(stride, loc, true), loc);
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
|
|
|
|
body = intermediate.growAggregate(body, assign);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
body->setOperator(EOpSequence);
|
|
|
|
|
node = body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EOpInterlockedAdd:
|
|
|
|
|
case EOpInterlockedAnd:
|
|
|
|
|
case EOpInterlockedExchange:
|
|
|
|
|
case EOpInterlockedMax:
|
|
|
|
|
case EOpInterlockedMin:
|
|
|
|
|
case EOpInterlockedOr:
|
|
|
|
|
case EOpInterlockedXor:
|
|
|
|
|
case EOpInterlockedCompareExchange:
|
|
|
|
|
case EOpInterlockedCompareStore:
|
|
|
|
|
{
|
|
|
|
|
// We'll replace the first argument with the block dereference, and let
|
|
|
|
|
// downstream decomposition handle the rest.
|
|
|
|
|
|
|
|
|
|
TIntermSequence& sequence = argAggregate->getSequence();
|
|
|
|
|
|
2017-04-20 15:00:56 +00:00
|
|
|
|
TIntermTyped* argIndex = makeIntegerIndex(sequence[1]->getAsTyped()); // index
|
2017-02-13 00:50:28 +00:00
|
|
|
|
argIndex = intermediate.addBinaryNode(EOpRightShift, argIndex, intermediate.addConstantUnion(2, loc, true),
|
|
|
|
|
loc, TType(EbtInt));
|
|
|
|
|
|
|
|
|
|
const TOperator idxOp = (argIndex->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
|
|
|
|
|
TIntermTyped* element = intermediate.addIndex(idxOp, argArray, argIndex, loc);
|
|
|
|
|
|
|
|
|
|
const TType derefType(argArray->getType(), 0);
|
|
|
|
|
element->setType(derefType);
|
|
|
|
|
|
|
|
|
|
// Replace the numeric byte offset parameter with array reference.
|
|
|
|
|
sequence[1] = element;
|
|
|
|
|
sequence.erase(sequence.begin(), sequence.begin()+1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2017-04-10 14:19:21 +00:00
|
|
|
|
case EOpMethodIncrementCounter:
|
2017-04-14 00:42:58 +00:00
|
|
|
|
{
|
|
|
|
|
node = incDecCounter(1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 14:19:21 +00:00
|
|
|
|
case EOpMethodDecrementCounter:
|
|
|
|
|
{
|
2017-04-14 00:42:58 +00:00
|
|
|
|
TIntermTyped* preIncValue = incDecCounter(-1); // result is original value
|
|
|
|
|
node = intermediate.addBinaryNode(EOpAdd, preIncValue, intermediate.addConstantUnion(-1, loc, true), loc,
|
|
|
|
|
preIncValue->getType());
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-04-10 14:19:21 +00:00
|
|
|
|
|
2017-04-14 00:42:58 +00:00
|
|
|
|
case EOpMethodAppend:
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* oldCounter = incDecCounter(1);
|
2017-04-10 14:19:21 +00:00
|
|
|
|
|
2017-04-14 00:42:58 +00:00
|
|
|
|
TIntermTyped* lValue = intermediate.addIndex(EOpIndexIndirect, argArray, oldCounter, loc);
|
|
|
|
|
TIntermTyped* rValue = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
const TType derefType(argArray->getType(), 0);
|
|
|
|
|
lValue->setType(derefType);
|
|
|
|
|
|
2017-04-15 14:18:16 +00:00
|
|
|
|
node = intermediate.addAssign(EOpAssign, lValue, rValue, loc);
|
2017-04-14 00:42:58 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpMethodConsume:
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* oldCounter = incDecCounter(-1);
|
|
|
|
|
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermTyped* newCounter = intermediate.addBinaryNode(EOpAdd, oldCounter,
|
|
|
|
|
intermediate.addConstantUnion(-1, loc, true), loc,
|
|
|
|
|
oldCounter->getType());
|
2017-04-10 14:19:21 +00:00
|
|
|
|
|
2017-04-14 00:42:58 +00:00
|
|
|
|
node = intermediate.addIndex(EOpIndexIndirect, argArray, newCounter, loc);
|
2017-04-10 14:19:21 +00:00
|
|
|
|
|
2017-04-14 00:42:58 +00:00
|
|
|
|
const TType derefType(argArray->getType(), 0);
|
|
|
|
|
node->setType(derefType);
|
|
|
|
|
|
|
|
|
|
break;
|
2017-04-10 14:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 00:50:28 +00:00
|
|
|
|
default:
|
|
|
|
|
break; // most pass through unchanged
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-26 14:31:56 +00:00
|
|
|
|
|
|
|
|
|
// Create array of standard sample positions for given sample count.
|
|
|
|
|
// TODO: remove when a real method to query sample pos exists in SPIR-V.
|
|
|
|
|
TIntermConstantUnion* HlslParseContext::getSamplePosArray(int count)
|
|
|
|
|
{
|
|
|
|
|
struct tSamplePos { float x, y; };
|
|
|
|
|
|
|
|
|
|
static const tSamplePos pos1[] = {
|
|
|
|
|
{ 0.0/16.0, 0.0/16.0 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// standard sample positions for 2, 4, 8, and 16 samples.
|
|
|
|
|
static const tSamplePos pos2[] = {
|
|
|
|
|
{ 4.0/16.0, 4.0/16.0 }, {-4.0/16.0, -4.0/16.0 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const tSamplePos pos4[] = {
|
|
|
|
|
{-2.0/16.0, -6.0/16.0 }, { 6.0/16.0, -2.0/16.0 }, {-6.0/16.0, 2.0/16.0 }, { 2.0/16.0, 6.0/16.0 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const tSamplePos pos8[] = {
|
|
|
|
|
{ 1.0/16.0, -3.0/16.0 }, {-1.0/16.0, 3.0/16.0 }, { 5.0/16.0, 1.0/16.0 }, {-3.0/16.0, -5.0/16.0 },
|
|
|
|
|
{-5.0/16.0, 5.0/16.0 }, {-7.0/16.0, -1.0/16.0 }, { 3.0/16.0, 7.0/16.0 }, { 7.0/16.0, -7.0/16.0 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const tSamplePos pos16[] = {
|
|
|
|
|
{ 1.0/16.0, 1.0/16.0 }, {-1.0/16.0, -3.0/16.0 }, {-3.0/16.0, 2.0/16.0 }, { 4.0/16.0, -1.0/16.0 },
|
|
|
|
|
{-5.0/16.0, -2.0/16.0 }, { 2.0/16.0, 5.0/16.0 }, { 5.0/16.0, 3.0/16.0 }, { 3.0/16.0, -5.0/16.0 },
|
|
|
|
|
{-2.0/16.0, 6.0/16.0 }, { 0.0/16.0, -7.0/16.0 }, {-4.0/16.0, -6.0/16.0 }, {-6.0/16.0, 4.0/16.0 },
|
|
|
|
|
{-8.0/16.0, 0.0/16.0 }, { 7.0/16.0, -4.0/16.0 }, { 6.0/16.0, 7.0/16.0 }, {-7.0/16.0, -8.0/16.0 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const tSamplePos* sampleLoc = nullptr;
|
|
|
|
|
int numSamples = count;
|
|
|
|
|
|
|
|
|
|
switch (count) {
|
|
|
|
|
case 2: sampleLoc = pos2; break;
|
|
|
|
|
case 4: sampleLoc = pos4; break;
|
|
|
|
|
case 8: sampleLoc = pos8; break;
|
|
|
|
|
case 16: sampleLoc = pos16; break;
|
|
|
|
|
default:
|
|
|
|
|
sampleLoc = pos1;
|
|
|
|
|
numSamples = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TConstUnionArray* values = new TConstUnionArray(numSamples*2);
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
2017-04-26 14:31:56 +00:00
|
|
|
|
for (int pos=0; pos<count; ++pos) {
|
|
|
|
|
TConstUnion x, y;
|
|
|
|
|
x.setDConst(sampleLoc[pos].x);
|
|
|
|
|
y.setDConst(sampleLoc[pos].y);
|
|
|
|
|
|
|
|
|
|
(*values)[pos*2+0] = x;
|
|
|
|
|
(*values)[pos*2+1] = y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TType retType(EbtFloat, EvqConst, 2);
|
|
|
|
|
|
|
|
|
|
if (numSamples != 1) {
|
|
|
|
|
TArraySizes arraySizes;
|
|
|
|
|
arraySizes.addInnerSize(numSamples);
|
|
|
|
|
retType.newArraySizes(arraySizes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new TIntermConstantUnion(*values, retType);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-14 20:45:14 +00:00
|
|
|
|
//
|
|
|
|
|
// Decompose DX9 and DX10 sample intrinsics & object methods into AST
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::decomposeSampleMethods(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments)
|
2016-06-20 19:26:59 +00:00
|
|
|
|
{
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (node == nullptr || !node->getAsOperator())
|
2016-06-20 19:26:59 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2016-10-28 15:57:25 +00:00
|
|
|
|
const auto clampReturn = [&loc, &node, this](TIntermTyped* result, const TSampler& sampler) -> TIntermTyped* {
|
2016-10-14 22:40:32 +00:00
|
|
|
|
// Sampler return must always be a vec4, but we can construct a shorter vector
|
|
|
|
|
result->setType(TType(node->getType().getBasicType(), EvqTemporary, node->getVectorSize()));
|
|
|
|
|
|
2016-10-16 17:50:46 +00:00
|
|
|
|
if (sampler.vectorSize < (unsigned)node->getVectorSize()) {
|
2016-10-14 22:40:32 +00:00
|
|
|
|
// Too many components. Construct shorter vector from it.
|
|
|
|
|
const TType clampedType(result->getType().getBasicType(), EvqTemporary, sampler.vectorSize);
|
|
|
|
|
|
2016-10-15 00:36:42 +00:00
|
|
|
|
const TOperator op = intermediate.mapTypeToConstructorOp(clampedType);
|
2016-10-14 22:40:32 +00:00
|
|
|
|
|
|
|
|
|
result = constructBuiltIn(clampedType, op, result, loc, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result->setLoc(loc);
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-20 19:26:59 +00:00
|
|
|
|
const TOperator op = node->getAsOperator()->getOp();
|
|
|
|
|
const TIntermAggregate* argAggregate = arguments ? arguments->getAsAggregate() : nullptr;
|
|
|
|
|
|
2017-05-24 22:02:56 +00:00
|
|
|
|
// Bail out if not a sampler method.
|
|
|
|
|
// Note though this is odd to do before checking the op, because the op
|
|
|
|
|
// could be something that takes the arguments, and the function in question
|
|
|
|
|
// takes the result of the op. So, this is not the final word.
|
2017-02-13 00:50:28 +00:00
|
|
|
|
if (arguments != nullptr) {
|
2017-05-24 22:02:56 +00:00
|
|
|
|
if (argAggregate == nullptr) {
|
|
|
|
|
if (arguments->getAsTyped()->getBasicType() != EbtSampler)
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
if (argAggregate->getSequence().size() == 0 ||
|
|
|
|
|
argAggregate->getSequence()[0]->getAsTyped()->getBasicType() != EbtSampler)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-02-13 00:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 19:26:59 +00:00
|
|
|
|
switch (op) {
|
2016-07-14 20:45:14 +00:00
|
|
|
|
// **** DX9 intrinsics: ****
|
2016-06-20 19:26:59 +00:00
|
|
|
|
case EOpTexture:
|
|
|
|
|
{
|
2016-07-14 20:45:14 +00:00
|
|
|
|
// Texture with ddx & ddy is really gradient form in HLSL
|
2016-10-14 22:40:32 +00:00
|
|
|
|
if (argAggregate->getSequence().size() == 4)
|
2016-06-20 19:26:59 +00:00
|
|
|
|
node->getAsAggregate()->setOperator(EOpTextureGrad);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpTextureBias:
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped(); // sampler
|
|
|
|
|
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped(); // coord
|
|
|
|
|
|
|
|
|
|
// HLSL puts bias in W component of coordinate. We extract it and add it to
|
|
|
|
|
// the argument list, instead
|
|
|
|
|
TIntermTyped* w = intermediate.addConstantUnion(3, loc, true);
|
|
|
|
|
TIntermTyped* bias = intermediate.addIndex(EOpIndexDirect, arg1, w, loc);
|
|
|
|
|
|
|
|
|
|
TOperator constructOp = EOpNull;
|
2016-10-14 22:40:32 +00:00
|
|
|
|
const TSampler& sampler = arg0->getType().getSampler();
|
|
|
|
|
|
|
|
|
|
switch (sampler.dim) {
|
2016-06-20 19:26:59 +00:00
|
|
|
|
case Esd1D: constructOp = EOpConstructFloat; break; // 1D
|
|
|
|
|
case Esd2D: constructOp = EOpConstructVec2; break; // 2D
|
|
|
|
|
case Esd3D: constructOp = EOpConstructVec3; break; // 3D
|
|
|
|
|
case EsdCube: constructOp = EOpConstructVec3; break; // also 3D
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
2016-10-14 22:40:32 +00:00
|
|
|
|
|
2016-06-20 19:26:59 +00:00
|
|
|
|
TIntermAggregate* constructCoord = new TIntermAggregate(constructOp);
|
|
|
|
|
constructCoord->getSequence().push_back(arg1);
|
|
|
|
|
constructCoord->setLoc(loc);
|
|
|
|
|
|
2016-10-20 20:50:12 +00:00
|
|
|
|
// The input vector should never be less than 2, since there's always a bias.
|
|
|
|
|
// The max is for safety, and should be a no-op.
|
|
|
|
|
constructCoord->setType(TType(arg1->getBasicType(), EvqTemporary, std::max(arg1->getVectorSize() - 1, 0)));
|
|
|
|
|
|
2016-06-20 19:26:59 +00:00
|
|
|
|
TIntermAggregate* tex = new TIntermAggregate(EOpTexture);
|
|
|
|
|
tex->getSequence().push_back(arg0); // sampler
|
|
|
|
|
tex->getSequence().push_back(constructCoord); // coordinate
|
|
|
|
|
tex->getSequence().push_back(bias); // bias
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-10-14 22:40:32 +00:00
|
|
|
|
node = clampReturn(tex, sampler);
|
2016-06-20 19:26:59 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-14 20:45:14 +00:00
|
|
|
|
// **** DX10 methods: ****
|
|
|
|
|
case EOpMethodSample: // fall through
|
|
|
|
|
case EOpMethodSampleBias: // ...
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
|
|
|
|
|
TIntermTyped* argBias = nullptr;
|
|
|
|
|
TIntermTyped* argOffset = nullptr;
|
2016-10-14 22:40:32 +00:00
|
|
|
|
const TSampler& sampler = argTex->getType().getSampler();
|
2016-07-14 20:45:14 +00:00
|
|
|
|
|
|
|
|
|
int nextArg = 3;
|
|
|
|
|
|
|
|
|
|
if (op == EOpMethodSampleBias) // SampleBias has a bias arg
|
|
|
|
|
argBias = argAggregate->getSequence()[nextArg++]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
TOperator textureOp = EOpTexture;
|
|
|
|
|
|
2016-07-16 16:19:43 +00:00
|
|
|
|
if ((int)argAggregate->getSequence().size() == (nextArg+1)) { // last parameter is offset form
|
2016-07-14 20:45:14 +00:00
|
|
|
|
textureOp = EOpTextureOffset;
|
|
|
|
|
argOffset = argAggregate->getSequence()[nextArg++]->getAsTyped();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* txsample = new TIntermAggregate(textureOp);
|
|
|
|
|
txsample->getSequence().push_back(txcombine);
|
|
|
|
|
txsample->getSequence().push_back(argCoord);
|
|
|
|
|
|
|
|
|
|
if (argBias != nullptr)
|
|
|
|
|
txsample->getSequence().push_back(argBias);
|
|
|
|
|
|
|
|
|
|
if (argOffset != nullptr)
|
|
|
|
|
txsample->getSequence().push_back(argOffset);
|
|
|
|
|
|
2016-10-14 22:40:32 +00:00
|
|
|
|
node = clampReturn(txsample, sampler);
|
2016-07-14 20:45:14 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-07-14 20:45:14 +00:00
|
|
|
|
case EOpMethodSampleGrad: // ...
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
|
|
|
|
|
TIntermTyped* argDDX = argAggregate->getSequence()[3]->getAsTyped();
|
|
|
|
|
TIntermTyped* argDDY = argAggregate->getSequence()[4]->getAsTyped();
|
|
|
|
|
TIntermTyped* argOffset = nullptr;
|
2016-10-14 22:40:32 +00:00
|
|
|
|
const TSampler& sampler = argTex->getType().getSampler();
|
2016-07-14 20:45:14 +00:00
|
|
|
|
|
|
|
|
|
TOperator textureOp = EOpTextureGrad;
|
|
|
|
|
|
|
|
|
|
if (argAggregate->getSequence().size() == 6) { // last parameter is offset form
|
|
|
|
|
textureOp = EOpTextureGradOffset;
|
|
|
|
|
argOffset = argAggregate->getSequence()[5]->getAsTyped();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* txsample = new TIntermAggregate(textureOp);
|
|
|
|
|
txsample->getSequence().push_back(txcombine);
|
|
|
|
|
txsample->getSequence().push_back(argCoord);
|
|
|
|
|
txsample->getSequence().push_back(argDDX);
|
|
|
|
|
txsample->getSequence().push_back(argDDY);
|
|
|
|
|
|
|
|
|
|
if (argOffset != nullptr)
|
|
|
|
|
txsample->getSequence().push_back(argOffset);
|
|
|
|
|
|
2016-10-14 22:40:32 +00:00
|
|
|
|
node = clampReturn(txsample, sampler);
|
2016-07-14 20:45:14 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 17:22:24 +00:00
|
|
|
|
case EOpMethodGetDimensions:
|
|
|
|
|
{
|
|
|
|
|
// AST returns a vector of results, which we break apart component-wise into
|
|
|
|
|
// separate values to assign to the HLSL method's outputs, ala:
|
|
|
|
|
// tx . GetDimensions(width, height);
|
|
|
|
|
// float2 sizeQueryTemp = EOpTextureQuerySize
|
|
|
|
|
// width = sizeQueryTemp.X;
|
|
|
|
|
// height = sizeQueryTemp.Y;
|
|
|
|
|
|
|
|
|
|
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
const TType& texType = argTex->getType();
|
|
|
|
|
|
|
|
|
|
assert(texType.getBasicType() == EbtSampler);
|
|
|
|
|
|
2016-10-14 22:40:32 +00:00
|
|
|
|
const TSampler& sampler = texType.getSampler();
|
|
|
|
|
const TSamplerDim dim = sampler.dim;
|
|
|
|
|
const bool isImage = sampler.isImage();
|
2017-03-08 02:30:25 +00:00
|
|
|
|
const bool isMs = sampler.isMultiSample();
|
2016-08-05 23:34:34 +00:00
|
|
|
|
const int numArgs = (int)argAggregate->getSequence().size();
|
2016-07-15 17:22:24 +00:00
|
|
|
|
|
|
|
|
|
int numDims = 0;
|
|
|
|
|
|
|
|
|
|
switch (dim) {
|
2016-10-04 22:58:14 +00:00
|
|
|
|
case Esd1D: numDims = 1; break; // W
|
|
|
|
|
case Esd2D: numDims = 2; break; // W, H
|
|
|
|
|
case Esd3D: numDims = 3; break; // W, H, D
|
|
|
|
|
case EsdCube: numDims = 2; break; // W, H (cube)
|
2016-10-07 02:12:24 +00:00
|
|
|
|
case EsdBuffer: numDims = 1; break; // W (buffers)
|
2017-03-08 02:30:25 +00:00
|
|
|
|
case EsdRect: numDims = 2; break; // W, H (rect)
|
2016-07-15 17:22:24 +00:00
|
|
|
|
default:
|
|
|
|
|
assert(0 && "unhandled texture dimension");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Arrayed adds another dimension for the number of array elements
|
2016-10-14 22:40:32 +00:00
|
|
|
|
if (sampler.isArrayed())
|
2016-07-15 17:22:24 +00:00
|
|
|
|
++numDims;
|
|
|
|
|
|
2017-03-08 02:30:25 +00:00
|
|
|
|
// Establish whether the method itself is querying mip levels. This can be false even
|
|
|
|
|
// if the underlying query requires a MIP level, due to the available HLSL method overloads.
|
|
|
|
|
const bool mipQuery = (numArgs > (numDims + 1 + (isMs ? 1 : 0)));
|
|
|
|
|
|
|
|
|
|
// Establish whether we must use the LOD form of query (even if the method did not supply a mip level to query).
|
|
|
|
|
// True if:
|
|
|
|
|
// 1. 1D/2D/3D/Cube AND multisample==0 AND NOT image (those can be sent to the non-LOD query)
|
|
|
|
|
// or,
|
|
|
|
|
// 2. There is a LOD (because the non-LOD query cannot be used in that case, per spec)
|
|
|
|
|
const bool mipRequired =
|
|
|
|
|
((dim == Esd1D || dim == Esd2D || dim == Esd3D || dim == EsdCube) && !isMs && !isImage) || // 1...
|
|
|
|
|
mipQuery; // 2...
|
2016-07-15 17:22:24 +00:00
|
|
|
|
|
|
|
|
|
// AST assumes integer return. Will be converted to float if required.
|
2016-10-04 22:58:14 +00:00
|
|
|
|
TIntermAggregate* sizeQuery = new TIntermAggregate(isImage ? EOpImageQuerySize : EOpTextureQuerySize);
|
2016-07-15 17:22:24 +00:00
|
|
|
|
sizeQuery->getSequence().push_back(argTex);
|
2017-03-08 02:30:25 +00:00
|
|
|
|
|
|
|
|
|
// If we're building an LOD query, add the LOD.
|
|
|
|
|
if (mipRequired) {
|
|
|
|
|
// If the base HLSL query had no MIP level given, use level 0.
|
|
|
|
|
TIntermTyped* queryLod = mipQuery ? argAggregate->getSequence()[1]->getAsTyped() :
|
|
|
|
|
intermediate.addConstantUnion(0, loc, true);
|
2016-07-15 17:22:24 +00:00
|
|
|
|
sizeQuery->getSequence().push_back(queryLod);
|
|
|
|
|
}
|
2017-03-08 02:30:25 +00:00
|
|
|
|
|
2016-07-15 17:22:24 +00:00
|
|
|
|
sizeQuery->setType(TType(EbtUint, EvqTemporary, numDims));
|
|
|
|
|
sizeQuery->setLoc(loc);
|
|
|
|
|
|
|
|
|
|
// Return value from size query
|
|
|
|
|
TVariable* tempArg = makeInternalVariable("sizeQueryTemp", sizeQuery->getType());
|
|
|
|
|
tempArg->getWritableType().getQualifier().makeTemporary();
|
2016-10-03 04:13:22 +00:00
|
|
|
|
TIntermTyped* sizeQueryAssign = intermediate.addAssign(EOpAssign,
|
|
|
|
|
intermediate.addSymbol(*tempArg, loc),
|
|
|
|
|
sizeQuery, loc);
|
2016-07-15 17:22:24 +00:00
|
|
|
|
|
|
|
|
|
// Compound statement for assigning outputs
|
|
|
|
|
TIntermAggregate* compoundStatement = intermediate.makeAggregate(sizeQueryAssign, loc);
|
|
|
|
|
// Index of first output parameter
|
|
|
|
|
const int outParamBase = mipQuery ? 2 : 1;
|
|
|
|
|
|
|
|
|
|
for (int compNum = 0; compNum < numDims; ++compNum) {
|
|
|
|
|
TIntermTyped* indexedOut = nullptr;
|
2016-10-03 04:13:22 +00:00
|
|
|
|
TIntermSymbol* sizeQueryReturn = intermediate.addSymbol(*tempArg, loc);
|
2016-07-15 17:22:24 +00:00
|
|
|
|
|
|
|
|
|
if (numDims > 1) {
|
|
|
|
|
TIntermTyped* component = intermediate.addConstantUnion(compNum, loc, true);
|
|
|
|
|
indexedOut = intermediate.addIndex(EOpIndexDirect, sizeQueryReturn, component, loc);
|
|
|
|
|
indexedOut->setType(TType(EbtUint, EvqTemporary, 1));
|
|
|
|
|
indexedOut->setLoc(loc);
|
|
|
|
|
} else {
|
|
|
|
|
indexedOut = sizeQueryReturn;
|
|
|
|
|
}
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-07-15 17:22:24 +00:00
|
|
|
|
TIntermTyped* outParam = argAggregate->getSequence()[outParamBase + compNum]->getAsTyped();
|
|
|
|
|
TIntermTyped* compAssign = intermediate.addAssign(EOpAssign, outParam, indexedOut, loc);
|
|
|
|
|
|
|
|
|
|
compoundStatement = intermediate.growAggregate(compoundStatement, compAssign);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handle mip level parameter
|
|
|
|
|
if (mipQuery) {
|
|
|
|
|
TIntermTyped* outParam = argAggregate->getSequence()[outParamBase + numDims]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* levelsQuery = new TIntermAggregate(EOpTextureQueryLevels);
|
|
|
|
|
levelsQuery->getSequence().push_back(argTex);
|
|
|
|
|
levelsQuery->setType(TType(EbtUint, EvqTemporary, 1));
|
|
|
|
|
levelsQuery->setLoc(loc);
|
|
|
|
|
|
|
|
|
|
TIntermTyped* compAssign = intermediate.addAssign(EOpAssign, outParam, levelsQuery, loc);
|
|
|
|
|
compoundStatement = intermediate.growAggregate(compoundStatement, compAssign);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-26 21:19:28 +00:00
|
|
|
|
// 2DMS formats query # samples, which needs a different query op
|
2016-10-14 22:40:32 +00:00
|
|
|
|
if (sampler.isMultiSample()) {
|
2016-07-26 21:19:28 +00:00
|
|
|
|
TIntermTyped* outParam = argAggregate->getSequence()[outParamBase + numDims]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* samplesQuery = new TIntermAggregate(EOpImageQuerySamples);
|
|
|
|
|
samplesQuery->getSequence().push_back(argTex);
|
|
|
|
|
samplesQuery->setType(TType(EbtUint, EvqTemporary, 1));
|
|
|
|
|
samplesQuery->setLoc(loc);
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-07-26 21:19:28 +00:00
|
|
|
|
TIntermTyped* compAssign = intermediate.addAssign(EOpAssign, outParam, samplesQuery, loc);
|
|
|
|
|
compoundStatement = intermediate.growAggregate(compoundStatement, compAssign);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 17:22:24 +00:00
|
|
|
|
compoundStatement->setOperator(EOpSequence);
|
|
|
|
|
compoundStatement->setLoc(loc);
|
|
|
|
|
compoundStatement->setType(TType(EbtVoid));
|
|
|
|
|
|
|
|
|
|
node = compoundStatement;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 20:28:05 +00:00
|
|
|
|
case EOpMethodSampleCmp: // fall through...
|
|
|
|
|
case EOpMethodSampleCmpLevelZero:
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
|
|
|
|
|
TIntermTyped* argCmpVal = argAggregate->getSequence()[3]->getAsTyped();
|
|
|
|
|
TIntermTyped* argOffset = nullptr;
|
|
|
|
|
|
2017-04-21 15:54:53 +00:00
|
|
|
|
// Sampler argument should be a sampler.
|
|
|
|
|
if (argSamp->getType().getBasicType() != EbtSampler) {
|
|
|
|
|
error(loc, "expected: sampler type", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sampler should be a SamplerComparisonState
|
|
|
|
|
if (! argSamp->getType().getSampler().isShadow()) {
|
|
|
|
|
error(loc, "expected: SamplerComparisonState", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 20:28:05 +00:00
|
|
|
|
// optional offset value
|
|
|
|
|
if (argAggregate->getSequence().size() > 4)
|
|
|
|
|
argOffset = argAggregate->getSequence()[4]->getAsTyped();
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-07-19 20:28:05 +00:00
|
|
|
|
const int coordDimWithCmpVal = argCoord->getType().getVectorSize() + 1; // +1 for cmp
|
|
|
|
|
|
|
|
|
|
// AST wants comparison value as one of the texture coordinates
|
|
|
|
|
TOperator constructOp = EOpNull;
|
|
|
|
|
switch (coordDimWithCmpVal) {
|
|
|
|
|
// 1D can't happen: there's always at least 1 coordinate dimension + 1 cmp val
|
|
|
|
|
case 2: constructOp = EOpConstructVec2; break;
|
|
|
|
|
case 3: constructOp = EOpConstructVec3; break;
|
|
|
|
|
case 4: constructOp = EOpConstructVec4; break;
|
|
|
|
|
case 5: constructOp = EOpConstructVec4; break; // cubeArrayShadow, cmp value is separate arg.
|
|
|
|
|
default: assert(0); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* coordWithCmp = new TIntermAggregate(constructOp);
|
|
|
|
|
coordWithCmp->getSequence().push_back(argCoord);
|
|
|
|
|
if (coordDimWithCmpVal != 5) // cube array shadow is special.
|
|
|
|
|
coordWithCmp->getSequence().push_back(argCmpVal);
|
|
|
|
|
coordWithCmp->setLoc(loc);
|
2016-10-20 20:50:12 +00:00
|
|
|
|
coordWithCmp->setType(TType(argCoord->getBasicType(), EvqTemporary, std::min(coordDimWithCmpVal, 4)));
|
2016-07-19 20:28:05 +00:00
|
|
|
|
|
|
|
|
|
TOperator textureOp = (op == EOpMethodSampleCmpLevelZero ? EOpTextureLod : EOpTexture);
|
|
|
|
|
if (argOffset != nullptr)
|
|
|
|
|
textureOp = (op == EOpMethodSampleCmpLevelZero ? EOpTextureLodOffset : EOpTextureOffset);
|
|
|
|
|
|
|
|
|
|
// Create combined sampler & texture op
|
|
|
|
|
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
|
|
|
|
|
TIntermAggregate* txsample = new TIntermAggregate(textureOp);
|
|
|
|
|
txsample->getSequence().push_back(txcombine);
|
|
|
|
|
txsample->getSequence().push_back(coordWithCmp);
|
|
|
|
|
|
|
|
|
|
if (coordDimWithCmpVal == 5) // cube array shadow is special: cmp val follows coord.
|
|
|
|
|
txsample->getSequence().push_back(argCmpVal);
|
|
|
|
|
|
|
|
|
|
// the LevelZero form uses 0 as an explicit LOD
|
|
|
|
|
if (op == EOpMethodSampleCmpLevelZero)
|
|
|
|
|
txsample->getSequence().push_back(intermediate.addConstantUnion(0.0, EbtFloat, loc, true));
|
|
|
|
|
|
|
|
|
|
// Add offset if present
|
|
|
|
|
if (argOffset != nullptr)
|
|
|
|
|
txsample->getSequence().push_back(argOffset);
|
|
|
|
|
|
|
|
|
|
txsample->setType(node->getType());
|
|
|
|
|
txsample->setLoc(loc);
|
|
|
|
|
node = txsample;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-20 22:34:44 +00:00
|
|
|
|
case EOpMethodLoad:
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* argCoord = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
TIntermTyped* argOffset = nullptr;
|
|
|
|
|
TIntermTyped* lodComponent = nullptr;
|
|
|
|
|
TIntermTyped* coordSwizzle = nullptr;
|
|
|
|
|
|
2016-10-14 22:40:32 +00:00
|
|
|
|
const TSampler& sampler = argTex->getType().getSampler();
|
|
|
|
|
const bool isMS = sampler.isMultiSample();
|
|
|
|
|
const bool isBuffer = sampler.dim == EsdBuffer;
|
|
|
|
|
const bool isImage = sampler.isImage();
|
2016-07-20 22:34:44 +00:00
|
|
|
|
const TBasicType coordBaseType = argCoord->getType().getBasicType();
|
|
|
|
|
|
|
|
|
|
// Last component of coordinate is the mip level, for non-MS. we separate them here:
|
2016-10-04 22:58:14 +00:00
|
|
|
|
if (isMS || isBuffer || isImage) {
|
|
|
|
|
// MS, Buffer, and Image have no LOD
|
2016-07-26 21:19:28 +00:00
|
|
|
|
coordSwizzle = argCoord;
|
2016-07-20 22:34:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Extract coordinate
|
2017-01-14 02:34:22 +00:00
|
|
|
|
int swizzleSize = argCoord->getType().getVectorSize() - (isMS ? 0 : 1);
|
|
|
|
|
TSwizzleSelectors<TVectorSelector> coordFields;
|
|
|
|
|
for (int i = 0; i < swizzleSize; ++i)
|
|
|
|
|
coordFields.push_back(i);
|
2016-07-20 22:34:44 +00:00
|
|
|
|
TIntermTyped* coordIdx = intermediate.addSwizzle(coordFields, loc);
|
|
|
|
|
coordSwizzle = intermediate.addIndex(EOpVectorSwizzle, argCoord, coordIdx, loc);
|
2017-01-14 02:34:22 +00:00
|
|
|
|
coordSwizzle->setType(TType(coordBaseType, EvqTemporary, coordFields.size()));
|
2016-07-20 22:34:44 +00:00
|
|
|
|
|
|
|
|
|
// Extract LOD
|
2017-01-14 02:34:22 +00:00
|
|
|
|
TIntermTyped* lodIdx = intermediate.addConstantUnion(coordFields.size(), loc, true);
|
2016-07-20 22:34:44 +00:00
|
|
|
|
lodComponent = intermediate.addIndex(EOpIndexDirect, argCoord, lodIdx, loc);
|
|
|
|
|
lodComponent->setType(TType(coordBaseType, EvqTemporary, 1));
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 23:34:34 +00:00
|
|
|
|
const int numArgs = (int)argAggregate->getSequence().size();
|
2016-07-20 22:34:44 +00:00
|
|
|
|
const bool hasOffset = ((!isMS && numArgs == 3) || (isMS && numArgs == 4));
|
|
|
|
|
|
|
|
|
|
// Create texel fetch
|
2016-10-04 22:58:14 +00:00
|
|
|
|
const TOperator fetchOp = (isImage ? EOpImageLoad :
|
|
|
|
|
hasOffset ? EOpTextureFetchOffset :
|
|
|
|
|
EOpTextureFetch);
|
2016-07-20 22:34:44 +00:00
|
|
|
|
TIntermAggregate* txfetch = new TIntermAggregate(fetchOp);
|
|
|
|
|
|
|
|
|
|
// Build up the fetch
|
|
|
|
|
txfetch->getSequence().push_back(argTex);
|
|
|
|
|
txfetch->getSequence().push_back(coordSwizzle);
|
|
|
|
|
|
2016-07-26 21:19:28 +00:00
|
|
|
|
if (isMS) {
|
|
|
|
|
// add 2DMS sample index
|
|
|
|
|
TIntermTyped* argSampleIdx = argAggregate->getSequence()[2]->getAsTyped();
|
|
|
|
|
txfetch->getSequence().push_back(argSampleIdx);
|
2016-07-27 21:46:48 +00:00
|
|
|
|
} else if (isBuffer) {
|
|
|
|
|
// Nothing else to do for buffers.
|
2016-10-04 22:58:14 +00:00
|
|
|
|
} else if (isImage) {
|
|
|
|
|
// Nothing else to do for images.
|
2016-07-26 21:19:28 +00:00
|
|
|
|
} else {
|
2016-07-27 21:46:48 +00:00
|
|
|
|
// 2DMS and buffer have no LOD, but everything else does.
|
2016-07-20 22:34:44 +00:00
|
|
|
|
txfetch->getSequence().push_back(lodComponent);
|
2016-07-26 21:19:28 +00:00
|
|
|
|
}
|
2016-07-20 22:34:44 +00:00
|
|
|
|
|
2016-07-26 21:19:28 +00:00
|
|
|
|
// Obtain offset arg, if there is one.
|
|
|
|
|
if (hasOffset) {
|
|
|
|
|
const int offsetPos = (isMS ? 3 : 2);
|
|
|
|
|
argOffset = argAggregate->getSequence()[offsetPos]->getAsTyped();
|
2016-07-20 22:34:44 +00:00
|
|
|
|
txfetch->getSequence().push_back(argOffset);
|
2016-07-26 21:19:28 +00:00
|
|
|
|
}
|
2016-07-20 22:34:44 +00:00
|
|
|
|
|
2016-10-14 22:40:32 +00:00
|
|
|
|
node = clampReturn(txfetch, sampler);
|
2016-07-20 22:34:44 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 21:02:16 +00:00
|
|
|
|
case EOpMethodSampleLevel:
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
|
|
|
|
|
TIntermTyped* argLod = argAggregate->getSequence()[3]->getAsTyped();
|
|
|
|
|
TIntermTyped* argOffset = nullptr;
|
2016-10-14 22:40:32 +00:00
|
|
|
|
const TSampler& sampler = argTex->getType().getSampler();
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-08-05 23:34:34 +00:00
|
|
|
|
const int numArgs = (int)argAggregate->getSequence().size();
|
2016-07-21 21:02:16 +00:00
|
|
|
|
|
|
|
|
|
if (numArgs == 5) // offset, if present
|
|
|
|
|
argOffset = argAggregate->getSequence()[4]->getAsTyped();
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-07-21 21:02:16 +00:00
|
|
|
|
const TOperator textureOp = (argOffset == nullptr ? EOpTextureLod : EOpTextureLodOffset);
|
|
|
|
|
TIntermAggregate* txsample = new TIntermAggregate(textureOp);
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
|
|
|
|
|
|
|
|
|
|
txsample->getSequence().push_back(txcombine);
|
|
|
|
|
txsample->getSequence().push_back(argCoord);
|
|
|
|
|
txsample->getSequence().push_back(argLod);
|
|
|
|
|
|
|
|
|
|
if (argOffset != nullptr)
|
|
|
|
|
txsample->getSequence().push_back(argOffset);
|
|
|
|
|
|
2016-10-14 22:40:32 +00:00
|
|
|
|
node = clampReturn(txsample, sampler);
|
2016-07-21 21:02:16 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 14:28:11 +00:00
|
|
|
|
case EOpMethodGather:
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
|
|
|
|
|
TIntermTyped* argOffset = nullptr;
|
|
|
|
|
|
|
|
|
|
// Offset is optional
|
2016-07-31 16:37:02 +00:00
|
|
|
|
if (argAggregate->getSequence().size() > 3)
|
2016-07-22 14:28:11 +00:00
|
|
|
|
argOffset = argAggregate->getSequence()[3]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
const TOperator textureOp = (argOffset == nullptr ? EOpTextureGather : EOpTextureGatherOffset);
|
|
|
|
|
TIntermAggregate* txgather = new TIntermAggregate(textureOp);
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
|
|
|
|
|
|
|
|
|
|
txgather->getSequence().push_back(txcombine);
|
|
|
|
|
txgather->getSequence().push_back(argCoord);
|
2016-07-31 16:37:02 +00:00
|
|
|
|
// Offset if not given is implicitly channel 0 (red)
|
2016-07-22 14:28:11 +00:00
|
|
|
|
|
|
|
|
|
if (argOffset != nullptr)
|
|
|
|
|
txgather->getSequence().push_back(argOffset);
|
|
|
|
|
|
|
|
|
|
txgather->setType(node->getType());
|
|
|
|
|
txgather->setLoc(loc);
|
|
|
|
|
node = txgather;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-07-31 16:37:02 +00:00
|
|
|
|
case EOpMethodGatherRed: // fall through...
|
|
|
|
|
case EOpMethodGatherGreen: // ...
|
|
|
|
|
case EOpMethodGatherBlue: // ...
|
|
|
|
|
case EOpMethodGatherAlpha: // ...
|
|
|
|
|
case EOpMethodGatherCmpRed: // ...
|
|
|
|
|
case EOpMethodGatherCmpGreen: // ...
|
|
|
|
|
case EOpMethodGatherCmpBlue: // ...
|
|
|
|
|
case EOpMethodGatherCmpAlpha: // ...
|
|
|
|
|
{
|
|
|
|
|
int channel = 0; // the channel we are gathering
|
|
|
|
|
int cmpValues = 0; // 1 if there is a compare value (handier than a bool below)
|
|
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case EOpMethodGatherCmpRed: cmpValues = 1; // fall through
|
|
|
|
|
case EOpMethodGatherRed: channel = 0; break;
|
|
|
|
|
case EOpMethodGatherCmpGreen: cmpValues = 1; // fall through
|
|
|
|
|
case EOpMethodGatherGreen: channel = 1; break;
|
|
|
|
|
case EOpMethodGatherCmpBlue: cmpValues = 1; // fall through
|
|
|
|
|
case EOpMethodGatherBlue: channel = 2; break;
|
|
|
|
|
case EOpMethodGatherCmpAlpha: cmpValues = 1; // fall through
|
|
|
|
|
case EOpMethodGatherAlpha: channel = 3; break;
|
|
|
|
|
default: assert(0); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For now, we have nothing to map the component-wise comparison forms
|
|
|
|
|
// to, because neither GLSL nor SPIR-V has such an opcode. Issue an
|
|
|
|
|
// unimplemented error instead. Most of the machinery is here if that
|
2017-03-09 15:59:45 +00:00
|
|
|
|
// should ever become available. However, red can be passed through
|
|
|
|
|
// to OpImageDrefGather. G/B/A cannot, because that opcode does not
|
|
|
|
|
// accept a component.
|
|
|
|
|
if (cmpValues != 0 && op != EOpMethodGatherCmpRed) {
|
2016-07-31 16:37:02 +00:00
|
|
|
|
error(loc, "unimplemented: component-level gather compare", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int arg = 0;
|
|
|
|
|
|
|
|
|
|
TIntermTyped* argTex = argAggregate->getSequence()[arg++]->getAsTyped();
|
|
|
|
|
TIntermTyped* argSamp = argAggregate->getSequence()[arg++]->getAsTyped();
|
|
|
|
|
TIntermTyped* argCoord = argAggregate->getSequence()[arg++]->getAsTyped();
|
|
|
|
|
TIntermTyped* argOffset = nullptr;
|
|
|
|
|
TIntermTyped* argOffsets[4] = { nullptr, nullptr, nullptr, nullptr };
|
|
|
|
|
// TIntermTyped* argStatus = nullptr; // TODO: residency
|
|
|
|
|
TIntermTyped* argCmp = nullptr;
|
|
|
|
|
|
|
|
|
|
const TSamplerDim dim = argTex->getType().getSampler().dim;
|
|
|
|
|
|
2016-08-15 16:01:15 +00:00
|
|
|
|
const int argSize = (int)argAggregate->getSequence().size();
|
2016-07-31 16:37:02 +00:00
|
|
|
|
bool hasStatus = (argSize == (5+cmpValues) || argSize == (8+cmpValues));
|
|
|
|
|
bool hasOffset1 = false;
|
|
|
|
|
bool hasOffset4 = false;
|
|
|
|
|
|
2017-04-21 15:54:53 +00:00
|
|
|
|
// Sampler argument should be a sampler.
|
|
|
|
|
if (argSamp->getType().getBasicType() != EbtSampler) {
|
|
|
|
|
error(loc, "expected: sampler type", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cmp forms require SamplerComparisonState
|
|
|
|
|
if (cmpValues > 0 && ! argSamp->getType().getSampler().isShadow()) {
|
|
|
|
|
error(loc, "expected: SamplerComparisonState", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-31 16:37:02 +00:00
|
|
|
|
// Only 2D forms can have offsets. Discover if we have 0, 1 or 4 offsets.
|
|
|
|
|
if (dim == Esd2D) {
|
|
|
|
|
hasOffset1 = (argSize == (4+cmpValues) || argSize == (5+cmpValues));
|
|
|
|
|
hasOffset4 = (argSize == (7+cmpValues) || argSize == (8+cmpValues));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(!(hasOffset1 && hasOffset4));
|
|
|
|
|
|
|
|
|
|
TOperator textureOp = EOpTextureGather;
|
|
|
|
|
|
|
|
|
|
// Compare forms have compare value
|
|
|
|
|
if (cmpValues != 0)
|
|
|
|
|
argCmp = argOffset = argAggregate->getSequence()[arg++]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
// Some forms have single offset
|
|
|
|
|
if (hasOffset1) {
|
|
|
|
|
textureOp = EOpTextureGatherOffset; // single offset form
|
|
|
|
|
argOffset = argAggregate->getSequence()[arg++]->getAsTyped();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Some forms have 4 gather offsets
|
|
|
|
|
if (hasOffset4) {
|
|
|
|
|
textureOp = EOpTextureGatherOffsets; // note plural, for 4 offset form
|
|
|
|
|
for (int offsetNum = 0; offsetNum < 4; ++offsetNum)
|
|
|
|
|
argOffsets[offsetNum] = argAggregate->getSequence()[arg++]->getAsTyped();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Residency status
|
|
|
|
|
if (hasStatus) {
|
|
|
|
|
// argStatus = argAggregate->getSequence()[arg++]->getAsTyped();
|
|
|
|
|
error(loc, "unimplemented: residency status", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* txgather = new TIntermAggregate(textureOp);
|
|
|
|
|
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
|
|
|
|
|
|
|
|
|
|
TIntermTyped* argChannel = intermediate.addConstantUnion(channel, loc, true);
|
|
|
|
|
|
|
|
|
|
txgather->getSequence().push_back(txcombine);
|
|
|
|
|
txgather->getSequence().push_back(argCoord);
|
|
|
|
|
|
|
|
|
|
// AST wants an array of 4 offsets, where HLSL has separate args. Here
|
|
|
|
|
// we construct an array from the separate args.
|
|
|
|
|
if (hasOffset4) {
|
|
|
|
|
TType arrayType(EbtInt, EvqTemporary, 2);
|
|
|
|
|
TArraySizes arraySizes;
|
|
|
|
|
arraySizes.addInnerSize(4);
|
|
|
|
|
arrayType.newArraySizes(arraySizes);
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* initList = new TIntermAggregate(EOpNull);
|
|
|
|
|
|
|
|
|
|
for (int offsetNum = 0; offsetNum < 4; ++offsetNum)
|
|
|
|
|
initList->getSequence().push_back(argOffsets[offsetNum]);
|
|
|
|
|
|
|
|
|
|
argOffset = addConstructor(loc, initList, arrayType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add comparison value if we have one
|
2017-03-09 15:59:45 +00:00
|
|
|
|
if (argCmp != nullptr)
|
2016-07-31 16:37:02 +00:00
|
|
|
|
txgather->getSequence().push_back(argCmp);
|
|
|
|
|
|
|
|
|
|
// Add offset (either 1, or an array of 4) if we have one
|
|
|
|
|
if (argOffset != nullptr)
|
|
|
|
|
txgather->getSequence().push_back(argOffset);
|
|
|
|
|
|
2017-03-13 09:07:18 +00:00
|
|
|
|
// Add channel value if the sampler is not shadow
|
|
|
|
|
if (! argSamp->getType().getSampler().isShadow())
|
|
|
|
|
txgather->getSequence().push_back(argChannel);
|
2016-07-31 16:37:02 +00:00
|
|
|
|
|
|
|
|
|
txgather->setType(node->getType());
|
|
|
|
|
txgather->setLoc(loc);
|
|
|
|
|
node = txgather;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-26 14:57:53 +00:00
|
|
|
|
case EOpMethodCalculateLevelOfDetail:
|
|
|
|
|
case EOpMethodCalculateLevelOfDetailUnclamped:
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* txquerylod = new TIntermAggregate(EOpTextureQueryLod);
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
|
|
|
|
|
txquerylod->getSequence().push_back(txcombine);
|
|
|
|
|
txquerylod->getSequence().push_back(argCoord);
|
|
|
|
|
|
|
|
|
|
TIntermTyped* lodComponent = intermediate.addConstantUnion(0, loc, true);
|
|
|
|
|
TIntermTyped* lodComponentIdx = intermediate.addIndex(EOpIndexDirect, txquerylod, lodComponent, loc);
|
|
|
|
|
lodComponentIdx->setType(TType(EbtFloat, EvqTemporary, 1));
|
|
|
|
|
|
|
|
|
|
node = lodComponentIdx;
|
|
|
|
|
|
|
|
|
|
// We cannot currently obtain the unclamped LOD
|
|
|
|
|
if (op == EOpMethodCalculateLevelOfDetailUnclamped)
|
|
|
|
|
error(loc, "unimplemented: CalculateLevelOfDetailUnclamped", "", "");
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpMethodGetSamplePosition:
|
|
|
|
|
{
|
2017-04-26 14:31:56 +00:00
|
|
|
|
// TODO: this entire decomposition exists because there is not yet a way to query
|
|
|
|
|
// the sample position directly through SPIR-V. Instead, we return fixed sample
|
|
|
|
|
// positions for common cases. *** If the sample positions are set differently,
|
|
|
|
|
// this will be wrong. ***
|
|
|
|
|
|
|
|
|
|
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* argSampIdx = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* samplesQuery = new TIntermAggregate(EOpImageQuerySamples);
|
|
|
|
|
samplesQuery->getSequence().push_back(argTex);
|
|
|
|
|
samplesQuery->setType(TType(EbtUint, EvqTemporary, 1));
|
|
|
|
|
samplesQuery->setLoc(loc);
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* compoundStatement = nullptr;
|
|
|
|
|
|
|
|
|
|
TVariable* outSampleCount = makeInternalVariable("@sampleCount", TType(EbtUint));
|
|
|
|
|
outSampleCount->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
TIntermTyped* compAssign = intermediate.addAssign(EOpAssign, intermediate.addSymbol(*outSampleCount, loc),
|
|
|
|
|
samplesQuery, loc);
|
|
|
|
|
compoundStatement = intermediate.growAggregate(compoundStatement, compAssign);
|
|
|
|
|
|
|
|
|
|
TIntermTyped* idxtest[4];
|
|
|
|
|
|
|
|
|
|
// Create tests against 2, 4, 8, and 16 sample values
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (int val = 2; val <= 16; val *= 2)
|
|
|
|
|
idxtest[count++] =
|
|
|
|
|
intermediate.addBinaryNode(EOpEqual,
|
|
|
|
|
intermediate.addSymbol(*outSampleCount, loc),
|
|
|
|
|
intermediate.addConstantUnion(val, loc),
|
|
|
|
|
loc, TType(EbtBool));
|
|
|
|
|
|
|
|
|
|
const TOperator idxOp = (argSampIdx->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
|
|
|
|
|
|
|
|
|
|
// Create index ops into position arrays given sample index.
|
|
|
|
|
// TODO: should it be clamped?
|
|
|
|
|
TIntermTyped* index[4];
|
|
|
|
|
count = 0;
|
|
|
|
|
for (int val = 2; val <= 16; val *= 2) {
|
|
|
|
|
index[count] = intermediate.addIndex(idxOp, getSamplePosArray(val), argSampIdx, loc);
|
|
|
|
|
index[count++]->setType(TType(EbtFloat, EvqTemporary, 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create expression as:
|
|
|
|
|
// (sampleCount == 2) ? pos2[idx] :
|
|
|
|
|
// (sampleCount == 4) ? pos4[idx] :
|
|
|
|
|
// (sampleCount == 8) ? pos8[idx] :
|
|
|
|
|
// (sampleCount == 16) ? pos16[idx] : float2(0,0);
|
|
|
|
|
TIntermTyped* test =
|
|
|
|
|
intermediate.addSelection(idxtest[0], index[0],
|
|
|
|
|
intermediate.addSelection(idxtest[1], index[1],
|
|
|
|
|
intermediate.addSelection(idxtest[2], index[2],
|
|
|
|
|
intermediate.addSelection(idxtest[3], index[3],
|
|
|
|
|
getSamplePosArray(1), loc), loc), loc), loc);
|
|
|
|
|
|
|
|
|
|
compoundStatement = intermediate.growAggregate(compoundStatement, test);
|
|
|
|
|
compoundStatement->setOperator(EOpSequence);
|
|
|
|
|
compoundStatement->setLoc(loc);
|
|
|
|
|
compoundStatement->setType(TType(EbtFloat, EvqTemporary, 2));
|
|
|
|
|
|
|
|
|
|
node = compoundStatement;
|
|
|
|
|
|
2016-07-26 14:57:53 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 19:26:59 +00:00
|
|
|
|
default:
|
|
|
|
|
break; // most pass through unchanged
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 22:04:20 +00:00
|
|
|
|
//
|
|
|
|
|
// Decompose geometry shader methods
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::decomposeGeometryMethods(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments)
|
|
|
|
|
{
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (node == nullptr || !node->getAsOperator())
|
2016-11-17 22:04:20 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const TOperator op = node->getAsOperator()->getOp();
|
|
|
|
|
const TIntermAggregate* argAggregate = arguments ? arguments->getAsAggregate() : nullptr;
|
|
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case EOpMethodAppend:
|
|
|
|
|
if (argAggregate) {
|
2017-05-13 15:20:11 +00:00
|
|
|
|
// Don't emit these for non-GS stage, since we won't have the gsStreamOutput symbol.
|
|
|
|
|
if (language != EShLangGeometry) {
|
|
|
|
|
node = nullptr;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 22:04:20 +00:00
|
|
|
|
TIntermAggregate* sequence = nullptr;
|
|
|
|
|
TIntermAggregate* emit = new TIntermAggregate(EOpEmitVertex);
|
|
|
|
|
|
|
|
|
|
emit->setLoc(loc);
|
|
|
|
|
emit->setType(TType(EbtVoid));
|
|
|
|
|
|
2017-03-30 02:01:13 +00:00
|
|
|
|
// find the matching output
|
|
|
|
|
if (gsStreamOutput == nullptr) {
|
|
|
|
|
error(loc, "unable to find output symbol for Append()", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 22:04:20 +00:00
|
|
|
|
sequence = intermediate.growAggregate(sequence,
|
2017-01-06 07:34:48 +00:00
|
|
|
|
handleAssign(loc, EOpAssign,
|
2017-03-30 02:01:13 +00:00
|
|
|
|
intermediate.addSymbol(*gsStreamOutput, loc),
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
argAggregate->getSequence()[1]->getAsTyped()),
|
2016-11-17 22:04:20 +00:00
|
|
|
|
loc);
|
|
|
|
|
|
|
|
|
|
sequence = intermediate.growAggregate(sequence, emit);
|
|
|
|
|
|
|
|
|
|
sequence->setOperator(EOpSequence);
|
|
|
|
|
sequence->setLoc(loc);
|
|
|
|
|
sequence->setType(TType(EbtVoid));
|
|
|
|
|
node = sequence;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EOpMethodRestartStrip:
|
|
|
|
|
{
|
2017-05-13 15:20:11 +00:00
|
|
|
|
// Don't emit these for non-GS stage, since we won't have the gsStreamOutput symbol.
|
|
|
|
|
if (language != EShLangGeometry) {
|
|
|
|
|
node = nullptr;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 22:04:20 +00:00
|
|
|
|
TIntermAggregate* cut = new TIntermAggregate(EOpEndPrimitive);
|
|
|
|
|
cut->setLoc(loc);
|
|
|
|
|
cut->setType(TType(EbtVoid));
|
|
|
|
|
node = cut;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break; // most pass through unchanged
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 19:26:59 +00:00
|
|
|
|
//
|
2016-06-09 14:57:35 +00:00
|
|
|
|
// Optionally decompose intrinsics to AST opcodes.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::decomposeIntrinsic(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments)
|
|
|
|
|
{
|
2016-10-19 16:15:25 +00:00
|
|
|
|
// Helper to find image data for image atomics:
|
|
|
|
|
// OpImageLoad(image[idx])
|
|
|
|
|
// We take the image load apart and add its params to the atomic op aggregate node
|
|
|
|
|
const auto imageAtomicParams = [this, &loc, &node](TIntermAggregate* atomic, TIntermTyped* load) {
|
|
|
|
|
TIntermAggregate* loadOp = load->getAsAggregate();
|
|
|
|
|
if (loadOp == nullptr) {
|
|
|
|
|
error(loc, "unknown image type in atomic operation", "", "");
|
|
|
|
|
node = nullptr;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
atomic->getSequence().push_back(loadOp->getSequence()[0]);
|
|
|
|
|
atomic->getSequence().push_back(loadOp->getSequence()[1]);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Return true if this is an imageLoad, which we will change to an image atomic.
|
2016-10-28 15:57:25 +00:00
|
|
|
|
const auto isImageParam = [](TIntermTyped* image) -> bool {
|
2016-10-19 16:15:25 +00:00
|
|
|
|
TIntermAggregate* imageAggregate = image->getAsAggregate();
|
|
|
|
|
return imageAggregate != nullptr && imageAggregate->getOp() == EOpImageLoad;
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-09 14:57:35 +00:00
|
|
|
|
// HLSL intrinsics can be pass through to native AST opcodes, or decomposed here to existing AST
|
|
|
|
|
// opcodes for compatibility with existing software stacks.
|
|
|
|
|
static const bool decomposeHlslIntrinsics = true;
|
|
|
|
|
|
|
|
|
|
if (!decomposeHlslIntrinsics || !node || !node->getAsOperator())
|
|
|
|
|
return;
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-06-09 14:57:35 +00:00
|
|
|
|
const TIntermAggregate* argAggregate = arguments ? arguments->getAsAggregate() : nullptr;
|
|
|
|
|
TIntermUnary* fnUnary = node->getAsUnaryNode();
|
|
|
|
|
const TOperator op = node->getAsOperator()->getOp();
|
|
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case EOpGenMul:
|
|
|
|
|
{
|
|
|
|
|
// mul(a,b) -> MatrixTimesMatrix, MatrixTimesVector, MatrixTimesScalar, VectorTimesScalar, Dot, Mul
|
2016-08-24 20:36:13 +00:00
|
|
|
|
// Since we are treating HLSL rows like GLSL columns (the first matrix indirection),
|
|
|
|
|
// we must reverse the operand order here. Hence, arg0 gets sequence[1], etc.
|
|
|
|
|
TIntermTyped* arg0 = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
TIntermTyped* arg1 = argAggregate->getSequence()[0]->getAsTyped();
|
2016-06-09 14:57:35 +00:00
|
|
|
|
|
|
|
|
|
if (arg0->isVector() && arg1->isVector()) { // vec * vec
|
|
|
|
|
node->getAsAggregate()->setOperator(EOpDot);
|
|
|
|
|
} else {
|
|
|
|
|
node = handleBinaryMath(loc, "mul", EOpMul, arg0, arg1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpRcp:
|
|
|
|
|
{
|
|
|
|
|
// rcp(a) -> 1 / a
|
|
|
|
|
TIntermTyped* arg0 = fnUnary->getOperand();
|
|
|
|
|
TBasicType type0 = arg0->getBasicType();
|
|
|
|
|
TIntermTyped* one = intermediate.addConstantUnion(1, type0, loc, true);
|
|
|
|
|
node = handleBinaryMath(loc, "rcp", EOpDiv, one, arg0);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-05 18:07:16 +00:00
|
|
|
|
case EOpAny: // fall through
|
|
|
|
|
case EOpAll:
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* typedArg = arguments->getAsTyped();
|
|
|
|
|
|
|
|
|
|
// HLSL allows float/etc types here, and the SPIR-V opcode requires a bool.
|
|
|
|
|
// We'll convert here. Note that for efficiency, we could add a smarter
|
|
|
|
|
// decomposition for some type cases, e.g, maybe by decomposing a dot product.
|
|
|
|
|
if (typedArg->getType().getBasicType() != EbtBool) {
|
|
|
|
|
const TType boolType(EbtBool, EvqTemporary,
|
|
|
|
|
typedArg->getVectorSize(),
|
|
|
|
|
typedArg->getMatrixCols(),
|
|
|
|
|
typedArg->getMatrixRows(),
|
|
|
|
|
typedArg->isVector());
|
|
|
|
|
|
|
|
|
|
typedArg = intermediate.addConversion(EOpConstructBool, boolType, typedArg);
|
|
|
|
|
node->getAsUnaryNode()->setOperand(typedArg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-09 14:57:35 +00:00
|
|
|
|
case EOpSaturate:
|
|
|
|
|
{
|
|
|
|
|
// saturate(a) -> clamp(a,0,1)
|
|
|
|
|
TIntermTyped* arg0 = fnUnary->getOperand();
|
|
|
|
|
TBasicType type0 = arg0->getBasicType();
|
|
|
|
|
TIntermAggregate* clamp = new TIntermAggregate(EOpClamp);
|
|
|
|
|
|
|
|
|
|
clamp->getSequence().push_back(arg0);
|
|
|
|
|
clamp->getSequence().push_back(intermediate.addConstantUnion(0, type0, loc, true));
|
|
|
|
|
clamp->getSequence().push_back(intermediate.addConstantUnion(1, type0, loc, true));
|
|
|
|
|
clamp->setLoc(loc);
|
|
|
|
|
clamp->setType(node->getType());
|
2016-06-13 15:22:28 +00:00
|
|
|
|
clamp->getWritableType().getQualifier().makeTemporary();
|
2016-06-09 14:57:35 +00:00
|
|
|
|
node = clamp;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpSinCos:
|
|
|
|
|
{
|
|
|
|
|
// sincos(a,b,c) -> b = sin(a), c = cos(a)
|
|
|
|
|
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
TIntermTyped* arg2 = argAggregate->getSequence()[2]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
TIntermTyped* sinStatement = handleUnaryMath(loc, "sin", EOpSin, arg0);
|
|
|
|
|
TIntermTyped* cosStatement = handleUnaryMath(loc, "cos", EOpCos, arg0);
|
|
|
|
|
TIntermTyped* sinAssign = intermediate.addAssign(EOpAssign, arg1, sinStatement, loc);
|
|
|
|
|
TIntermTyped* cosAssign = intermediate.addAssign(EOpAssign, arg2, cosStatement, loc);
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* compoundStatement = intermediate.makeAggregate(sinAssign, loc);
|
|
|
|
|
compoundStatement = intermediate.growAggregate(compoundStatement, cosAssign);
|
|
|
|
|
compoundStatement->setOperator(EOpSequence);
|
|
|
|
|
compoundStatement->setLoc(loc);
|
2016-06-20 19:26:59 +00:00
|
|
|
|
compoundStatement->setType(TType(EbtVoid));
|
2016-06-09 14:57:35 +00:00
|
|
|
|
|
|
|
|
|
node = compoundStatement;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpClip:
|
|
|
|
|
{
|
|
|
|
|
// clip(a) -> if (any(a<0)) discard;
|
|
|
|
|
TIntermTyped* arg0 = fnUnary->getOperand();
|
|
|
|
|
TBasicType type0 = arg0->getBasicType();
|
|
|
|
|
TIntermTyped* compareNode = nullptr;
|
|
|
|
|
|
|
|
|
|
// For non-scalars: per experiment with FXC compiler, discard if any component < 0.
|
|
|
|
|
if (!arg0->isScalar()) {
|
|
|
|
|
// component-wise compare: a < 0
|
|
|
|
|
TIntermAggregate* less = new TIntermAggregate(EOpLessThan);
|
|
|
|
|
less->getSequence().push_back(arg0);
|
|
|
|
|
less->setLoc(loc);
|
|
|
|
|
|
|
|
|
|
// make vec or mat of bool matching dimensions of input
|
|
|
|
|
less->setType(TType(EbtBool, EvqTemporary,
|
|
|
|
|
arg0->getType().getVectorSize(),
|
|
|
|
|
arg0->getType().getMatrixCols(),
|
|
|
|
|
arg0->getType().getMatrixRows(),
|
|
|
|
|
arg0->getType().isVector()));
|
|
|
|
|
|
|
|
|
|
// calculate # of components for comparison const
|
2017-01-06 07:34:48 +00:00
|
|
|
|
const int constComponentCount =
|
2016-06-09 14:57:35 +00:00
|
|
|
|
std::max(arg0->getType().getVectorSize(), 1) *
|
|
|
|
|
std::max(arg0->getType().getMatrixCols(), 1) *
|
|
|
|
|
std::max(arg0->getType().getMatrixRows(), 1);
|
|
|
|
|
|
|
|
|
|
TConstUnion zero;
|
|
|
|
|
zero.setDConst(0.0);
|
|
|
|
|
TConstUnionArray zeros(constComponentCount, zero);
|
|
|
|
|
|
|
|
|
|
less->getSequence().push_back(intermediate.addConstantUnion(zeros, arg0->getType(), loc, true));
|
|
|
|
|
|
|
|
|
|
compareNode = intermediate.addBuiltInFunctionCall(loc, EOpAny, true, less, TType(EbtBool));
|
|
|
|
|
} else {
|
|
|
|
|
TIntermTyped* zero = intermediate.addConstantUnion(0, type0, loc, true);
|
|
|
|
|
compareNode = handleBinaryMath(loc, "clip", EOpLessThan, arg0, zero);
|
|
|
|
|
}
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-06-09 14:57:35 +00:00
|
|
|
|
TIntermBranch* killNode = intermediate.addBranch(EOpKill, loc);
|
|
|
|
|
|
|
|
|
|
node = new TIntermSelection(compareNode, killNode, nullptr);
|
|
|
|
|
node->setLoc(loc);
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-06-09 14:57:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpLog10:
|
|
|
|
|
{
|
|
|
|
|
// log10(a) -> log2(a) * 0.301029995663981 (== 1/log2(10))
|
|
|
|
|
TIntermTyped* arg0 = fnUnary->getOperand();
|
|
|
|
|
TIntermTyped* log2 = handleUnaryMath(loc, "log2", EOpLog2, arg0);
|
|
|
|
|
TIntermTyped* base = intermediate.addConstantUnion(0.301029995663981f, EbtFloat, loc, true);
|
|
|
|
|
|
|
|
|
|
node = handleBinaryMath(loc, "mul", EOpMul, log2, base);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpDst:
|
|
|
|
|
{
|
|
|
|
|
// dest.x = 1;
|
|
|
|
|
// dest.y = src0.y * src1.y;
|
|
|
|
|
// dest.z = src0.z;
|
|
|
|
|
// dest.w = src1.w;
|
|
|
|
|
|
|
|
|
|
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
TIntermTyped* y = intermediate.addConstantUnion(1, loc, true);
|
|
|
|
|
TIntermTyped* z = intermediate.addConstantUnion(2, loc, true);
|
|
|
|
|
TIntermTyped* w = intermediate.addConstantUnion(3, loc, true);
|
|
|
|
|
|
|
|
|
|
TIntermTyped* src0y = intermediate.addIndex(EOpIndexDirect, arg0, y, loc);
|
|
|
|
|
TIntermTyped* src1y = intermediate.addIndex(EOpIndexDirect, arg1, y, loc);
|
|
|
|
|
TIntermTyped* src0z = intermediate.addIndex(EOpIndexDirect, arg0, z, loc);
|
|
|
|
|
TIntermTyped* src1w = intermediate.addIndex(EOpIndexDirect, arg1, w, loc);
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* dst = new TIntermAggregate(EOpConstructVec4);
|
|
|
|
|
|
|
|
|
|
dst->getSequence().push_back(intermediate.addConstantUnion(1.0, EbtFloat, loc, true));
|
|
|
|
|
dst->getSequence().push_back(handleBinaryMath(loc, "mul", EOpMul, src0y, src1y));
|
|
|
|
|
dst->getSequence().push_back(src0z);
|
|
|
|
|
dst->getSequence().push_back(src1w);
|
2016-06-15 15:50:24 +00:00
|
|
|
|
dst->setType(TType(EbtFloat, EvqTemporary, 4));
|
2016-06-09 14:57:35 +00:00
|
|
|
|
dst->setLoc(loc);
|
|
|
|
|
node = dst;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-13 15:22:28 +00:00
|
|
|
|
case EOpInterlockedAdd: // optional last argument (if present) is assigned from return value
|
|
|
|
|
case EOpInterlockedMin: // ...
|
|
|
|
|
case EOpInterlockedMax: // ...
|
|
|
|
|
case EOpInterlockedAnd: // ...
|
|
|
|
|
case EOpInterlockedOr: // ...
|
|
|
|
|
case EOpInterlockedXor: // ...
|
|
|
|
|
case EOpInterlockedExchange: // always has output arg
|
|
|
|
|
{
|
2016-10-19 16:15:25 +00:00
|
|
|
|
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped(); // dest
|
|
|
|
|
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped(); // value
|
|
|
|
|
TIntermTyped* arg2 = nullptr;
|
2016-06-13 15:22:28 +00:00
|
|
|
|
|
2016-10-19 16:15:25 +00:00
|
|
|
|
if (argAggregate->getSequence().size() > 2)
|
|
|
|
|
arg2 = argAggregate->getSequence()[2]->getAsTyped();
|
2016-06-13 15:22:28 +00:00
|
|
|
|
|
2016-10-19 16:15:25 +00:00
|
|
|
|
const bool isImage = isImageParam(arg0);
|
|
|
|
|
const TOperator atomicOp = mapAtomicOp(loc, op, isImage);
|
|
|
|
|
TIntermAggregate* atomic = new TIntermAggregate(atomicOp);
|
|
|
|
|
atomic->setType(arg0->getType());
|
|
|
|
|
atomic->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
atomic->setLoc(loc);
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-10-19 16:15:25 +00:00
|
|
|
|
if (isImage) {
|
|
|
|
|
// orig_value = imageAtomicOp(image, loc, data)
|
|
|
|
|
imageAtomicParams(atomic, arg0);
|
2016-06-13 15:22:28 +00:00
|
|
|
|
atomic->getSequence().push_back(arg1);
|
|
|
|
|
|
2016-10-19 16:15:25 +00:00
|
|
|
|
if (argAggregate->getSequence().size() > 2) {
|
|
|
|
|
node = intermediate.addAssign(EOpAssign, arg2, atomic, loc);
|
|
|
|
|
} else {
|
|
|
|
|
node = atomic; // no assignment needed, as there was no out var.
|
|
|
|
|
}
|
2016-06-13 15:22:28 +00:00
|
|
|
|
} else {
|
2016-10-19 16:15:25 +00:00
|
|
|
|
// Normal memory variable:
|
|
|
|
|
// arg0 = mem, arg1 = data, arg2(optional,out) = orig_value
|
|
|
|
|
if (argAggregate->getSequence().size() > 2) {
|
|
|
|
|
// optional output param is present. return value goes to arg2.
|
|
|
|
|
atomic->getSequence().push_back(arg0);
|
|
|
|
|
atomic->getSequence().push_back(arg1);
|
|
|
|
|
|
|
|
|
|
node = intermediate.addAssign(EOpAssign, arg2, atomic, loc);
|
|
|
|
|
} else {
|
|
|
|
|
// Set the matching operator. Since output is absent, this is all we need to do.
|
|
|
|
|
node->getAsAggregate()->setOperator(atomicOp);
|
|
|
|
|
}
|
2016-06-13 15:22:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpInterlockedCompareExchange:
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped(); // dest
|
|
|
|
|
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped(); // cmp
|
|
|
|
|
TIntermTyped* arg2 = argAggregate->getSequence()[2]->getAsTyped(); // value
|
|
|
|
|
TIntermTyped* arg3 = argAggregate->getSequence()[3]->getAsTyped(); // orig
|
|
|
|
|
|
2016-10-19 16:15:25 +00:00
|
|
|
|
const bool isImage = isImageParam(arg0);
|
2016-06-13 15:22:28 +00:00
|
|
|
|
TIntermAggregate* atomic = new TIntermAggregate(mapAtomicOp(loc, op, isImage));
|
|
|
|
|
atomic->setLoc(loc);
|
|
|
|
|
atomic->setType(arg2->getType());
|
|
|
|
|
atomic->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
|
2016-10-19 16:15:25 +00:00
|
|
|
|
if (isImage) {
|
|
|
|
|
imageAtomicParams(atomic, arg0);
|
|
|
|
|
} else {
|
|
|
|
|
atomic->getSequence().push_back(arg0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
atomic->getSequence().push_back(arg1);
|
|
|
|
|
atomic->getSequence().push_back(arg2);
|
2016-06-13 15:22:28 +00:00
|
|
|
|
node = intermediate.addAssign(EOpAssign, arg3, atomic, loc);
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-06-13 15:22:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 15:50:24 +00:00
|
|
|
|
case EOpEvaluateAttributeSnapped:
|
|
|
|
|
{
|
|
|
|
|
// SPIR-V InterpolateAtOffset uses float vec2 offset in pixels
|
|
|
|
|
// HLSL uses int2 offset on a 16x16 grid in [-8..7] on x & y:
|
|
|
|
|
// iU = (iU<<28)>>28
|
|
|
|
|
// fU = ((float)iU)/16
|
|
|
|
|
// Targets might handle this natively, in which case they can disable
|
|
|
|
|
// decompositions.
|
|
|
|
|
|
|
|
|
|
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped(); // value
|
|
|
|
|
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped(); // offset
|
|
|
|
|
|
|
|
|
|
TIntermTyped* i28 = intermediate.addConstantUnion(28, loc, true);
|
|
|
|
|
TIntermTyped* iU = handleBinaryMath(loc, ">>", EOpRightShift,
|
|
|
|
|
handleBinaryMath(loc, "<<", EOpLeftShift, arg1, i28),
|
|
|
|
|
i28);
|
|
|
|
|
|
|
|
|
|
TIntermTyped* recip16 = intermediate.addConstantUnion((1.0/16.0), EbtFloat, loc, true);
|
|
|
|
|
TIntermTyped* floatOffset = handleBinaryMath(loc, "mul", EOpMul,
|
|
|
|
|
intermediate.addConversion(EOpConstructFloat,
|
|
|
|
|
TType(EbtFloat, EvqTemporary, 2), iU),
|
|
|
|
|
recip16);
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-06-15 15:50:24 +00:00
|
|
|
|
TIntermAggregate* interp = new TIntermAggregate(EOpInterpolateAtOffset);
|
|
|
|
|
interp->getSequence().push_back(arg0);
|
|
|
|
|
interp->getSequence().push_back(floatOffset);
|
|
|
|
|
interp->setLoc(loc);
|
|
|
|
|
interp->setType(arg0->getType());
|
|
|
|
|
interp->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
|
|
|
|
|
node = interp;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpLit:
|
|
|
|
|
{
|
|
|
|
|
TIntermTyped* n_dot_l = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* n_dot_h = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
TIntermTyped* m = argAggregate->getSequence()[2]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* dst = new TIntermAggregate(EOpConstructVec4);
|
|
|
|
|
|
|
|
|
|
// Ambient
|
|
|
|
|
dst->getSequence().push_back(intermediate.addConstantUnion(1.0, EbtFloat, loc, true));
|
|
|
|
|
|
|
|
|
|
// Diffuse:
|
|
|
|
|
TIntermTyped* zero = intermediate.addConstantUnion(0.0, EbtFloat, loc, true);
|
|
|
|
|
TIntermAggregate* diffuse = new TIntermAggregate(EOpMax);
|
|
|
|
|
diffuse->getSequence().push_back(n_dot_l);
|
|
|
|
|
diffuse->getSequence().push_back(zero);
|
|
|
|
|
diffuse->setLoc(loc);
|
|
|
|
|
diffuse->setType(TType(EbtFloat));
|
|
|
|
|
dst->getSequence().push_back(diffuse);
|
|
|
|
|
|
|
|
|
|
// Specular:
|
|
|
|
|
TIntermAggregate* min_ndot = new TIntermAggregate(EOpMin);
|
|
|
|
|
min_ndot->getSequence().push_back(n_dot_l);
|
|
|
|
|
min_ndot->getSequence().push_back(n_dot_h);
|
|
|
|
|
min_ndot->setLoc(loc);
|
|
|
|
|
min_ndot->setType(TType(EbtFloat));
|
|
|
|
|
|
|
|
|
|
TIntermTyped* compare = handleBinaryMath(loc, "<", EOpLessThan, min_ndot, zero);
|
|
|
|
|
TIntermTyped* n_dot_h_m = handleBinaryMath(loc, "mul", EOpMul, n_dot_h, m); // n_dot_h * m
|
|
|
|
|
|
|
|
|
|
dst->getSequence().push_back(intermediate.addSelection(compare, zero, n_dot_h_m, loc));
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-06-15 15:50:24 +00:00
|
|
|
|
// One:
|
|
|
|
|
dst->getSequence().push_back(intermediate.addConstantUnion(1.0, EbtFloat, loc, true));
|
|
|
|
|
|
|
|
|
|
dst->setLoc(loc);
|
|
|
|
|
dst->setType(TType(EbtFloat, EvqTemporary, 4));
|
|
|
|
|
node = dst;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-22 21:20:14 +00:00
|
|
|
|
case EOpAsDouble:
|
|
|
|
|
{
|
|
|
|
|
// asdouble accepts two 32 bit ints. we can use EOpUint64BitsToDouble, but must
|
|
|
|
|
// first construct a uint64.
|
|
|
|
|
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped();
|
|
|
|
|
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped();
|
|
|
|
|
|
|
|
|
|
if (arg0->getType().isVector()) { // TODO: ...
|
|
|
|
|
error(loc, "double2 conversion not implemented", "asdouble", "");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* uint64 = new TIntermAggregate(EOpConstructUVec2);
|
|
|
|
|
|
|
|
|
|
uint64->getSequence().push_back(arg0);
|
|
|
|
|
uint64->getSequence().push_back(arg1);
|
|
|
|
|
uint64->setType(TType(EbtUint, EvqTemporary, 2)); // convert 2 uints to a uint2
|
|
|
|
|
uint64->setLoc(loc);
|
|
|
|
|
|
|
|
|
|
// bitcast uint2 to a double
|
|
|
|
|
TIntermTyped* convert = new TIntermUnary(EOpUint64BitsToDouble);
|
|
|
|
|
convert->getAsUnaryNode()->setOperand(uint64);
|
|
|
|
|
convert->setLoc(loc);
|
|
|
|
|
convert->setType(TType(EbtDouble, EvqTemporary));
|
|
|
|
|
node = convert;
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-06-22 21:20:14 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-06-15 15:50:24 +00:00
|
|
|
|
case EOpF16tof32:
|
2017-02-27 20:09:32 +00:00
|
|
|
|
{
|
|
|
|
|
// input uvecN with low 16 bits of each component holding a float16. convert to float32.
|
|
|
|
|
TIntermTyped* argValue = node->getAsUnaryNode()->getOperand();
|
2017-02-28 21:14:14 +00:00
|
|
|
|
TIntermTyped* zero = intermediate.addConstantUnion(0, loc, true);
|
2017-02-27 20:09:32 +00:00
|
|
|
|
const int vecSize = argValue->getType().getVectorSize();
|
|
|
|
|
|
|
|
|
|
TOperator constructOp = EOpNull;
|
|
|
|
|
switch (vecSize) {
|
|
|
|
|
case 1: constructOp = EOpNull; break; // direct use, no construct needed
|
|
|
|
|
case 2: constructOp = EOpConstructVec2; break;
|
|
|
|
|
case 3: constructOp = EOpConstructVec3; break;
|
|
|
|
|
case 4: constructOp = EOpConstructVec4; break;
|
|
|
|
|
default: assert(0); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For scalar case, we don't need to construct another type.
|
|
|
|
|
TIntermAggregate* result = (vecSize > 1) ? new TIntermAggregate(constructOp) : nullptr;
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
result->setType(TType(EbtFloat, EvqTemporary, vecSize));
|
|
|
|
|
result->setLoc(loc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < vecSize; ++idx) {
|
|
|
|
|
TIntermTyped* idxConst = intermediate.addConstantUnion(idx, loc, true);
|
|
|
|
|
TIntermTyped* component = argValue->getType().isVector() ?
|
|
|
|
|
intermediate.addIndex(EOpIndexDirect, argValue, idxConst, loc) : argValue;
|
|
|
|
|
|
|
|
|
|
if (component != argValue)
|
|
|
|
|
component->setType(TType(argValue->getBasicType(), EvqTemporary));
|
|
|
|
|
|
|
|
|
|
TIntermTyped* unpackOp = new TIntermUnary(EOpUnpackHalf2x16);
|
|
|
|
|
unpackOp->setType(TType(EbtFloat, EvqTemporary, 2));
|
|
|
|
|
unpackOp->getAsUnaryNode()->setOperand(component);
|
|
|
|
|
unpackOp->setLoc(loc);
|
|
|
|
|
|
|
|
|
|
TIntermTyped* lowOrder = intermediate.addIndex(EOpIndexDirect, unpackOp, zero, loc);
|
|
|
|
|
|
|
|
|
|
if (result != nullptr) {
|
|
|
|
|
result->getSequence().push_back(lowOrder);
|
|
|
|
|
node = result;
|
|
|
|
|
} else {
|
|
|
|
|
node = lowOrder;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 15:50:24 +00:00
|
|
|
|
case EOpF32tof16:
|
|
|
|
|
{
|
2017-02-27 20:09:32 +00:00
|
|
|
|
// input floatN converted to 16 bit float in low order bits of each component of uintN
|
|
|
|
|
TIntermTyped* argValue = node->getAsUnaryNode()->getOperand();
|
|
|
|
|
|
|
|
|
|
TIntermTyped* zero = intermediate.addConstantUnion(0.0, EbtFloat, loc, true);
|
|
|
|
|
const int vecSize = argValue->getType().getVectorSize();
|
|
|
|
|
|
|
|
|
|
TOperator constructOp = EOpNull;
|
|
|
|
|
switch (vecSize) {
|
|
|
|
|
case 1: constructOp = EOpNull; break; // direct use, no construct needed
|
|
|
|
|
case 2: constructOp = EOpConstructUVec2; break;
|
|
|
|
|
case 3: constructOp = EOpConstructUVec3; break;
|
|
|
|
|
case 4: constructOp = EOpConstructUVec4; break;
|
|
|
|
|
default: assert(0); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For scalar case, we don't need to construct another type.
|
|
|
|
|
TIntermAggregate* result = (vecSize > 1) ? new TIntermAggregate(constructOp) : nullptr;
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
result->setType(TType(EbtUint, EvqTemporary, vecSize));
|
|
|
|
|
result->setLoc(loc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < vecSize; ++idx) {
|
|
|
|
|
TIntermTyped* idxConst = intermediate.addConstantUnion(idx, loc, true);
|
|
|
|
|
TIntermTyped* component = argValue->getType().isVector() ?
|
|
|
|
|
intermediate.addIndex(EOpIndexDirect, argValue, idxConst, loc) : argValue;
|
|
|
|
|
|
|
|
|
|
if (component != argValue)
|
|
|
|
|
component->setType(TType(argValue->getBasicType(), EvqTemporary));
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* vec2ComponentAndZero = new TIntermAggregate(EOpConstructVec2);
|
|
|
|
|
vec2ComponentAndZero->getSequence().push_back(component);
|
|
|
|
|
vec2ComponentAndZero->getSequence().push_back(zero);
|
|
|
|
|
vec2ComponentAndZero->setType(TType(EbtFloat, EvqTemporary, 2));
|
|
|
|
|
vec2ComponentAndZero->setLoc(loc);
|
|
|
|
|
|
|
|
|
|
TIntermTyped* packOp = new TIntermUnary(EOpPackHalf2x16);
|
|
|
|
|
packOp->getAsUnaryNode()->setOperand(vec2ComponentAndZero);
|
|
|
|
|
packOp->setLoc(loc);
|
|
|
|
|
packOp->setType(TType(EbtUint, EvqTemporary));
|
|
|
|
|
|
|
|
|
|
if (result != nullptr) {
|
|
|
|
|
result->getSequence().push_back(packOp);
|
|
|
|
|
node = result;
|
|
|
|
|
} else {
|
|
|
|
|
node = packOp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 15:50:24 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-03 21:42:18 +00:00
|
|
|
|
case EOpD3DCOLORtoUBYTE4:
|
|
|
|
|
{
|
|
|
|
|
// ivec4 ( x.zyxw * 255.001953 );
|
|
|
|
|
TIntermTyped* arg0 = node->getAsUnaryNode()->getOperand();
|
2017-01-14 02:34:22 +00:00
|
|
|
|
TSwizzleSelectors<TVectorSelector> selectors;
|
|
|
|
|
selectors.push_back(2);
|
|
|
|
|
selectors.push_back(1);
|
|
|
|
|
selectors.push_back(0);
|
|
|
|
|
selectors.push_back(3);
|
|
|
|
|
TIntermTyped* swizzleIdx = intermediate.addSwizzle(selectors, loc);
|
2017-01-03 21:42:18 +00:00
|
|
|
|
TIntermTyped* swizzled = intermediate.addIndex(EOpVectorSwizzle, arg0, swizzleIdx, loc);
|
|
|
|
|
swizzled->setType(arg0->getType());
|
|
|
|
|
swizzled->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
|
|
|
|
|
TIntermTyped* conversion = intermediate.addConstantUnion(255.001953f, EbtFloat, loc, true);
|
|
|
|
|
TIntermTyped* rangeConverted = handleBinaryMath(loc, "mul", EOpMul, conversion, swizzled);
|
|
|
|
|
rangeConverted->setType(arg0->getType());
|
|
|
|
|
rangeConverted->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
|
|
|
|
|
node = intermediate.addConversion(EOpConstructInt, TType(EbtInt, EvqTemporary, 4), rangeConverted);
|
|
|
|
|
node->setLoc(loc);
|
|
|
|
|
node->setType(TType(EbtInt, EvqTemporary, 4));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 02:05:21 +00:00
|
|
|
|
case EOpIsFinite:
|
|
|
|
|
{
|
|
|
|
|
// Since OPIsFinite in SPIR-V is only supported with the Kernel capability, we translate
|
|
|
|
|
// it to !isnan && !isinf
|
|
|
|
|
|
|
|
|
|
TIntermTyped* arg0 = node->getAsUnaryNode()->getOperand();
|
|
|
|
|
|
|
|
|
|
// We'll make a temporary in case the RHS is cmoplex
|
|
|
|
|
TVariable* tempArg = makeInternalVariable("@finitetmp", arg0->getType());
|
|
|
|
|
tempArg->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
|
|
|
|
|
TIntermTyped* tmpArgAssign = intermediate.addAssign(EOpAssign,
|
|
|
|
|
intermediate.addSymbol(*tempArg, loc),
|
|
|
|
|
arg0, loc);
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* compoundStatement = intermediate.makeAggregate(tmpArgAssign, loc);
|
|
|
|
|
|
2017-07-28 22:20:13 +00:00
|
|
|
|
const TType boolType(EbtBool, EvqTemporary, arg0->getVectorSize(), arg0->getMatrixCols(),
|
|
|
|
|
arg0->getMatrixRows());
|
2017-04-10 14:27:34 +00:00
|
|
|
|
|
2017-04-04 02:05:21 +00:00
|
|
|
|
TIntermTyped* isnan = handleUnaryMath(loc, "isnan", EOpIsNan, intermediate.addSymbol(*tempArg, loc));
|
2017-04-10 14:27:34 +00:00
|
|
|
|
isnan->setType(boolType);
|
2017-04-04 02:05:21 +00:00
|
|
|
|
|
|
|
|
|
TIntermTyped* notnan = handleUnaryMath(loc, "!", EOpLogicalNot, isnan);
|
2017-04-10 14:27:34 +00:00
|
|
|
|
notnan->setType(boolType);
|
2017-04-04 02:05:21 +00:00
|
|
|
|
|
|
|
|
|
TIntermTyped* isinf = handleUnaryMath(loc, "isinf", EOpIsInf, intermediate.addSymbol(*tempArg, loc));
|
2017-04-10 14:27:34 +00:00
|
|
|
|
isinf->setType(boolType);
|
2017-04-04 02:05:21 +00:00
|
|
|
|
|
|
|
|
|
TIntermTyped* notinf = handleUnaryMath(loc, "!", EOpLogicalNot, isinf);
|
2017-04-10 14:27:34 +00:00
|
|
|
|
notinf->setType(boolType);
|
2017-04-04 02:05:21 +00:00
|
|
|
|
|
|
|
|
|
TIntermTyped* andNode = handleBinaryMath(loc, "and", EOpLogicalAnd, notnan, notinf);
|
2017-04-10 14:27:34 +00:00
|
|
|
|
andNode->setType(boolType);
|
2017-04-04 02:05:21 +00:00
|
|
|
|
|
|
|
|
|
compoundStatement = intermediate.growAggregate(compoundStatement, andNode);
|
|
|
|
|
compoundStatement->setOperator(EOpSequence);
|
|
|
|
|
compoundStatement->setLoc(loc);
|
2017-04-10 14:27:34 +00:00
|
|
|
|
compoundStatement->setType(boolType);
|
2017-04-04 02:05:21 +00:00
|
|
|
|
|
|
|
|
|
node = compoundStatement;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-09 14:57:35 +00:00
|
|
|
|
default:
|
|
|
|
|
break; // most pass through unchanged
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Handle seeing function call syntax in the grammar, which could be any of
|
|
|
|
|
// - .length() method
|
|
|
|
|
// - constructor
|
|
|
|
|
// - a call to a built-in function mapped to an operator
|
|
|
|
|
// - a call to a built-in function that will remain a function call (e.g., texturing)
|
|
|
|
|
// - user function
|
|
|
|
|
// - subroutine call (not implemented yet)
|
|
|
|
|
//
|
2016-12-24 01:56:57 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction* function, TIntermTyped* arguments)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
TIntermTyped* result = nullptr;
|
|
|
|
|
|
|
|
|
|
TOperator op = function->getBuiltInOp();
|
2017-03-09 04:16:35 +00:00
|
|
|
|
if (op != EOpNull) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Then this should be a constructor.
|
|
|
|
|
// Don't go through the symbol table for constructors.
|
|
|
|
|
// Their parameters will be verified algorithmically.
|
|
|
|
|
//
|
|
|
|
|
TType type(EbtVoid); // use this to get the type back
|
|
|
|
|
if (! constructorError(loc, arguments, *function, op, type)) {
|
|
|
|
|
//
|
|
|
|
|
// It's a constructor, of type 'type'.
|
|
|
|
|
//
|
2017-04-04 03:48:37 +00:00
|
|
|
|
result = handleConstructor(loc, arguments, type);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (result == nullptr)
|
|
|
|
|
error(loc, "cannot construct with these arguments", type.getCompleteString().c_str(), "");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//
|
|
|
|
|
// Find it in the symbol table.
|
|
|
|
|
//
|
2017-02-13 00:50:28 +00:00
|
|
|
|
const TFunction* fnCandidate = nullptr;
|
2017-02-28 14:01:43 +00:00
|
|
|
|
bool builtIn = false;
|
2017-05-17 05:16:26 +00:00
|
|
|
|
int thisDepth = 0;
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
2017-04-27 17:22:32 +00:00
|
|
|
|
TIntermAggregate* aggregate = arguments ? arguments->getAsAggregate() : nullptr;
|
|
|
|
|
|
2017-02-13 00:50:28 +00:00
|
|
|
|
// TODO: this needs improvement: there's no way at present to look up a signature in
|
|
|
|
|
// the symbol table for an arbitrary type. This is a temporary hack until that ability exists.
|
|
|
|
|
// It will have false positives, since it doesn't check arg counts or types.
|
2017-04-10 14:19:21 +00:00
|
|
|
|
if (arguments) {
|
|
|
|
|
// Check if first argument is struct buffer type. It may be an aggregate or a symbol, so we
|
|
|
|
|
// look for either case.
|
|
|
|
|
|
|
|
|
|
TIntermTyped* arg0 = nullptr;
|
2017-03-31 18:47:34 +00:00
|
|
|
|
|
2017-04-27 17:22:32 +00:00
|
|
|
|
if (aggregate && aggregate->getSequence().size() > 0)
|
|
|
|
|
arg0 = aggregate->getSequence()[0]->getAsTyped();
|
2017-04-10 14:19:21 +00:00
|
|
|
|
else if (arguments->getAsSymbolNode())
|
|
|
|
|
arg0 = arguments->getAsSymbolNode();
|
|
|
|
|
|
|
|
|
|
if (arg0 != nullptr && isStructBufferType(arg0->getType())) {
|
2017-03-20 00:12:37 +00:00
|
|
|
|
static const int methodPrefixSize = sizeof(BUILTIN_PREFIX)-1;
|
|
|
|
|
|
|
|
|
|
if (function->getName().length() > methodPrefixSize &&
|
|
|
|
|
isStructBufferMethod(function->getName().substr(methodPrefixSize))) {
|
2017-02-13 00:50:28 +00:00
|
|
|
|
const TString mangle = function->getName() + "(";
|
|
|
|
|
TSymbol* symbol = symbolTable.find(mangle, &builtIn);
|
|
|
|
|
|
|
|
|
|
if (symbol)
|
|
|
|
|
fnCandidate = symbol->getAsFunction();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fnCandidate == nullptr)
|
2017-05-17 05:16:26 +00:00
|
|
|
|
fnCandidate = findFunction(loc, *function, builtIn, thisDepth, arguments);
|
2017-02-13 00:50:28 +00:00
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (fnCandidate) {
|
|
|
|
|
// This is a declared function that might map to
|
|
|
|
|
// - a built-in operator,
|
|
|
|
|
// - a built-in function not mapped to an operator, or
|
|
|
|
|
// - a user function.
|
|
|
|
|
|
|
|
|
|
// Error check for a function requiring specific extensions present.
|
|
|
|
|
if (builtIn && fnCandidate->getNumExtensions())
|
2017-07-28 22:20:13 +00:00
|
|
|
|
requireExtensions(loc, fnCandidate->getNumExtensions(), fnCandidate->getExtensions(),
|
|
|
|
|
fnCandidate->getName().c_str());
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
2017-05-17 05:16:26 +00:00
|
|
|
|
// turn an implicit member-function resolution into an explicit call
|
|
|
|
|
TString callerName;
|
|
|
|
|
if (thisDepth == 0)
|
|
|
|
|
callerName = fnCandidate->getMangledName();
|
|
|
|
|
else {
|
|
|
|
|
// get the explicit (full) name of the function
|
|
|
|
|
callerName = currentTypePrefix[currentTypePrefix.size() - thisDepth];
|
|
|
|
|
callerName += fnCandidate->getMangledName();
|
|
|
|
|
// insert the implicit calling argument
|
|
|
|
|
pushFrontArguments(intermediate.addSymbol(*getImplicitThis(thisDepth)), arguments);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 06:01:36 +00:00
|
|
|
|
// Convert 'in' arguments, so that types match.
|
|
|
|
|
// However, skip those that need expansion, that is covered next.
|
2016-10-01 23:11:21 +00:00
|
|
|
|
if (arguments)
|
|
|
|
|
addInputArgumentConversions(*fnCandidate, arguments);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
2017-05-26 06:01:36 +00:00
|
|
|
|
// Expand arguments. Some arguments must physically expand to a different set
|
|
|
|
|
// than what the shader declared and passes.
|
|
|
|
|
if (arguments && !builtIn)
|
|
|
|
|
expandArguments(loc, *fnCandidate, arguments);
|
|
|
|
|
|
|
|
|
|
// Expansion may have changed the form of arguments
|
|
|
|
|
aggregate = arguments ? arguments->getAsAggregate() : nullptr;
|
2017-04-27 17:22:32 +00:00
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
op = fnCandidate->getBuiltInOp();
|
|
|
|
|
if (builtIn && op != EOpNull) {
|
|
|
|
|
// A function call mapped to a built-in operation.
|
2017-07-28 22:20:13 +00:00
|
|
|
|
result = intermediate.addBuiltInFunctionCall(loc, op, fnCandidate->getParamCount() == 1, arguments,
|
|
|
|
|
fnCandidate->getType());
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (result == nullptr) {
|
|
|
|
|
error(arguments->getLoc(), " wrong operand type", "Internal Error",
|
|
|
|
|
"built in unary operator function. Type: %s",
|
|
|
|
|
static_cast<TIntermTyped*>(arguments)->getCompleteString().c_str());
|
|
|
|
|
} else if (result->getAsOperator()) {
|
|
|
|
|
builtInOpCheck(loc, *fnCandidate, *result->getAsOperator());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// This is a function call not mapped to built-in operator.
|
|
|
|
|
// It could still be a built-in function, but only if PureOperatorBuiltins == false.
|
|
|
|
|
result = intermediate.setAggregateOperator(arguments, EOpFunctionCall, fnCandidate->getType(), loc);
|
|
|
|
|
TIntermAggregate* call = result->getAsAggregate();
|
2017-05-17 05:16:26 +00:00
|
|
|
|
call->setName(callerName);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
// this is how we know whether the given function is a built-in function or a user-defined function
|
|
|
|
|
// if builtIn == false, it's a userDefined -> could be an overloaded built-in function also
|
|
|
|
|
// if builtIn == true, it's definitely a built-in function with EOpNull
|
|
|
|
|
if (! builtIn) {
|
|
|
|
|
call->setUserDefined();
|
2017-05-17 05:16:26 +00:00
|
|
|
|
intermediate.addToCallGraph(infoSink, currentCaller, callerName);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
// for decompositions, since we want to operate on the function node, not the aggregate holding
|
|
|
|
|
// output conversions.
|
2017-01-06 07:34:48 +00:00
|
|
|
|
const TIntermTyped* fnNode = result;
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
|
2017-02-13 00:50:28 +00:00
|
|
|
|
decomposeStructBufferMethods(loc, result, arguments); // HLSL->AST struct buffer method decompositions
|
|
|
|
|
decomposeIntrinsic(loc, result, arguments); // HLSL->AST intrinsic decompositions
|
|
|
|
|
decomposeSampleMethods(loc, result, arguments); // HLSL->AST sample method decompositions
|
|
|
|
|
decomposeGeometryMethods(loc, result, arguments); // HLSL->AST geometry method decompositions
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
|
2017-05-26 06:01:36 +00:00
|
|
|
|
// Create the qualifier list, carried in the AST for the call.
|
|
|
|
|
// Because some arguments expand to multiple arguments, the qualifier list will
|
|
|
|
|
// be longer than the formal parameter list.
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
if (result == fnNode && result->getAsAggregate()) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
TQualifierList& qualifierList = result->getAsAggregate()->getQualifierList();
|
|
|
|
|
for (int i = 0; i < fnCandidate->getParamCount(); ++i) {
|
|
|
|
|
TStorageQualifier qual = (*fnCandidate)[i].type->getQualifier().storage;
|
2017-05-26 06:01:36 +00:00
|
|
|
|
if (hasStructBuffCounter(*(*fnCandidate)[i].type)) {
|
|
|
|
|
// add buffer and counter buffer argument qualifier
|
|
|
|
|
qualifierList.push_back(qual);
|
|
|
|
|
qualifierList.push_back(qual);
|
|
|
|
|
} else if (shouldFlatten(*(*fnCandidate)[i].type)) {
|
|
|
|
|
// add structure member expansion
|
|
|
|
|
for (int memb = 0; memb < (int)(*fnCandidate)[i].type->getStruct()->size(); ++memb)
|
|
|
|
|
qualifierList.push_back(qual);
|
|
|
|
|
} else {
|
|
|
|
|
// Normal 1:1 case
|
2017-04-27 17:22:32 +00:00
|
|
|
|
qualifierList.push_back(qual);
|
2017-05-26 06:01:36 +00:00
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
2017-05-26 06:01:36 +00:00
|
|
|
|
}
|
2017-04-27 17:22:32 +00:00
|
|
|
|
|
2017-05-26 06:01:36 +00:00
|
|
|
|
// Convert 'out' arguments. If it was a constant folded built-in, it won't be an aggregate anymore.
|
|
|
|
|
// Built-ins with a single argument aren't called with an aggregate, but they also don't have an output.
|
|
|
|
|
// Also, build the qualifier list for user function calls, which are always called with an aggregate.
|
|
|
|
|
// We don't do this is if there has been a decomposition, which will have added its own conversions
|
|
|
|
|
// for output parameters.
|
|
|
|
|
if (result == fnNode && result->getAsAggregate())
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
result = addOutputArgumentConversions(*fnCandidate, *result->getAsOperator());
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// generic error recovery
|
2017-07-28 22:20:13 +00:00
|
|
|
|
// TODO: simplification: localize all the error recoveries that look like this, and taking type into account to
|
|
|
|
|
// reduce cascades
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (result == nullptr)
|
|
|
|
|
result = intermediate.addConstantUnion(0.0, EbtFloat, loc);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-17 05:16:26 +00:00
|
|
|
|
// An initial argument list is difficult: it can be null, or a single node,
|
|
|
|
|
// or an aggregate if more than one argument. Add one to the front, maintaining
|
|
|
|
|
// this lack of uniformity.
|
|
|
|
|
void HlslParseContext::pushFrontArguments(TIntermTyped* front, TIntermTyped*& arguments)
|
|
|
|
|
{
|
|
|
|
|
if (arguments == nullptr)
|
|
|
|
|
arguments = front;
|
|
|
|
|
else if (arguments->getAsAggregate() != nullptr)
|
|
|
|
|
arguments->getAsAggregate()->getSequence().insert(arguments->getAsAggregate()->getSequence().begin(), front);
|
|
|
|
|
else
|
|
|
|
|
arguments = intermediate.growAggregate(front, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Add any needed implicit conversions for function-call arguments to input parameters.
|
|
|
|
|
//
|
2016-12-24 01:56:57 +00:00
|
|
|
|
void HlslParseContext::addInputArgumentConversions(const TFunction& function, TIntermTyped*& arguments)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
TIntermAggregate* aggregate = arguments->getAsAggregate();
|
2017-05-26 06:01:36 +00:00
|
|
|
|
|
|
|
|
|
// Replace a single argument with a single argument.
|
|
|
|
|
const auto setArg = [&](int paramNum, TIntermTyped* arg) {
|
2016-09-19 06:06:19 +00:00
|
|
|
|
if (function.getParamCount() == 1)
|
|
|
|
|
arguments = arg;
|
|
|
|
|
else {
|
2017-05-26 06:01:36 +00:00
|
|
|
|
if (aggregate == nullptr)
|
2016-09-19 06:06:19 +00:00
|
|
|
|
arguments = arg;
|
2017-05-26 06:01:36 +00:00
|
|
|
|
else
|
|
|
|
|
aggregate->getSequence()[paramNum] = arg;
|
2016-09-19 06:06:19 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
// Process each argument's conversion
|
2017-05-26 06:01:36 +00:00
|
|
|
|
for (int param = 0; param < function.getParamCount(); ++param) {
|
|
|
|
|
if (! function[param].type->getQualifier().isParamInput())
|
2016-10-01 19:30:37 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// At this early point there is a slight ambiguity between whether an aggregate 'arguments'
|
|
|
|
|
// is the single argument itself or its children are the arguments. Only one argument
|
|
|
|
|
// means take 'arguments' itself as the one argument.
|
2016-10-01 23:11:21 +00:00
|
|
|
|
TIntermTyped* arg = function.getParamCount() == 1
|
|
|
|
|
? arguments->getAsTyped()
|
2017-05-26 06:01:36 +00:00
|
|
|
|
: (aggregate ?
|
|
|
|
|
aggregate->getSequence()[param]->getAsTyped() :
|
|
|
|
|
arguments->getAsTyped());
|
|
|
|
|
if (*function[param].type != arg->getType()) {
|
2016-10-01 19:30:37 +00:00
|
|
|
|
// In-qualified arguments just need an extra node added above the argument to
|
|
|
|
|
// convert to the correct type.
|
2017-05-26 06:01:36 +00:00
|
|
|
|
TIntermTyped* convArg = intermediate.addConversion(EOpFunctionCall, *function[param].type, arg);
|
2016-12-15 00:02:32 +00:00
|
|
|
|
if (convArg != nullptr)
|
2017-05-26 06:01:36 +00:00
|
|
|
|
convArg = intermediate.addUniShapeConversion(EOpFunctionCall, *function[param].type, convArg);
|
2016-12-15 00:02:32 +00:00
|
|
|
|
if (convArg != nullptr)
|
2017-05-26 06:01:36 +00:00
|
|
|
|
setArg(param, convArg);
|
2016-12-15 00:02:32 +00:00
|
|
|
|
else
|
2017-05-26 06:01:36 +00:00
|
|
|
|
error(arg->getLoc(), "cannot convert input argument, argument", "", "%d", param);
|
2016-09-19 06:06:19 +00:00
|
|
|
|
} else {
|
2017-07-30 22:54:02 +00:00
|
|
|
|
if (wasFlattened(arg)) {
|
2017-05-26 06:01:36 +00:00
|
|
|
|
// If both formal and calling arg are to be flattened, leave that to argument
|
|
|
|
|
// expansion, not conversion.
|
|
|
|
|
if (!shouldFlatten(*function[param].type)) {
|
|
|
|
|
// Will make a two-level subtree.
|
|
|
|
|
// The deepest will copy member-by-member to build the structure to pass.
|
|
|
|
|
// The level above that will be a two-operand EOpComma sequence that follows the copy by the
|
|
|
|
|
// object itself.
|
|
|
|
|
TVariable* internalAggregate = makeInternalVariable("aggShadow", *function[param].type);
|
|
|
|
|
internalAggregate->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
TIntermSymbol* internalSymbolNode = new TIntermSymbol(internalAggregate->getUniqueId(),
|
|
|
|
|
internalAggregate->getName(),
|
|
|
|
|
internalAggregate->getType());
|
|
|
|
|
internalSymbolNode->setLoc(arg->getLoc());
|
|
|
|
|
// This makes the deepest level, the member-wise copy
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermAggregate* assignAgg = handleAssign(arg->getLoc(), EOpAssign,
|
|
|
|
|
internalSymbolNode, arg)->getAsAggregate();
|
2017-05-26 06:01:36 +00:00
|
|
|
|
|
|
|
|
|
// Now, pair that with the resulting aggregate.
|
|
|
|
|
assignAgg = intermediate.growAggregate(assignAgg, internalSymbolNode, arg->getLoc());
|
|
|
|
|
assignAgg->setOperator(EOpComma);
|
|
|
|
|
assignAgg->setType(internalAggregate->getType());
|
|
|
|
|
setArg(param, assignAgg);
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 06:01:36 +00:00
|
|
|
|
//
|
|
|
|
|
// Add any needed implicit expansion of calling arguments from what the shader listed to what's
|
|
|
|
|
// internally needed for the AST (given the constraints downstream).
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::expandArguments(const TSourceLoc& loc, const TFunction& function, TIntermTyped*& arguments)
|
|
|
|
|
{
|
|
|
|
|
TIntermAggregate* aggregate = arguments->getAsAggregate();
|
|
|
|
|
int functionParamNumberOffset = 0;
|
|
|
|
|
|
|
|
|
|
// Replace a single argument with a single argument.
|
|
|
|
|
const auto setArg = [&](int paramNum, TIntermTyped* arg) {
|
|
|
|
|
if (function.getParamCount() + functionParamNumberOffset == 1)
|
|
|
|
|
arguments = arg;
|
|
|
|
|
else {
|
|
|
|
|
if (aggregate == nullptr)
|
|
|
|
|
arguments = arg;
|
|
|
|
|
else
|
|
|
|
|
aggregate->getSequence()[paramNum] = arg;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Replace a single argument with a list of arguments
|
|
|
|
|
const auto setArgList = [&](int paramNum, const TVector<TIntermTyped*>& args) {
|
|
|
|
|
if (args.size() == 1)
|
|
|
|
|
setArg(paramNum, args.front());
|
|
|
|
|
else {
|
|
|
|
|
if (function.getParamCount() + functionParamNumberOffset == 1) {
|
|
|
|
|
arguments = intermediate.makeAggregate(args.front());
|
|
|
|
|
std::for_each(args.begin() + 1, args.end(),
|
|
|
|
|
[&](TIntermTyped* arg) {
|
|
|
|
|
arguments = intermediate.growAggregate(arguments, arg);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
auto it = aggregate->getSequence().erase(aggregate->getSequence().begin() + paramNum);
|
|
|
|
|
aggregate->getSequence().insert(it, args.begin(), args.end());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
functionParamNumberOffset += (args.size() - 1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Process each argument's conversion
|
|
|
|
|
for (int param = 0; param < function.getParamCount(); ++param) {
|
|
|
|
|
// At this early point there is a slight ambiguity between whether an aggregate 'arguments'
|
|
|
|
|
// is the single argument itself or its children are the arguments. Only one argument
|
|
|
|
|
// means take 'arguments' itself as the one argument.
|
|
|
|
|
TIntermTyped* arg = function.getParamCount() == 1
|
|
|
|
|
? arguments->getAsTyped()
|
|
|
|
|
: (aggregate ?
|
|
|
|
|
aggregate->getSequence()[param + functionParamNumberOffset]->getAsTyped() :
|
|
|
|
|
arguments->getAsTyped());
|
|
|
|
|
|
|
|
|
|
if (wasFlattened(arg) && shouldFlatten(*function[param].type)) {
|
|
|
|
|
// Need to pass the structure members instead of the structure.
|
|
|
|
|
TVector<TIntermTyped*> memberArgs;
|
2017-06-29 23:43:31 +00:00
|
|
|
|
for (int memb = 0; memb < (int)arg->getType().getStruct()->size(); ++memb)
|
2017-05-26 06:01:36 +00:00
|
|
|
|
memberArgs.push_back(flattenAccess(arg, memb));
|
|
|
|
|
setArgList(param + functionParamNumberOffset, memberArgs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: if we need both hidden counter args (below) and struct expansion (above)
|
|
|
|
|
// the two algorithms need to be merged: Each assumes the list starts out 1:1 between
|
|
|
|
|
// parameters and arguments.
|
|
|
|
|
|
|
|
|
|
// If any argument is a pass-by-reference struct buffer with an associated counter
|
|
|
|
|
// buffer, we have to add another hidden parameter for that counter.
|
|
|
|
|
if (aggregate)
|
|
|
|
|
addStructBuffArguments(loc, aggregate);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Add any needed implicit output conversions for function-call arguments. This
|
|
|
|
|
// can require a new tree topology, complicated further by whether the function
|
|
|
|
|
// has a return value.
|
|
|
|
|
//
|
|
|
|
|
// Returns a node of a subtree that evaluates to the return value of the function.
|
|
|
|
|
//
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::addOutputArgumentConversions(const TFunction& function, TIntermOperator& intermNode)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
assert (intermNode.getAsAggregate() != nullptr || intermNode.getAsUnaryNode() != nullptr);
|
|
|
|
|
|
|
|
|
|
const TSourceLoc& loc = intermNode.getLoc();
|
|
|
|
|
|
|
|
|
|
TIntermSequence argSequence; // temp sequence for unary node args
|
|
|
|
|
|
|
|
|
|
if (intermNode.getAsUnaryNode())
|
|
|
|
|
argSequence.push_back(intermNode.getAsUnaryNode()->getOperand());
|
|
|
|
|
|
|
|
|
|
TIntermSequence& arguments = argSequence.empty() ? intermNode.getAsAggregate()->getSequence() : argSequence;
|
|
|
|
|
|
2016-10-01 23:11:21 +00:00
|
|
|
|
const auto needsConversion = [&](int argNum) {
|
|
|
|
|
return function[argNum].type->getQualifier().isParamOutput() &&
|
|
|
|
|
(*function[argNum].type != arguments[argNum]->getAsTyped()->getType() ||
|
2016-10-08 01:35:40 +00:00
|
|
|
|
shouldConvertLValue(arguments[argNum]) ||
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
wasFlattened(arguments[argNum]->getAsTyped()));
|
2016-10-01 23:11:21 +00:00
|
|
|
|
};
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
// Will there be any output conversions?
|
|
|
|
|
bool outputConversions = false;
|
|
|
|
|
for (int i = 0; i < function.getParamCount(); ++i) {
|
2016-10-01 23:11:21 +00:00
|
|
|
|
if (needsConversion(i)) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
outputConversions = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! outputConversions)
|
|
|
|
|
return &intermNode;
|
|
|
|
|
|
|
|
|
|
// Setup for the new tree, if needed:
|
|
|
|
|
//
|
|
|
|
|
// Output conversions need a different tree topology.
|
|
|
|
|
// Out-qualified arguments need a temporary of the correct type, with the call
|
|
|
|
|
// followed by an assignment of the temporary to the original argument:
|
|
|
|
|
// void: function(arg, ...) -> ( function(tempArg, ...), arg = tempArg, ...)
|
|
|
|
|
// ret = function(arg, ...) -> ret = (tempRet = function(tempArg, ...), arg = tempArg, ..., tempRet)
|
|
|
|
|
// Where the "tempArg" type needs no conversion as an argument, but will convert on assignment.
|
|
|
|
|
TIntermTyped* conversionTree = nullptr;
|
|
|
|
|
TVariable* tempRet = nullptr;
|
|
|
|
|
if (intermNode.getBasicType() != EbtVoid) {
|
|
|
|
|
// do the "tempRet = function(...), " bit from above
|
|
|
|
|
tempRet = makeInternalVariable("tempReturn", intermNode.getType());
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
TIntermSymbol* tempRetNode = intermediate.addSymbol(*tempRet, loc);
|
|
|
|
|
conversionTree = intermediate.addAssign(EOpAssign, tempRetNode, &intermNode, loc);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
} else
|
|
|
|
|
conversionTree = &intermNode;
|
|
|
|
|
|
|
|
|
|
conversionTree = intermediate.makeAggregate(conversionTree);
|
|
|
|
|
|
|
|
|
|
// Process each argument's conversion
|
|
|
|
|
for (int i = 0; i < function.getParamCount(); ++i) {
|
2016-10-01 23:11:21 +00:00
|
|
|
|
if (needsConversion(i)) {
|
|
|
|
|
// Out-qualified arguments needing conversion need to use the topology setup above.
|
|
|
|
|
// Do the " ...(tempArg, ...), arg = tempArg" bit from above.
|
|
|
|
|
|
|
|
|
|
// Make a temporary for what the function expects the argument to look like.
|
|
|
|
|
TVariable* tempArg = makeInternalVariable("tempArg", *function[i].type);
|
|
|
|
|
tempArg->getWritableType().getQualifier().makeTemporary();
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
TIntermSymbol* tempArgNode = intermediate.addSymbol(*tempArg, loc);
|
2016-10-01 23:11:21 +00:00
|
|
|
|
|
|
|
|
|
// This makes the deepest level, the member-wise copy
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermTyped* tempAssign = handleAssign(arguments[i]->getLoc(), EOpAssign, arguments[i]->getAsTyped(),
|
|
|
|
|
tempArgNode);
|
2016-10-08 01:35:40 +00:00
|
|
|
|
tempAssign = handleLvalue(arguments[i]->getLoc(), "assign", tempAssign);
|
2016-10-01 23:11:21 +00:00
|
|
|
|
conversionTree = intermediate.growAggregate(conversionTree, tempAssign, arguments[i]->getLoc());
|
|
|
|
|
|
|
|
|
|
// replace the argument with another node for the same tempArg variable
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
arguments[i] = intermediate.addSymbol(*tempArg, loc);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finalize the tree topology (see bigger comment above).
|
|
|
|
|
if (tempRet) {
|
|
|
|
|
// do the "..., tempRet" bit from above
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
TIntermSymbol* tempRetNode = intermediate.addSymbol(*tempRet, loc);
|
|
|
|
|
conversionTree = intermediate.growAggregate(conversionTree, tempRetNode, loc);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
|
|
|
|
|
conversionTree = intermediate.setAggregateOperator(conversionTree, EOpComma, intermNode.getType(), loc);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
return conversionTree;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:22:32 +00:00
|
|
|
|
//
|
|
|
|
|
// Add any needed "hidden" counter buffer arguments for function calls.
|
|
|
|
|
//
|
|
|
|
|
// Modifies the 'aggregate' argument if needed. Otherwise, is no-op.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::addStructBuffArguments(const TSourceLoc& loc, TIntermAggregate*& aggregate)
|
|
|
|
|
{
|
|
|
|
|
// See if there are any SB types with counters.
|
|
|
|
|
const bool hasStructBuffArg =
|
|
|
|
|
std::any_of(aggregate->getSequence().begin(),
|
|
|
|
|
aggregate->getSequence().end(),
|
|
|
|
|
[this](const TIntermNode* node) {
|
|
|
|
|
return (node->getAsTyped() != nullptr) && hasStructBuffCounter(node->getAsTyped()->getType());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Nothing to do, if we didn't find one.
|
|
|
|
|
if (! hasStructBuffArg)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
TIntermSequence argsWithCounterBuffers;
|
|
|
|
|
|
2017-05-26 06:01:36 +00:00
|
|
|
|
for (int param = 0; param < int(aggregate->getSequence().size()); ++param) {
|
2017-04-27 17:22:32 +00:00
|
|
|
|
argsWithCounterBuffers.push_back(aggregate->getSequence()[param]);
|
|
|
|
|
|
|
|
|
|
if (hasStructBuffCounter(aggregate->getSequence()[param]->getAsTyped()->getType())) {
|
|
|
|
|
const TIntermSymbol* blockSym = aggregate->getSequence()[param]->getAsSymbolNode();
|
|
|
|
|
if (blockSym != nullptr) {
|
|
|
|
|
TType counterType;
|
|
|
|
|
counterBufferType(loc, counterType);
|
|
|
|
|
|
|
|
|
|
const TString counterBlockName(getStructBuffCounterName(blockSym->getName()));
|
|
|
|
|
|
|
|
|
|
TVariable* variable = makeInternalVariable(counterBlockName, counterType);
|
|
|
|
|
|
|
|
|
|
// Mark this buffer as requiring a counter block. TODO: there should be a better
|
|
|
|
|
// way to track it.
|
|
|
|
|
structBufferCounter[counterBlockName] = true;
|
|
|
|
|
|
|
|
|
|
TIntermSymbol* sym = intermediate.addSymbol(*variable, loc);
|
|
|
|
|
argsWithCounterBuffers.push_back(sym);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Swap with the temp list we've built up.
|
|
|
|
|
aggregate->getSequence().swap(argsWithCounterBuffers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Do additional checking of built-in function calls that is not caught
|
|
|
|
|
// by normal semantic checks on argument type, extension tagging, etc.
|
|
|
|
|
//
|
|
|
|
|
// Assumes there has been a semantically correct match to a built-in function prototype.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCandidate, TIntermOperator& callNode)
|
|
|
|
|
{
|
|
|
|
|
// Set up convenience accessors to the argument(s). There is almost always
|
|
|
|
|
// multiple arguments for the cases below, but when there might be one,
|
|
|
|
|
// check the unaryArg first.
|
|
|
|
|
const TIntermSequence* argp = nullptr; // confusing to use [] syntax on a pointer, so this is to help get a reference
|
|
|
|
|
const TIntermTyped* unaryArg = nullptr;
|
|
|
|
|
const TIntermTyped* arg0 = nullptr;
|
|
|
|
|
if (callNode.getAsAggregate()) {
|
|
|
|
|
argp = &callNode.getAsAggregate()->getSequence();
|
|
|
|
|
if (argp->size() > 0)
|
|
|
|
|
arg0 = (*argp)[0]->getAsTyped();
|
|
|
|
|
} else {
|
|
|
|
|
assert(callNode.getAsUnaryNode());
|
|
|
|
|
unaryArg = callNode.getAsUnaryNode()->getOperand();
|
|
|
|
|
arg0 = unaryArg;
|
|
|
|
|
}
|
|
|
|
|
const TIntermSequence& aggArgs = *argp; // only valid when unaryArg is nullptr
|
|
|
|
|
|
|
|
|
|
switch (callNode.getOp()) {
|
|
|
|
|
case EOpTextureGather:
|
|
|
|
|
case EOpTextureGatherOffset:
|
|
|
|
|
case EOpTextureGatherOffsets:
|
|
|
|
|
{
|
|
|
|
|
// Figure out which variants are allowed by what extensions,
|
|
|
|
|
// and what arguments must be constant for which situations.
|
|
|
|
|
|
|
|
|
|
TString featureString = fnCandidate.getName() + "(...)";
|
|
|
|
|
const char* feature = featureString.c_str();
|
|
|
|
|
int compArg = -1; // track which argument, if any, is the constant component argument
|
|
|
|
|
switch (callNode.getOp()) {
|
|
|
|
|
case EOpTextureGather:
|
|
|
|
|
// More than two arguments needs gpu_shader5, and rectangular or shadow needs gpu_shader5,
|
|
|
|
|
// otherwise, need GL_ARB_texture_gather.
|
2017-07-28 22:20:13 +00:00
|
|
|
|
if (fnCandidate.getParamCount() > 2 || fnCandidate[0].type->getSampler().dim == EsdRect ||
|
|
|
|
|
fnCandidate[0].type->getSampler().shadow) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (! fnCandidate[0].type->getSampler().shadow)
|
|
|
|
|
compArg = 2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EOpTextureGatherOffset:
|
|
|
|
|
// GL_ARB_texture_gather is good enough for 2D non-shadow textures with no component argument
|
|
|
|
|
if (! fnCandidate[0].type->getSampler().shadow)
|
|
|
|
|
compArg = 3;
|
|
|
|
|
break;
|
|
|
|
|
case EOpTextureGatherOffsets:
|
|
|
|
|
if (! fnCandidate[0].type->getSampler().shadow)
|
|
|
|
|
compArg = 3;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (compArg > 0 && compArg < fnCandidate.getParamCount()) {
|
|
|
|
|
if (aggArgs[compArg]->getAsConstantUnion()) {
|
|
|
|
|
int value = aggArgs[compArg]->getAsConstantUnion()->getConstArray()[0].getIConst();
|
|
|
|
|
if (value < 0 || value > 3)
|
|
|
|
|
error(loc, "must be 0, 1, 2, or 3:", feature, "component argument");
|
|
|
|
|
} else
|
|
|
|
|
error(loc, "must be a compile-time constant:", feature, "component argument");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpTextureOffset:
|
|
|
|
|
case EOpTextureFetchOffset:
|
|
|
|
|
case EOpTextureProjOffset:
|
|
|
|
|
case EOpTextureLodOffset:
|
|
|
|
|
case EOpTextureProjLodOffset:
|
|
|
|
|
case EOpTextureGradOffset:
|
|
|
|
|
case EOpTextureProjGradOffset:
|
|
|
|
|
{
|
|
|
|
|
// Handle texture-offset limits checking
|
|
|
|
|
// Pick which argument has to hold constant offsets
|
|
|
|
|
int arg = -1;
|
|
|
|
|
switch (callNode.getOp()) {
|
|
|
|
|
case EOpTextureOffset: arg = 2; break;
|
|
|
|
|
case EOpTextureFetchOffset: arg = (arg0->getType().getSampler().dim != EsdRect) ? 3 : 2; break;
|
|
|
|
|
case EOpTextureProjOffset: arg = 2; break;
|
|
|
|
|
case EOpTextureLodOffset: arg = 3; break;
|
|
|
|
|
case EOpTextureProjLodOffset: arg = 3; break;
|
|
|
|
|
case EOpTextureGradOffset: arg = 4; break;
|
|
|
|
|
case EOpTextureProjGradOffset: arg = 4; break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (arg > 0) {
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (aggArgs[arg]->getAsConstantUnion() == nullptr)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
error(loc, "argument must be compile-time constant", "texel offset", "");
|
|
|
|
|
else {
|
|
|
|
|
const TType& type = aggArgs[arg]->getAsTyped()->getType();
|
|
|
|
|
for (int c = 0; c < type.getVectorSize(); ++c) {
|
|
|
|
|
int offset = aggArgs[arg]->getAsConstantUnion()->getConstArray()[c].getIConst();
|
|
|
|
|
if (offset > resources.maxProgramTexelOffset || offset < resources.minProgramTexelOffset)
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "value is out of range:", "texel offset",
|
|
|
|
|
"[gl_MinProgramTexelOffset, gl_MaxProgramTexelOffset]");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EOpTextureQuerySamples:
|
|
|
|
|
case EOpImageQuerySamples:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EOpImageAtomicAdd:
|
|
|
|
|
case EOpImageAtomicMin:
|
|
|
|
|
case EOpImageAtomicMax:
|
|
|
|
|
case EOpImageAtomicAnd:
|
|
|
|
|
case EOpImageAtomicOr:
|
|
|
|
|
case EOpImageAtomicXor:
|
|
|
|
|
case EOpImageAtomicExchange:
|
|
|
|
|
case EOpImageAtomicCompSwap:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EOpInterpolateAtCentroid:
|
|
|
|
|
case EOpInterpolateAtSample:
|
|
|
|
|
case EOpInterpolateAtOffset:
|
|
|
|
|
// Make sure the first argument is an interpolant, or an array element of an interpolant
|
|
|
|
|
if (arg0->getType().getQualifier().storage != EvqVaryingIn) {
|
|
|
|
|
// It might still be an array element.
|
|
|
|
|
//
|
|
|
|
|
// We could check more, but the semantics of the first argument are already met; the
|
|
|
|
|
// only way to turn an array into a float/vec* is array dereference and swizzle.
|
|
|
|
|
//
|
|
|
|
|
// ES and desktop 4.3 and earlier: swizzles may not be used
|
|
|
|
|
// desktop 4.4 and later: swizzles may be used
|
|
|
|
|
const TIntermTyped* base = TIntermediate::findLValueBase(arg0, true);
|
|
|
|
|
if (base == nullptr || base->getType().getQualifier().storage != EvqVaryingIn)
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "first argument must be an interpolant, or interpolant-array element",
|
|
|
|
|
fnCandidate.getName().c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2017-04-04 03:48:37 +00:00
|
|
|
|
// Handle seeing something in a grammar production that can be done by calling
|
|
|
|
|
// a constructor.
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
2017-04-04 03:48:37 +00:00
|
|
|
|
// The constructor still must be "handled" by handleFunctionCall(), which will
|
|
|
|
|
// then call handleConstructor().
|
|
|
|
|
//
|
|
|
|
|
TFunction* HlslParseContext::makeConstructorCall(const TSourceLoc& loc, const TType& type)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
2016-07-28 21:29:35 +00:00
|
|
|
|
TOperator op = intermediate.mapTypeToConstructorOp(type);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
if (op == EOpNull) {
|
|
|
|
|
error(loc, "cannot construct this type", type.getBasicString(), "");
|
2016-03-13 17:24:20 +00:00
|
|
|
|
return nullptr;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TString empty("");
|
|
|
|
|
|
|
|
|
|
return new TFunction(&empty, type, op);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-13 05:52:12 +00:00
|
|
|
|
//
|
|
|
|
|
// Handle seeing a "COLON semantic" at the end of a type declaration,
|
|
|
|
|
// by updating the type according to the semantic.
|
|
|
|
|
//
|
2017-06-27 21:17:38 +00:00
|
|
|
|
void HlslParseContext::handleSemantic(TSourceLoc loc, TQualifier& qualifier, TBuiltInVariable builtIn,
|
|
|
|
|
const TString& upperCase)
|
2016-06-13 05:52:12 +00:00
|
|
|
|
{
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
// Parse and return semantic number. If limit is 0, it will be ignored. Otherwise, if the parsed
|
|
|
|
|
// semantic number is >= limit, errorMsg is issued and 0 is returned.
|
|
|
|
|
// TODO: it would be nicer if limit and errorMsg had default parameters, but some compilers don't yet
|
|
|
|
|
// accept those in lambda functions.
|
|
|
|
|
const auto getSemanticNumber = [this, loc](const TString& semantic, unsigned int limit, const char* errorMsg) -> unsigned int {
|
2017-06-27 21:17:38 +00:00
|
|
|
|
size_t pos = semantic.find_last_not_of("0123456789");
|
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
|
return 0u;
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
|
|
|
|
|
unsigned int semanticNum = (unsigned int)atoi(semantic.c_str() + pos + 1);
|
|
|
|
|
|
|
|
|
|
if (limit != 0 && semanticNum >= limit) {
|
|
|
|
|
error(loc, errorMsg, semantic.c_str(), "");
|
|
|
|
|
return 0u;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return semanticNum;
|
2017-06-27 21:17:38 +00:00
|
|
|
|
};
|
2016-08-25 15:59:17 +00:00
|
|
|
|
|
2017-03-09 21:37:32 +00:00
|
|
|
|
switch(builtIn) {
|
2017-06-27 21:17:38 +00:00
|
|
|
|
case EbvNone:
|
|
|
|
|
// Get location numbers from fragment outputs, instead of
|
|
|
|
|
// auto-assigning them.
|
|
|
|
|
if (language == EShLangFragment && upperCase.compare(0, 9, "SV_TARGET") == 0) {
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
qualifier.layoutLocation = getSemanticNumber(upperCase, 0, nullptr);
|
2017-06-27 21:17:38 +00:00
|
|
|
|
nextOutLocation = std::max(nextOutLocation, qualifier.layoutLocation + 1u);
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
} else if (upperCase.compare(0, 15, "SV_CLIPDISTANCE") == 0) {
|
|
|
|
|
builtIn = EbvClipDistance;
|
|
|
|
|
qualifier.layoutLocation = getSemanticNumber(upperCase, maxClipCullRegs, "invalid clip semantic");
|
|
|
|
|
} else if (upperCase.compare(0, 15, "SV_CULLDISTANCE") == 0) {
|
|
|
|
|
builtIn = EbvCullDistance;
|
|
|
|
|
qualifier.layoutLocation = getSemanticNumber(upperCase, maxClipCullRegs, "invalid cull semantic");
|
2017-06-27 21:17:38 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2017-03-09 21:37:32 +00:00
|
|
|
|
case EbvPosition:
|
2017-06-27 21:17:38 +00:00
|
|
|
|
// adjust for stage in/out
|
2017-03-09 21:37:32 +00:00
|
|
|
|
if (language == EShLangFragment)
|
|
|
|
|
builtIn = EbvFragCoord;
|
|
|
|
|
break;
|
2017-06-29 09:46:34 +00:00
|
|
|
|
case EbvFragStencilRef:
|
2016-10-16 18:12:11 +00:00
|
|
|
|
error(loc, "unimplemented; need ARB_shader_stencil_export", "SV_STENCILREF", "");
|
2017-03-09 21:37:32 +00:00
|
|
|
|
break;
|
2017-03-19 04:24:14 +00:00
|
|
|
|
case EbvTessLevelInner:
|
|
|
|
|
case EbvTessLevelOuter:
|
|
|
|
|
qualifier.patch = true;
|
|
|
|
|
break;
|
2017-03-09 21:37:32 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qualifier.builtIn = builtIn;
|
2017-03-15 03:50:06 +00:00
|
|
|
|
qualifier.semanticName = intermediate.addSemanticName(upperCase);
|
2016-06-13 05:52:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 19:03:05 +00:00
|
|
|
|
//
|
2016-07-29 20:28:39 +00:00
|
|
|
|
// Handle seeing something like "PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN"
|
2016-07-29 19:03:05 +00:00
|
|
|
|
//
|
|
|
|
|
// 'location' has the "c[Subcomponent]" part.
|
|
|
|
|
// 'component' points to the "component" part, or nullptr if not present.
|
|
|
|
|
//
|
2016-09-05 18:40:06 +00:00
|
|
|
|
void HlslParseContext::handlePackOffset(const TSourceLoc& loc, TQualifier& qualifier, const glslang::TString& location,
|
|
|
|
|
const glslang::TString* component)
|
2016-07-29 19:03:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (location.size() == 0 || location[0] != 'c') {
|
|
|
|
|
error(loc, "expected 'c'", "packoffset", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (location.size() == 1)
|
|
|
|
|
return;
|
|
|
|
|
if (! isdigit(location[1])) {
|
|
|
|
|
error(loc, "expected number after 'c'", "packoffset", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-05 18:40:06 +00:00
|
|
|
|
qualifier.layoutOffset = 16 * atoi(location.substr(1, location.size()).c_str());
|
2016-07-29 20:28:39 +00:00
|
|
|
|
if (component != nullptr) {
|
2016-07-29 19:03:05 +00:00
|
|
|
|
int componentOffset = 0;
|
|
|
|
|
switch ((*component)[0]) {
|
|
|
|
|
case 'x': componentOffset = 0; break;
|
|
|
|
|
case 'y': componentOffset = 4; break;
|
|
|
|
|
case 'z': componentOffset = 8; break;
|
|
|
|
|
case 'w': componentOffset = 12; break;
|
|
|
|
|
default:
|
|
|
|
|
componentOffset = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (componentOffset < 0 || component->size() > 1) {
|
|
|
|
|
error(loc, "expected {x, y, z, w} for component", "packoffset", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-09-05 18:40:06 +00:00
|
|
|
|
qualifier.layoutOffset += componentOffset;
|
2016-07-29 19:03:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 20:28:39 +00:00
|
|
|
|
//
|
|
|
|
|
// Handle seeing something like "REGISTER LEFT_PAREN [shader_profile,] Type# RIGHT_PAREN"
|
|
|
|
|
//
|
|
|
|
|
// 'profile' points to the shader_profile part, or nullptr if not present.
|
|
|
|
|
// 'desc' is the type# part.
|
|
|
|
|
//
|
2016-09-05 18:40:06 +00:00
|
|
|
|
void HlslParseContext::handleRegister(const TSourceLoc& loc, TQualifier& qualifier, const glslang::TString* profile,
|
2016-09-05 22:03:12 +00:00
|
|
|
|
const glslang::TString& desc, int subComponent, const glslang::TString* spaceDesc)
|
2016-07-29 20:28:39 +00:00
|
|
|
|
{
|
|
|
|
|
if (profile != nullptr)
|
|
|
|
|
warn(loc, "ignoring shader_profile", "register", "");
|
|
|
|
|
|
2016-07-30 16:29:54 +00:00
|
|
|
|
if (desc.size() < 1) {
|
|
|
|
|
error(loc, "expected register type", "register", "");
|
2016-07-29 20:28:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-30 16:29:54 +00:00
|
|
|
|
int regNumber = 0;
|
|
|
|
|
if (desc.size() > 1) {
|
|
|
|
|
if (isdigit(desc[1]))
|
|
|
|
|
regNumber = atoi(desc.substr(1, desc.size()).c_str());
|
|
|
|
|
else {
|
|
|
|
|
error(loc, "expected register number after register type", "register", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-07-29 20:28:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-30 16:29:54 +00:00
|
|
|
|
// TODO: learn what all these really mean and how they interact with regNumber and subComponent
|
2017-07-14 21:15:47 +00:00
|
|
|
|
const std::vector<std::string>& resourceInfo = intermediate.getResourceSetBinding();
|
2016-11-01 16:31:42 +00:00
|
|
|
|
switch (std::tolower(desc[0])) {
|
2016-07-29 20:28:39 +00:00
|
|
|
|
case 'b':
|
|
|
|
|
case 't':
|
|
|
|
|
case 'c':
|
|
|
|
|
case 's':
|
2016-11-01 16:31:42 +00:00
|
|
|
|
case 'u':
|
2016-09-05 18:40:06 +00:00
|
|
|
|
qualifier.layoutBinding = regNumber + subComponent;
|
2017-07-14 21:15:47 +00:00
|
|
|
|
|
|
|
|
|
// This handles per-register layout sets numbers. For the global mode which sets
|
|
|
|
|
// every symbol to the same value, see setLinkageLayoutSets().
|
|
|
|
|
if ((resourceInfo.size() % 3) == 0) {
|
|
|
|
|
// Apply per-symbol resource set and binding.
|
|
|
|
|
for (auto it = resourceInfo.cbegin(); it != resourceInfo.cend(); it = it + 3) {
|
|
|
|
|
if (strcmp(desc.c_str(), it[0].c_str()) == 0) {
|
|
|
|
|
qualifier.layoutSet = atoi(it[1].c_str());
|
|
|
|
|
qualifier.layoutBinding = atoi(it[2].c_str()) + subComponent;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-05-02 07:27:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-29 20:28:39 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
warn(loc, "ignoring unrecognized register type", "register", "%c", desc[0]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-09-05 22:03:12 +00:00
|
|
|
|
|
|
|
|
|
// space
|
|
|
|
|
unsigned int setNumber;
|
2016-10-13 17:23:39 +00:00
|
|
|
|
const auto crackSpace = [&]() -> bool {
|
2016-09-05 22:03:12 +00:00
|
|
|
|
const int spaceLen = 5;
|
|
|
|
|
if (spaceDesc->size() < spaceLen + 1)
|
|
|
|
|
return false;
|
|
|
|
|
if (spaceDesc->compare(0, spaceLen, "space") != 0)
|
|
|
|
|
return false;
|
|
|
|
|
if (! isdigit((*spaceDesc)[spaceLen]))
|
|
|
|
|
return false;
|
|
|
|
|
setNumber = atoi(spaceDesc->substr(spaceLen, spaceDesc->size()).c_str());
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (spaceDesc) {
|
|
|
|
|
if (! crackSpace()) {
|
|
|
|
|
error(loc, "expected spaceN", "register", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
qualifier.layoutSet = setNumber;
|
|
|
|
|
}
|
2016-07-29 20:28:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 04:09:30 +00:00
|
|
|
|
// Convert to a scalar boolean, or if not allowed by HLSL semantics,
|
|
|
|
|
// report an error and return nullptr.
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::convertConditionalExpression(const TSourceLoc& loc, TIntermTyped* condition,
|
|
|
|
|
bool mustBeScalar)
|
2017-03-31 04:09:30 +00:00
|
|
|
|
{
|
2017-04-12 01:45:00 +00:00
|
|
|
|
if (mustBeScalar && !condition->getType().isScalarOrVec1()) {
|
2017-03-31 04:09:30 +00:00
|
|
|
|
error(loc, "requires a scalar", "conditional expression", "");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-28 22:20:13 +00:00
|
|
|
|
return intermediate.addConversion(EOpConstructBool, TType(EbtBool, EvqTemporary, condition->getVectorSize()),
|
|
|
|
|
condition);
|
2017-03-31 04:09:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Same error message for all places assignments don't work.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::assignError(const TSourceLoc& loc, const char* op, TString left, TString right)
|
|
|
|
|
{
|
|
|
|
|
error(loc, "", op, "cannot convert from '%s' to '%s'",
|
|
|
|
|
right.c_str(), left.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Same error message for all places unary operations don't work.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::unaryOpError(const TSourceLoc& loc, const char* op, TString operand)
|
|
|
|
|
{
|
|
|
|
|
error(loc, " wrong operand type", op,
|
|
|
|
|
"no operation '%s' exists that takes an operand of type %s (or there is no acceptable conversion)",
|
|
|
|
|
op, operand.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Same error message for all binary operations don't work.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::binaryOpError(const TSourceLoc& loc, const char* op, TString left, TString right)
|
|
|
|
|
{
|
|
|
|
|
error(loc, " wrong operand types:", op,
|
|
|
|
|
"no operation '%s' exists that takes a left-hand operand of type '%s' and "
|
|
|
|
|
"a right operand of type '%s' (or there is no acceptable conversion)",
|
|
|
|
|
op, left.c_str(), right.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// A basic type of EbtVoid is a key that the name string was seen in the source, but
|
|
|
|
|
// it was not found as a variable in the symbol table. If so, give the error
|
|
|
|
|
// message and insert a dummy variable in the symbol table to prevent future errors.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::variableCheck(TIntermTyped*& nodePtr)
|
|
|
|
|
{
|
|
|
|
|
TIntermSymbol* symbol = nodePtr->getAsSymbolNode();
|
|
|
|
|
if (! symbol)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (symbol->getType().getBasicType() == EbtVoid) {
|
|
|
|
|
error(symbol->getLoc(), "undeclared identifier", symbol->getName().c_str(), "");
|
|
|
|
|
|
|
|
|
|
// Add to symbol table to prevent future error messages on the same name
|
|
|
|
|
if (symbol->getName().size() > 0) {
|
|
|
|
|
TVariable* fakeVariable = new TVariable(&symbol->getName(), TType(EbtFloat));
|
|
|
|
|
symbolTable.insert(*fakeVariable);
|
|
|
|
|
|
|
|
|
|
// substitute a symbol node for this new variable
|
|
|
|
|
nodePtr = intermediate.addSymbol(*fakeVariable, symbol->getLoc());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Both test, and if necessary spit out an error, to see if the node is really
|
|
|
|
|
// a constant.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::constantValueCheck(TIntermTyped* node, const char* token)
|
|
|
|
|
{
|
|
|
|
|
if (node->getQualifier().storage != EvqConst)
|
|
|
|
|
error(node->getLoc(), "constant expression required", token, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Both test, and if necessary spit out an error, to see if the node is really
|
|
|
|
|
// an integer.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::integerCheck(const TIntermTyped* node, const char* token)
|
|
|
|
|
{
|
|
|
|
|
if ((node->getBasicType() == EbtInt || node->getBasicType() == EbtUint) && node->isScalar())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error(node->getLoc(), "scalar integer expression required", token, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Both test, and if necessary spit out an error, to see if we are currently
|
|
|
|
|
// globally scoped.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::globalCheck(const TSourceLoc& loc, const char* token)
|
|
|
|
|
{
|
|
|
|
|
if (! symbolTable.atGlobalLevel())
|
|
|
|
|
error(loc, "not allowed in nested scope", token, "");
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-09 04:09:10 +00:00
|
|
|
|
bool HlslParseContext::builtInName(const TString& /*identifier*/)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Make sure there is enough data and not too many arguments provided to the
|
|
|
|
|
// constructor to build something of the type of the constructor. Also returns
|
|
|
|
|
// the type of the constructor.
|
|
|
|
|
//
|
|
|
|
|
// Returns true if there was an error in construction.
|
|
|
|
|
//
|
2016-11-28 05:51:36 +00:00
|
|
|
|
bool HlslParseContext::constructorError(const TSourceLoc& loc, TIntermNode* node, TFunction& function,
|
2016-07-09 04:09:10 +00:00
|
|
|
|
TOperator op, TType& type)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
type.shallowCopy(function.getType());
|
|
|
|
|
|
|
|
|
|
bool constructingMatrix = false;
|
|
|
|
|
switch (op) {
|
|
|
|
|
case EOpConstructTextureSampler:
|
|
|
|
|
return constructorTextureSamplerError(loc, function);
|
|
|
|
|
case EOpConstructMat2x2:
|
|
|
|
|
case EOpConstructMat2x3:
|
|
|
|
|
case EOpConstructMat2x4:
|
|
|
|
|
case EOpConstructMat3x2:
|
|
|
|
|
case EOpConstructMat3x3:
|
|
|
|
|
case EOpConstructMat3x4:
|
|
|
|
|
case EOpConstructMat4x2:
|
|
|
|
|
case EOpConstructMat4x3:
|
|
|
|
|
case EOpConstructMat4x4:
|
|
|
|
|
case EOpConstructDMat2x2:
|
|
|
|
|
case EOpConstructDMat2x3:
|
|
|
|
|
case EOpConstructDMat2x4:
|
|
|
|
|
case EOpConstructDMat3x2:
|
|
|
|
|
case EOpConstructDMat3x3:
|
|
|
|
|
case EOpConstructDMat3x4:
|
|
|
|
|
case EOpConstructDMat4x2:
|
|
|
|
|
case EOpConstructDMat4x3:
|
|
|
|
|
case EOpConstructDMat4x4:
|
2017-05-21 03:40:27 +00:00
|
|
|
|
case EOpConstructIMat2x2:
|
|
|
|
|
case EOpConstructIMat2x3:
|
|
|
|
|
case EOpConstructIMat2x4:
|
|
|
|
|
case EOpConstructIMat3x2:
|
|
|
|
|
case EOpConstructIMat3x3:
|
|
|
|
|
case EOpConstructIMat3x4:
|
|
|
|
|
case EOpConstructIMat4x2:
|
|
|
|
|
case EOpConstructIMat4x3:
|
|
|
|
|
case EOpConstructIMat4x4:
|
|
|
|
|
case EOpConstructUMat2x2:
|
|
|
|
|
case EOpConstructUMat2x3:
|
|
|
|
|
case EOpConstructUMat2x4:
|
|
|
|
|
case EOpConstructUMat3x2:
|
|
|
|
|
case EOpConstructUMat3x3:
|
|
|
|
|
case EOpConstructUMat3x4:
|
|
|
|
|
case EOpConstructUMat4x2:
|
|
|
|
|
case EOpConstructUMat4x3:
|
|
|
|
|
case EOpConstructUMat4x4:
|
|
|
|
|
case EOpConstructBMat2x2:
|
|
|
|
|
case EOpConstructBMat2x3:
|
|
|
|
|
case EOpConstructBMat2x4:
|
|
|
|
|
case EOpConstructBMat3x2:
|
|
|
|
|
case EOpConstructBMat3x3:
|
|
|
|
|
case EOpConstructBMat3x4:
|
|
|
|
|
case EOpConstructBMat4x2:
|
|
|
|
|
case EOpConstructBMat4x3:
|
|
|
|
|
case EOpConstructBMat4x4:
|
2016-03-13 03:11:22 +00:00
|
|
|
|
constructingMatrix = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Walk the arguments for first-pass checks and collection of information.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int size = 0;
|
|
|
|
|
bool constType = true;
|
|
|
|
|
bool full = false;
|
|
|
|
|
bool overFull = false;
|
|
|
|
|
bool matrixInMatrix = false;
|
|
|
|
|
bool arrayArg = false;
|
|
|
|
|
for (int arg = 0; arg < function.getParamCount(); ++arg) {
|
|
|
|
|
if (function[arg].type->isArray()) {
|
|
|
|
|
if (! function[arg].type->isExplicitlySizedArray()) {
|
|
|
|
|
// Can't construct from an unsized array.
|
|
|
|
|
error(loc, "array argument must be sized", "constructor", "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
arrayArg = true;
|
|
|
|
|
}
|
|
|
|
|
if (constructingMatrix && function[arg].type->isMatrix())
|
|
|
|
|
matrixInMatrix = true;
|
|
|
|
|
|
|
|
|
|
// 'full' will go to true when enough args have been seen. If we loop
|
|
|
|
|
// again, there is an extra argument.
|
|
|
|
|
if (full) {
|
|
|
|
|
// For vectors and matrices, it's okay to have too many components
|
|
|
|
|
// available, but not okay to have unused arguments.
|
|
|
|
|
overFull = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size += function[arg].type->computeNumComponents();
|
|
|
|
|
if (op != EOpConstructStruct && ! type.isArray() && size >= type.computeNumComponents())
|
|
|
|
|
full = true;
|
|
|
|
|
|
|
|
|
|
if (function[arg].type->getQualifier().storage != EvqConst)
|
|
|
|
|
constType = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (constType)
|
|
|
|
|
type.getQualifier().storage = EvqConst;
|
|
|
|
|
|
|
|
|
|
if (type.isArray()) {
|
|
|
|
|
if (function.getParamCount() == 0) {
|
|
|
|
|
error(loc, "array constructor must have at least one argument", "constructor", "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type.isImplicitlySizedArray()) {
|
|
|
|
|
// auto adapt the constructor type to the number of arguments
|
|
|
|
|
type.changeOuterArraySize(function.getParamCount());
|
2017-06-14 05:13:10 +00:00
|
|
|
|
} else if (type.getOuterArraySize() != function.getParamCount() &&
|
|
|
|
|
type.computeNumComponents() > size) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
error(loc, "array constructor needs one argument per array element", "constructor", "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type.isArrayOfArrays()) {
|
|
|
|
|
// Types have to match, but we're still making the type.
|
|
|
|
|
// Finish making the type, and the comparison is done later
|
|
|
|
|
// when checking for conversion.
|
|
|
|
|
TArraySizes& arraySizes = type.getArraySizes();
|
|
|
|
|
|
|
|
|
|
// At least the dimensionalities have to match.
|
2017-07-28 22:20:13 +00:00
|
|
|
|
if (! function[0].type->isArray() ||
|
|
|
|
|
arraySizes.getNumDims() != function[0].type->getArraySizes().getNumDims() + 1) {
|
2016-11-28 00:26:21 +00:00
|
|
|
|
error(loc, "array constructor argument not correct type to construct array element", "constructor", "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (arraySizes.isInnerImplicit()) {
|
|
|
|
|
// "Arrays of arrays ..., and the size for any dimension is optional"
|
|
|
|
|
// That means we need to adopt (from the first argument) the other array sizes into the type.
|
|
|
|
|
for (int d = 1; d < arraySizes.getNumDims(); ++d) {
|
|
|
|
|
if (arraySizes.getDimSize(d) == UnsizedArraySize) {
|
|
|
|
|
arraySizes.setDimSize(d, function[0].type->getArraySizes().getDimSize(d - 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 05:13:10 +00:00
|
|
|
|
// Some array -> array type casts are okay
|
|
|
|
|
if (arrayArg && function.getParamCount() == 1 && op != EOpConstructStruct && type.isArray() &&
|
|
|
|
|
!type.isArrayOfArrays() && !function[0].type->isArrayOfArrays() &&
|
|
|
|
|
type.getVectorSize() >= 1 && function[0].type->getVectorSize() >= 1)
|
|
|
|
|
return false;
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (arrayArg && op != EOpConstructStruct && ! type.isArrayOfArrays()) {
|
|
|
|
|
error(loc, "constructing non-array constituent from array argument", "constructor", "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (matrixInMatrix && ! type.isArray()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (overFull) {
|
|
|
|
|
error(loc, "too many arguments", "constructor", "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 17:47:42 +00:00
|
|
|
|
if (op == EOpConstructStruct && ! type.isArray() && isScalarConstructor(node))
|
2016-11-28 05:51:36 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (op == EOpConstructStruct && ! type.isArray() && (int)type.getStruct()->size() != function.getParamCount()) {
|
|
|
|
|
error(loc, "Number of constructor parameters does not match the number of structure fields", "constructor", "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((op != EOpConstructStruct && size != 1 && size < type.computeNumComponents()) ||
|
|
|
|
|
(op == EOpConstructStruct && size < type.computeNumComponents())) {
|
|
|
|
|
error(loc, "not enough data provided for construction", "constructor", "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 17:47:42 +00:00
|
|
|
|
// See if 'node', in the context of constructing aggregates, is a scalar argument
|
|
|
|
|
// to a constructor.
|
|
|
|
|
//
|
|
|
|
|
bool HlslParseContext::isScalarConstructor(const TIntermNode* node)
|
2016-11-28 05:51:36 +00:00
|
|
|
|
{
|
2017-04-04 17:47:42 +00:00
|
|
|
|
// Obviously, it must be a scalar, but an aggregate node might not be fully
|
|
|
|
|
// completed yet: holding a sequence of initializers under an aggregate
|
|
|
|
|
// would not yet be typed, so don't check it's type. This corresponds to
|
|
|
|
|
// the aggregate operator also not being set yet. (An aggregate operation
|
|
|
|
|
// that legitimately yields a scalar will have a getOp() of that operator,
|
|
|
|
|
// not EOpNull.)
|
|
|
|
|
|
|
|
|
|
return node->getAsTyped() != nullptr &&
|
|
|
|
|
node->getAsTyped()->isScalar() &&
|
|
|
|
|
(node->getAsAggregate() == nullptr || node->getAsAggregate()->getOp() != EOpNull);
|
2016-11-28 05:51:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// Verify all the correct semantics for constructing a combined texture/sampler.
|
|
|
|
|
// Return true if the semantics are incorrect.
|
|
|
|
|
bool HlslParseContext::constructorTextureSamplerError(const TSourceLoc& loc, const TFunction& function)
|
|
|
|
|
{
|
|
|
|
|
TString constructorName = function.getType().getBasicTypeString(); // TODO: performance: should not be making copy; interface needs to change
|
|
|
|
|
const char* token = constructorName.c_str();
|
|
|
|
|
|
|
|
|
|
// exactly two arguments needed
|
|
|
|
|
if (function.getParamCount() != 2) {
|
|
|
|
|
error(loc, "sampler-constructor requires two arguments", token, "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For now, not allowing arrayed constructors, the rest of this function
|
|
|
|
|
// is set up to allow them, if this test is removed:
|
|
|
|
|
if (function.getType().isArray()) {
|
|
|
|
|
error(loc, "sampler-constructor cannot make an array of samplers", token, "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// first argument
|
|
|
|
|
// * the constructor's first argument must be a texture type
|
|
|
|
|
// * the dimensionality (1D, 2D, 3D, Cube, Rect, Buffer, MS, and Array)
|
|
|
|
|
// of the texture type must match that of the constructed sampler type
|
|
|
|
|
// (that is, the suffixes of the type of the first argument and the
|
|
|
|
|
// type of the constructor will be spelled the same way)
|
|
|
|
|
if (function[0].type->getBasicType() != EbtSampler ||
|
|
|
|
|
! function[0].type->getSampler().isTexture() ||
|
|
|
|
|
function[0].type->isArray()) {
|
|
|
|
|
error(loc, "sampler-constructor first argument must be a scalar textureXXX type", token, "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// simulate the first argument's impact on the result type, so it can be compared with the encapsulated operator!=()
|
|
|
|
|
TSampler texture = function.getType().getSampler();
|
|
|
|
|
texture.combined = false;
|
|
|
|
|
texture.shadow = false;
|
|
|
|
|
if (texture != function[0].type->getSampler()) {
|
|
|
|
|
error(loc, "sampler-constructor first argument must match type and dimensionality of constructor type", token, "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// second argument
|
|
|
|
|
// * the constructor's second argument must be a scalar of type
|
|
|
|
|
// *sampler* or *samplerShadow*
|
|
|
|
|
// * the presence or absence of depth comparison (Shadow) must match
|
|
|
|
|
// between the constructed sampler type and the type of the second argument
|
|
|
|
|
if (function[1].type->getBasicType() != EbtSampler ||
|
|
|
|
|
! function[1].type->getSampler().isPureSampler() ||
|
|
|
|
|
function[1].type->isArray()) {
|
|
|
|
|
error(loc, "sampler-constructor second argument must be a scalar type 'sampler'", token, "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (function.getType().getSampler().shadow != function[1].type->getSampler().shadow) {
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "sampler-constructor second argument presence of shadow must match constructor presence of shadow",
|
|
|
|
|
token, "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Checks to see if a void variable has been declared and raise an error message for such a case
|
|
|
|
|
//
|
|
|
|
|
// returns true in case of an error
|
|
|
|
|
//
|
|
|
|
|
bool HlslParseContext::voidErrorCheck(const TSourceLoc& loc, const TString& identifier, const TBasicType basicType)
|
|
|
|
|
{
|
|
|
|
|
if (basicType == EbtVoid) {
|
|
|
|
|
error(loc, "illegal use of type 'void'", identifier.c_str(), "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Fix just a full qualifier (no variables or types yet, but qualifier is complete) at global level.
|
|
|
|
|
//
|
2016-07-09 04:09:10 +00:00
|
|
|
|
void HlslParseContext::globalQualifierFix(const TSourceLoc&, TQualifier& qualifier)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
// move from parameter/unknown qualifiers to pipeline in/out qualifiers
|
|
|
|
|
switch (qualifier.storage) {
|
|
|
|
|
case EvqIn:
|
|
|
|
|
qualifier.storage = EvqVaryingIn;
|
|
|
|
|
break;
|
|
|
|
|
case EvqOut:
|
|
|
|
|
qualifier.storage = EvqVaryingOut;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Merge characteristics of the 'src' qualifier into the 'dst'.
|
|
|
|
|
// If there is duplication, issue error messages, unless 'force'
|
|
|
|
|
// is specified, which means to just override default settings.
|
|
|
|
|
//
|
|
|
|
|
// Also, when force is false, it will be assumed that 'src' follows
|
|
|
|
|
// 'dst', for the purpose of error checking order for versions
|
|
|
|
|
// that require specific orderings of qualifiers.
|
|
|
|
|
//
|
2016-09-16 23:10:39 +00:00
|
|
|
|
void HlslParseContext::mergeQualifiers(TQualifier& dst, const TQualifier& src)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
// Storage qualification
|
|
|
|
|
if (dst.storage == EvqTemporary || dst.storage == EvqGlobal)
|
|
|
|
|
dst.storage = src.storage;
|
|
|
|
|
else if ((dst.storage == EvqIn && src.storage == EvqOut) ||
|
2016-07-25 22:05:33 +00:00
|
|
|
|
(dst.storage == EvqOut && src.storage == EvqIn))
|
2016-03-13 03:11:22 +00:00
|
|
|
|
dst.storage = EvqInOut;
|
|
|
|
|
else if ((dst.storage == EvqIn && src.storage == EvqConst) ||
|
2016-07-25 22:05:33 +00:00
|
|
|
|
(dst.storage == EvqConst && src.storage == EvqIn))
|
2016-03-13 03:11:22 +00:00
|
|
|
|
dst.storage = EvqConstReadOnly;
|
|
|
|
|
|
|
|
|
|
// Layout qualifiers
|
|
|
|
|
mergeObjectLayoutQualifiers(dst, src, false);
|
|
|
|
|
|
|
|
|
|
// individual qualifiers
|
|
|
|
|
bool repeated = false;
|
|
|
|
|
#define MERGE_SINGLETON(field) repeated |= dst.field && src.field; dst.field |= src.field;
|
|
|
|
|
MERGE_SINGLETON(invariant);
|
2016-05-04 18:36:14 +00:00
|
|
|
|
MERGE_SINGLETON(noContraction);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
MERGE_SINGLETON(centroid);
|
|
|
|
|
MERGE_SINGLETON(smooth);
|
|
|
|
|
MERGE_SINGLETON(flat);
|
|
|
|
|
MERGE_SINGLETON(nopersp);
|
|
|
|
|
MERGE_SINGLETON(patch);
|
|
|
|
|
MERGE_SINGLETON(sample);
|
|
|
|
|
MERGE_SINGLETON(coherent);
|
|
|
|
|
MERGE_SINGLETON(volatil);
|
|
|
|
|
MERGE_SINGLETON(restrict);
|
|
|
|
|
MERGE_SINGLETON(readonly);
|
|
|
|
|
MERGE_SINGLETON(writeonly);
|
|
|
|
|
MERGE_SINGLETON(specConstant);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// used to flatten the sampler type space into a single dimension
|
|
|
|
|
// correlates with the declaration of defaultSamplerPrecision[]
|
|
|
|
|
int HlslParseContext::computeSamplerTypeIndex(TSampler& sampler)
|
|
|
|
|
{
|
|
|
|
|
int arrayIndex = sampler.arrayed ? 1 : 0;
|
|
|
|
|
int shadowIndex = sampler.shadow ? 1 : 0;
|
|
|
|
|
int externalIndex = sampler.external ? 1 : 0;
|
|
|
|
|
|
2017-07-28 22:20:13 +00:00
|
|
|
|
return EsdNumDims *
|
|
|
|
|
(EbtNumTypes * (2 * (2 * arrayIndex + shadowIndex) + externalIndex) + sampler.type) + sampler.dim;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Do size checking for an array type's size.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::arraySizeCheck(const TSourceLoc& loc, TIntermTyped* expr, TArraySize& sizePair)
|
|
|
|
|
{
|
|
|
|
|
bool isConst = false;
|
|
|
|
|
sizePair.size = 1;
|
|
|
|
|
sizePair.node = nullptr;
|
|
|
|
|
|
|
|
|
|
TIntermConstantUnion* constant = expr->getAsConstantUnion();
|
|
|
|
|
if (constant) {
|
|
|
|
|
// handle true (non-specialization) constant
|
|
|
|
|
sizePair.size = constant->getConstArray()[0].getIConst();
|
|
|
|
|
isConst = true;
|
|
|
|
|
} else {
|
|
|
|
|
// see if it's a specialization constant instead
|
|
|
|
|
if (expr->getQualifier().isSpecConstant()) {
|
|
|
|
|
isConst = true;
|
|
|
|
|
sizePair.node = expr;
|
|
|
|
|
TIntermSymbol* symbol = expr->getAsSymbolNode();
|
|
|
|
|
if (symbol && symbol->getConstArray().size() > 0)
|
|
|
|
|
sizePair.size = symbol->getConstArray()[0].getIConst();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! isConst || (expr->getBasicType() != EbtInt && expr->getBasicType() != EbtUint)) {
|
|
|
|
|
error(loc, "array size must be a constant integer expression", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sizePair.size <= 0) {
|
|
|
|
|
error(loc, "array size must be a positive integer", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Require array to be completely sized
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::arraySizeRequiredCheck(const TSourceLoc& loc, const TArraySizes& arraySizes)
|
|
|
|
|
{
|
|
|
|
|
if (arraySizes.isImplicit())
|
|
|
|
|
error(loc, "array size required", "", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HlslParseContext::structArrayCheck(const TSourceLoc& /*loc*/, const TType& type)
|
|
|
|
|
{
|
|
|
|
|
const TTypeList& structure = *type.getStruct();
|
|
|
|
|
for (int m = 0; m < (int)structure.size(); ++m) {
|
|
|
|
|
const TType& member = *structure[m].type;
|
|
|
|
|
if (member.isArray())
|
|
|
|
|
arraySizeRequiredCheck(structure[m].loc, *member.getArraySizes());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Merge array dimensions listed in 'sizes' onto the type's array dimensions.
|
|
|
|
|
//
|
|
|
|
|
// From the spec: "vec4[2] a[3]; // size-3 array of size-2 array of vec4"
|
|
|
|
|
//
|
|
|
|
|
// That means, the 'sizes' go in front of the 'type' as outermost sizes.
|
|
|
|
|
// 'type' is the type part of the declaration (to the left)
|
|
|
|
|
// 'sizes' is the arrayness tagged on the identifier (to the right)
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::arrayDimMerge(TType& type, const TArraySizes* sizes)
|
|
|
|
|
{
|
|
|
|
|
if (sizes)
|
|
|
|
|
type.addArrayOuterSizes(*sizes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Do all the semantic checking for declaring or redeclaring an array, with and
|
|
|
|
|
// without a size, and make the right changes to the symbol table.
|
|
|
|
|
//
|
2017-07-28 22:20:13 +00:00
|
|
|
|
void HlslParseContext::declareArray(const TSourceLoc& loc, const TString& identifier, const TType& type,
|
|
|
|
|
TSymbol*& symbol, bool track)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (symbol == nullptr) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
bool currentScope;
|
|
|
|
|
symbol = symbolTable.find(identifier, nullptr, ¤tScope);
|
|
|
|
|
|
|
|
|
|
if (symbol && builtInName(identifier) && ! symbolTable.atBuiltInLevel()) {
|
|
|
|
|
// bad shader (errors already reported) trying to redeclare a built-in name as an array
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (symbol == nullptr || ! currentScope) {
|
|
|
|
|
//
|
|
|
|
|
// Successfully process a new definition.
|
|
|
|
|
// (Redeclarations have to take place at the same scope; otherwise they are hiding declarations)
|
|
|
|
|
//
|
|
|
|
|
symbol = new TVariable(&identifier, type);
|
|
|
|
|
symbolTable.insert(*symbol);
|
2016-11-05 16:15:53 +00:00
|
|
|
|
if (track && symbolTable.atGlobalLevel())
|
2017-01-19 22:41:47 +00:00
|
|
|
|
trackLinkage(*symbol);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (symbol->getAsAnonMember()) {
|
|
|
|
|
error(loc, "cannot redeclare a user-block member array", identifier.c_str(), "");
|
|
|
|
|
symbol = nullptr;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Process a redeclaration.
|
|
|
|
|
//
|
|
|
|
|
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (symbol == nullptr) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
error(loc, "array variable name expected", identifier.c_str(), "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// redeclareBuiltinVariable() should have already done the copyUp()
|
|
|
|
|
TType& existingType = symbol->getWritableType();
|
|
|
|
|
|
|
|
|
|
if (existingType.isExplicitlySizedArray()) {
|
2017-07-28 22:20:13 +00:00
|
|
|
|
// be more lenient for input arrays to geometry shaders and tessellation control outputs,
|
|
|
|
|
// where the redeclaration is the same size
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
existingType.updateArraySizes(type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HlslParseContext::updateImplicitArraySize(const TSourceLoc& loc, TIntermNode *node, int index)
|
|
|
|
|
{
|
|
|
|
|
// maybe there is nothing to do...
|
|
|
|
|
TIntermTyped* typedNode = node->getAsTyped();
|
|
|
|
|
if (typedNode->getType().getImplicitArraySize() > index)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// something to do...
|
|
|
|
|
|
|
|
|
|
// Figure out what symbol to lookup, as we will use its type to edit for the size change,
|
|
|
|
|
// as that type will be shared through shallow copies for future references.
|
|
|
|
|
TSymbol* symbol = nullptr;
|
|
|
|
|
int blockIndex = -1;
|
|
|
|
|
const TString* lookupName = nullptr;
|
|
|
|
|
if (node->getAsSymbolNode())
|
|
|
|
|
lookupName = &node->getAsSymbolNode()->getName();
|
|
|
|
|
else if (node->getAsBinaryNode()) {
|
|
|
|
|
const TIntermBinary* deref = node->getAsBinaryNode();
|
|
|
|
|
// This has to be the result of a block dereference, unless it's bad shader code
|
|
|
|
|
// If it's a uniform block, then an error will be issued elsewhere, but
|
|
|
|
|
// return early now to avoid crashing later in this function.
|
|
|
|
|
if (! deref->getLeft()->getAsSymbolNode() || deref->getLeft()->getBasicType() != EbtBlock ||
|
|
|
|
|
deref->getLeft()->getType().getQualifier().storage == EvqUniform ||
|
|
|
|
|
deref->getRight()->getAsConstantUnion() == nullptr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
blockIndex = deref->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst();
|
|
|
|
|
|
|
|
|
|
lookupName = &deref->getLeft()->getAsSymbolNode()->getName();
|
|
|
|
|
if (IsAnonymous(*lookupName))
|
|
|
|
|
lookupName = &(*deref->getLeft()->getType().getStruct())[blockIndex].type->getFieldName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lookup the symbol, should only fail if shader code is incorrect
|
|
|
|
|
symbol = symbolTable.find(*lookupName);
|
|
|
|
|
if (symbol == nullptr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (symbol->getAsFunction()) {
|
|
|
|
|
error(loc, "array variable name expected", symbol->getName().c_str(), "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
symbol->getWritableType().setImplicitArraySize(index + 1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-30 23:42:57 +00:00
|
|
|
|
//
|
|
|
|
|
// Enforce non-initializer type/qualifier rules.
|
|
|
|
|
//
|
2017-07-28 22:20:13 +00:00
|
|
|
|
void HlslParseContext::fixConstInit(const TSourceLoc& loc, const TString& identifier, TType& type,
|
|
|
|
|
TIntermTyped*& initializer)
|
2016-12-30 23:42:57 +00:00
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// Make the qualifier make sense, given that there is an initializer.
|
|
|
|
|
//
|
|
|
|
|
if (initializer == nullptr) {
|
|
|
|
|
if (type.getQualifier().storage == EvqConst ||
|
|
|
|
|
type.getQualifier().storage == EvqConstReadOnly) {
|
|
|
|
|
initializer = intermediate.makeAggregate(loc);
|
|
|
|
|
warn(loc, "variable with qualifier 'const' not initialized; zero initializing", identifier.c_str(), "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// See if the identifier is a built-in symbol that can be redeclared, and if so,
|
|
|
|
|
// copy the symbol table's read-only built-in variable to the current
|
|
|
|
|
// global level, where it can be modified based on the passed in type.
|
|
|
|
|
//
|
|
|
|
|
// Returns nullptr if no redeclaration took place; meaning a normal declaration still
|
|
|
|
|
// needs to occur for it, not necessarily an error.
|
|
|
|
|
//
|
|
|
|
|
// Returns a redeclared and type-modified variable if a redeclared occurred.
|
|
|
|
|
//
|
2016-07-09 04:09:10 +00:00
|
|
|
|
TSymbol* HlslParseContext::redeclareBuiltinVariable(const TSourceLoc& /*loc*/, const TString& identifier,
|
|
|
|
|
const TQualifier& /*qualifier*/,
|
2016-11-05 16:15:53 +00:00
|
|
|
|
const TShaderQualifiers& /*publicType*/)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (! builtInName(identifier) || symbolTable.atBuiltInLevel() || ! symbolTable.atGlobalLevel())
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-24 01:04:12 +00:00
|
|
|
|
//
|
|
|
|
|
// Generate index to the array element in a structure buffer (SSBO)
|
|
|
|
|
//
|
|
|
|
|
TIntermTyped* HlslParseContext::indexStructBufferContent(const TSourceLoc& loc, TIntermTyped* buffer) const
|
|
|
|
|
{
|
|
|
|
|
// Bail out if not a struct buffer
|
|
|
|
|
if (buffer == nullptr || ! isStructBufferType(buffer->getType()))
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
// Runtime sized array is always the last element.
|
|
|
|
|
const TTypeList* bufferStruct = buffer->getType().getStruct();
|
|
|
|
|
TIntermTyped* arrayPosition = intermediate.addConstantUnion(unsigned(bufferStruct->size()-1), loc);
|
|
|
|
|
|
|
|
|
|
TIntermTyped* argArray = intermediate.addIndex(EOpIndexDirectStruct, buffer, arrayPosition, loc);
|
|
|
|
|
argArray->setType(*(*bufferStruct)[bufferStruct->size()-1].type);
|
|
|
|
|
|
|
|
|
|
return argArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// IFF type is a structuredbuffer/byteaddressbuffer type, return the content
|
|
|
|
|
// (template) type. E.g, StructuredBuffer<MyType> -> MyType. Else return nullptr.
|
|
|
|
|
//
|
|
|
|
|
TType* HlslParseContext::getStructBufferContentType(const TType& type) const
|
|
|
|
|
{
|
|
|
|
|
if (type.getBasicType() != EbtBlock)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
2017-03-03 15:34:07 +00:00
|
|
|
|
const int memberCount = (int)type.getStruct()->size();
|
2017-02-24 01:04:12 +00:00
|
|
|
|
assert(memberCount > 0);
|
|
|
|
|
|
|
|
|
|
TType* contentType = (*type.getStruct())[memberCount-1].type;
|
|
|
|
|
|
|
|
|
|
return contentType->isRuntimeSizedArray() ? contentType : nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// If an existing struct buffer has a sharable type, then share it.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::shareStructBufferType(TType& type)
|
|
|
|
|
{
|
|
|
|
|
// PackOffset must be equivalent to share types on a per-member basis.
|
|
|
|
|
// Note: cannot use auto type due to recursion. Thus, this is a std::function.
|
|
|
|
|
const std::function<bool(TType& lhs, TType& rhs)>
|
|
|
|
|
compareQualifiers = [&](TType& lhs, TType& rhs) -> bool {
|
|
|
|
|
if (lhs.getQualifier().layoutOffset != rhs.getQualifier().layoutOffset)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (lhs.isStruct() != rhs.isStruct())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (lhs.isStruct() && rhs.isStruct()) {
|
|
|
|
|
if (lhs.getStruct()->size() != rhs.getStruct()->size())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < int(lhs.getStruct()->size()); ++i)
|
|
|
|
|
if (!compareQualifiers(*(*lhs.getStruct())[i].type, *(*rhs.getStruct())[i].type))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// We need to compare certain qualifiers in addition to the type.
|
|
|
|
|
const auto typeEqual = [compareQualifiers](TType& lhs, TType& rhs) -> bool {
|
|
|
|
|
if (lhs.getQualifier().readonly != rhs.getQualifier().readonly)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// If both are structures, recursively look for packOffset equality
|
|
|
|
|
// as well as type equality.
|
|
|
|
|
return compareQualifiers(lhs, rhs) && lhs == rhs;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// This is an exhaustive O(N) search, but real world shaders have
|
|
|
|
|
// only a small number of these.
|
|
|
|
|
for (int idx = 0; idx < int(structBufferTypes.size()); ++idx) {
|
|
|
|
|
// If the deep structure matches, modulo qualifiers, use it
|
|
|
|
|
if (typeEqual(*structBufferTypes[idx], type)) {
|
|
|
|
|
type.shallowCopy(*structBufferTypes[idx]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Otherwise, remember it:
|
|
|
|
|
TType* typeCopy = new TType;
|
|
|
|
|
typeCopy->shallowCopy(type);
|
|
|
|
|
structBufferTypes.push_back(typeCopy);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-17 21:50:47 +00:00
|
|
|
|
void HlslParseContext::paramFix(TType& type)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
2016-06-17 21:50:47 +00:00
|
|
|
|
switch (type.getQualifier().storage) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
case EvqConst:
|
|
|
|
|
type.getQualifier().storage = EvqConstReadOnly;
|
|
|
|
|
break;
|
|
|
|
|
case EvqGlobal:
|
|
|
|
|
case EvqTemporary:
|
|
|
|
|
type.getQualifier().storage = EvqIn;
|
|
|
|
|
break;
|
2017-02-24 01:04:12 +00:00
|
|
|
|
case EvqBuffer:
|
|
|
|
|
{
|
|
|
|
|
// SSBO parameter. These do not go through the declareBlock path since they are fn parameters.
|
|
|
|
|
correctUniform(type.getQualifier());
|
|
|
|
|
TQualifier bufferQualifier = globalBufferDefaults;
|
|
|
|
|
mergeObjectLayoutQualifiers(bufferQualifier, type.getQualifier(), true);
|
|
|
|
|
bufferQualifier.storage = type.getQualifier().storage;
|
|
|
|
|
bufferQualifier.readonly = type.getQualifier().readonly;
|
|
|
|
|
bufferQualifier.coherent = type.getQualifier().coherent;
|
2017-04-27 17:22:32 +00:00
|
|
|
|
bufferQualifier.declaredBuiltIn = type.getQualifier().declaredBuiltIn;
|
2017-02-24 01:04:12 +00:00
|
|
|
|
type.getQualifier() = bufferQualifier;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HlslParseContext::specializationCheck(const TSourceLoc& loc, const TType& type, const char* op)
|
|
|
|
|
{
|
|
|
|
|
if (type.containsSpecializationSize())
|
|
|
|
|
error(loc, "can't use with types containing arrays sized with a specialization constant", op, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Layout qualifier stuff.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// Put the id's layout qualification into the public type, for qualifiers not having a number set.
|
|
|
|
|
// This is before we know any type information for error checking.
|
2016-08-17 16:22:08 +00:00
|
|
|
|
void HlslParseContext::setLayoutQualifier(const TSourceLoc& loc, TQualifier& qualifier, TString& id)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
|
|
|
|
|
|
|
|
|
|
if (id == TQualifier::getLayoutMatrixString(ElmColumnMajor)) {
|
2016-09-26 02:25:06 +00:00
|
|
|
|
qualifier.layoutMatrix = ElmRowMajor;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == TQualifier::getLayoutMatrixString(ElmRowMajor)) {
|
2016-09-26 02:25:06 +00:00
|
|
|
|
qualifier.layoutMatrix = ElmColumnMajor;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == "push_constant") {
|
|
|
|
|
requireVulkan(loc, "push_constant");
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutPushConstant = true;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (language == EShLangGeometry || language == EShLangTessEvaluation) {
|
|
|
|
|
if (id == TQualifier::getGeometryString(ElgTriangles)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.geometry = ElgTriangles;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (language == EShLangGeometry) {
|
|
|
|
|
if (id == TQualifier::getGeometryString(ElgPoints)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.geometry = ElgPoints;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == TQualifier::getGeometryString(ElgLineStrip)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.geometry = ElgLineStrip;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == TQualifier::getGeometryString(ElgLines)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.geometry = ElgLines;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == TQualifier::getGeometryString(ElgLinesAdjacency)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.geometry = ElgLinesAdjacency;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == TQualifier::getGeometryString(ElgTrianglesAdjacency)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.geometry = ElgTrianglesAdjacency;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == TQualifier::getGeometryString(ElgTriangleStrip)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.geometry = ElgTriangleStrip;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
assert(language == EShLangTessEvaluation);
|
|
|
|
|
|
|
|
|
|
// input primitive
|
|
|
|
|
if (id == TQualifier::getGeometryString(ElgTriangles)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.geometry = ElgTriangles;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == TQualifier::getGeometryString(ElgQuads)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.geometry = ElgQuads;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == TQualifier::getGeometryString(ElgIsolines)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.geometry = ElgIsolines;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// vertex spacing
|
|
|
|
|
if (id == TQualifier::getVertexSpacingString(EvsEqual)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.spacing = EvsEqual;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == TQualifier::getVertexSpacingString(EvsFractionalEven)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.spacing = EvsFractionalEven;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == TQualifier::getVertexSpacingString(EvsFractionalOdd)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.spacing = EvsFractionalOdd;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// triangle order
|
|
|
|
|
if (id == TQualifier::getVertexOrderString(EvoCw)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.order = EvoCw;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == TQualifier::getVertexOrderString(EvoCcw)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.order = EvoCcw;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// point mode
|
|
|
|
|
if (id == "point_mode") {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.pointMode = true;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (language == EShLangFragment) {
|
|
|
|
|
if (id == "origin_upper_left") {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.originUpperLeft = true;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == "pixel_center_integer") {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.pixelCenterInteger = true;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == "early_fragment_tests") {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.earlyFragmentTests = true;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (TLayoutDepth depth = (TLayoutDepth)(EldNone + 1); depth < EldCount; depth = (TLayoutDepth)(depth + 1)) {
|
|
|
|
|
if (id == TQualifier::getLayoutDepthString(depth)) {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.layoutDepth = depth;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (id.compare(0, 13, "blend_support") == 0) {
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (TBlendEquationShift be = (TBlendEquationShift)0; be < EBlendCount; be = (TBlendEquationShift)(be + 1)) {
|
|
|
|
|
if (id == TQualifier::getBlendEquationString(be)) {
|
|
|
|
|
requireExtensions(loc, 1, &E_GL_KHR_blend_equation_advanced, "blend equation");
|
|
|
|
|
intermediate.addBlendEquation(be);
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.blendEquation = true;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (! found)
|
|
|
|
|
error(loc, "unknown blend equation", "blend_support", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
error(loc, "unrecognized layout identifier, or qualifier requires assignment (e.g., binding = 4)", id.c_str(), "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Put the id's layout qualifier value into the public type, for qualifiers having a number set.
|
|
|
|
|
// This is before we know any type information for error checking.
|
2017-07-28 22:20:13 +00:00
|
|
|
|
void HlslParseContext::setLayoutQualifier(const TSourceLoc& loc, TQualifier& qualifier, TString& id,
|
|
|
|
|
const TIntermTyped* node)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
const char* feature = "layout-id value";
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// const char* nonLiteralFeature = "non-literal layout-id value";
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
integerCheck(node, feature);
|
|
|
|
|
const TIntermConstantUnion* constUnion = node->getAsConstantUnion();
|
|
|
|
|
int value = 0;
|
|
|
|
|
if (constUnion) {
|
|
|
|
|
value = constUnion->getConstArray()[0].getIConst();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
|
|
|
|
|
|
|
|
|
|
if (id == "offset") {
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutOffset = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
} else if (id == "align") {
|
|
|
|
|
// "The specified alignment must be a power of 2, or a compile-time error results."
|
|
|
|
|
if (! IsPow2(value))
|
|
|
|
|
error(loc, "must be a power of 2", "align", "");
|
|
|
|
|
else
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutAlign = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
} else if (id == "location") {
|
|
|
|
|
if ((unsigned int)value >= TQualifier::layoutLocationEnd)
|
|
|
|
|
error(loc, "location is too large", id.c_str(), "");
|
|
|
|
|
else
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutLocation = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
} else if (id == "set") {
|
|
|
|
|
if ((unsigned int)value >= TQualifier::layoutSetEnd)
|
|
|
|
|
error(loc, "set is too large", id.c_str(), "");
|
|
|
|
|
else
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutSet = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
} else if (id == "binding") {
|
|
|
|
|
if ((unsigned int)value >= TQualifier::layoutBindingEnd)
|
|
|
|
|
error(loc, "binding is too large", id.c_str(), "");
|
|
|
|
|
else
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutBinding = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
} else if (id == "component") {
|
|
|
|
|
if ((unsigned)value >= TQualifier::layoutComponentEnd)
|
|
|
|
|
error(loc, "component is too large", id.c_str(), "");
|
|
|
|
|
else
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutComponent = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
} else if (id.compare(0, 4, "xfb_") == 0) {
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// "Any shader making any static use (after preprocessing) of any of these
|
|
|
|
|
// *xfb_* qualifiers will cause the shader to be in a transform feedback
|
|
|
|
|
// capturing mode and hence responsible for describing the transform feedback
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// setup."
|
|
|
|
|
intermediate.setXfbMode();
|
|
|
|
|
if (id == "xfb_buffer") {
|
|
|
|
|
// "It is a compile-time error to specify an *xfb_buffer* that is greater than
|
|
|
|
|
// the implementation-dependent constant gl_MaxTransformFeedbackBuffers."
|
|
|
|
|
if (value >= resources.maxTransformFeedbackBuffers)
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "buffer is too large:", id.c_str(), "gl_MaxTransformFeedbackBuffers is %d",
|
|
|
|
|
resources.maxTransformFeedbackBuffers);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (value >= (int)TQualifier::layoutXfbBufferEnd)
|
|
|
|
|
error(loc, "buffer is too large:", id.c_str(), "internal max is %d", TQualifier::layoutXfbBufferEnd - 1);
|
|
|
|
|
else
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutXfbBuffer = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
} else if (id == "xfb_offset") {
|
|
|
|
|
if (value >= (int)TQualifier::layoutXfbOffsetEnd)
|
|
|
|
|
error(loc, "offset is too large:", id.c_str(), "internal max is %d", TQualifier::layoutXfbOffsetEnd - 1);
|
|
|
|
|
else
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutXfbOffset = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
} else if (id == "xfb_stride") {
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// "The resulting stride (implicit or explicit), when divided by 4, must be less than or equal to the
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// implementation-dependent constant gl_MaxTransformFeedbackInterleavedComponents."
|
|
|
|
|
if (value > 4 * resources.maxTransformFeedbackInterleavedComponents)
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "1/4 stride is too large:", id.c_str(), "gl_MaxTransformFeedbackInterleavedComponents is %d",
|
|
|
|
|
resources.maxTransformFeedbackInterleavedComponents);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
else if (value >= (int)TQualifier::layoutXfbStrideEnd)
|
|
|
|
|
error(loc, "stride is too large:", id.c_str(), "internal max is %d", TQualifier::layoutXfbStrideEnd - 1);
|
|
|
|
|
if (value < (int)TQualifier::layoutXfbStrideEnd)
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutXfbStride = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id == "input_attachment_index") {
|
|
|
|
|
requireVulkan(loc, "input_attachment_index");
|
|
|
|
|
if (value >= (int)TQualifier::layoutAttachmentEnd)
|
|
|
|
|
error(loc, "attachment index is too large", id.c_str(), "");
|
|
|
|
|
else
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutAttachment = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == "constant_id") {
|
|
|
|
|
requireSpv(loc, "constant_id");
|
|
|
|
|
if (value >= (int)TQualifier::layoutSpecConstantIdEnd) {
|
|
|
|
|
error(loc, "specialization-constant id is too large", id.c_str(), "");
|
|
|
|
|
} else {
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutSpecConstantId = value;
|
|
|
|
|
qualifier.specConstant = true;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (! intermediate.addUsedConstantId(value))
|
|
|
|
|
error(loc, "specialization-constant id already used", id.c_str(), "");
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (language) {
|
|
|
|
|
case EShLangVertex:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EShLangTessControl:
|
|
|
|
|
if (id == "vertices") {
|
|
|
|
|
if (value == 0)
|
|
|
|
|
error(loc, "must be greater than 0", "vertices", "");
|
|
|
|
|
else
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.vertices = value;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EShLangTessEvaluation:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EShLangGeometry:
|
|
|
|
|
if (id == "invocations") {
|
|
|
|
|
if (value == 0)
|
|
|
|
|
error(loc, "must be at least 1", "invocations", "");
|
|
|
|
|
else
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.invocations = value;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == "max_vertices") {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.vertices = value;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (value > resources.maxGeometryOutputVertices)
|
|
|
|
|
error(loc, "too large, must be less than gl_MaxGeometryOutputVertices", "max_vertices", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == "stream") {
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutStream = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EShLangFragment:
|
|
|
|
|
if (id == "index") {
|
2016-08-17 16:22:08 +00:00
|
|
|
|
qualifier.layoutIndex = value;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EShLangCompute:
|
|
|
|
|
if (id.compare(0, 11, "local_size_") == 0) {
|
|
|
|
|
if (id == "local_size_x") {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.localSize[0] = value;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == "local_size_y") {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.localSize[1] = value;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == "local_size_z") {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.localSize[2] = value;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-17 02:59:42 +00:00
|
|
|
|
if (spvVersion.spv != 0) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (id == "local_size_x_id") {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.localSizeSpecId[0] = value;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == "local_size_y_id") {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.localSizeSpecId[1] = value;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id == "local_size_z_id") {
|
2017-01-06 19:34:14 +00:00
|
|
|
|
// publicType.shaderQualifiers.localSizeSpecId[2] = value;
|
2016-08-17 16:22:08 +00:00
|
|
|
|
warn(loc, "ignored", id.c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error(loc, "there is no such layout identifier for this stage taking an assigned value", id.c_str(), "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Merge any layout qualifier information from src into dst, leaving everything else in dst alone
|
|
|
|
|
//
|
|
|
|
|
// "More than one layout qualifier may appear in a single declaration.
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// Additionally, the same layout-qualifier-name can occur multiple times
|
|
|
|
|
// within a layout qualifier or across multiple layout qualifiers in the
|
|
|
|
|
// same declaration. When the same layout-qualifier-name occurs
|
|
|
|
|
// multiple times, in a single declaration, the last occurrence overrides
|
|
|
|
|
// the former occurrence(s). Further, if such a layout-qualifier-name
|
|
|
|
|
// will effect subsequent declarations or other observable behavior, it
|
|
|
|
|
// is only the last occurrence that will have any effect, behaving as if
|
|
|
|
|
// the earlier occurrence(s) within the declaration are not present.
|
|
|
|
|
// This is also true for overriding layout-qualifier-names, where one
|
|
|
|
|
// overrides the other (e.g., row_major vs. column_major); only the last
|
|
|
|
|
// occurrence has any effect."
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::mergeObjectLayoutQualifiers(TQualifier& dst, const TQualifier& src, bool inheritOnly)
|
|
|
|
|
{
|
|
|
|
|
if (src.hasMatrix())
|
|
|
|
|
dst.layoutMatrix = src.layoutMatrix;
|
|
|
|
|
if (src.hasPacking())
|
|
|
|
|
dst.layoutPacking = src.layoutPacking;
|
|
|
|
|
|
|
|
|
|
if (src.hasStream())
|
|
|
|
|
dst.layoutStream = src.layoutStream;
|
|
|
|
|
|
|
|
|
|
if (src.hasFormat())
|
|
|
|
|
dst.layoutFormat = src.layoutFormat;
|
|
|
|
|
|
|
|
|
|
if (src.hasXfbBuffer())
|
|
|
|
|
dst.layoutXfbBuffer = src.layoutXfbBuffer;
|
|
|
|
|
|
|
|
|
|
if (src.hasAlign())
|
|
|
|
|
dst.layoutAlign = src.layoutAlign;
|
|
|
|
|
|
|
|
|
|
if (! inheritOnly) {
|
|
|
|
|
if (src.hasLocation())
|
|
|
|
|
dst.layoutLocation = src.layoutLocation;
|
|
|
|
|
if (src.hasComponent())
|
|
|
|
|
dst.layoutComponent = src.layoutComponent;
|
|
|
|
|
if (src.hasIndex())
|
|
|
|
|
dst.layoutIndex = src.layoutIndex;
|
|
|
|
|
|
|
|
|
|
if (src.hasOffset())
|
|
|
|
|
dst.layoutOffset = src.layoutOffset;
|
|
|
|
|
|
|
|
|
|
if (src.hasSet())
|
|
|
|
|
dst.layoutSet = src.layoutSet;
|
|
|
|
|
if (src.layoutBinding != TQualifier::layoutBindingEnd)
|
|
|
|
|
dst.layoutBinding = src.layoutBinding;
|
|
|
|
|
|
|
|
|
|
if (src.hasXfbStride())
|
|
|
|
|
dst.layoutXfbStride = src.layoutXfbStride;
|
|
|
|
|
if (src.hasXfbOffset())
|
|
|
|
|
dst.layoutXfbOffset = src.layoutXfbOffset;
|
|
|
|
|
if (src.hasAttachment())
|
|
|
|
|
dst.layoutAttachment = src.layoutAttachment;
|
|
|
|
|
if (src.hasSpecConstantId())
|
|
|
|
|
dst.layoutSpecConstantId = src.layoutSpecConstantId;
|
|
|
|
|
|
|
|
|
|
if (src.layoutPushConstant)
|
|
|
|
|
dst.layoutPushConstant = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Look up a function name in the symbol table, and make sure it is a function.
|
|
|
|
|
//
|
2016-08-25 00:34:43 +00:00
|
|
|
|
// First, look for an exact match. If there is none, use the generic selector
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// TParseContextBase::selectFunction() to find one, parameterized by the
|
2016-08-25 00:34:43 +00:00
|
|
|
|
// convertible() and better() predicates defined below.
|
|
|
|
|
//
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// Return the function symbol if found, otherwise nullptr.
|
|
|
|
|
//
|
2017-05-17 05:16:26 +00:00
|
|
|
|
const TFunction* HlslParseContext::findFunction(const TSourceLoc& loc, TFunction& call, bool& builtIn, int& thisDepth,
|
2016-12-24 01:56:57 +00:00
|
|
|
|
TIntermTyped*& args)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (symbolTable.isFunctionNameVariable(call.getName())) {
|
|
|
|
|
error(loc, "can't use function syntax on variable", call.getName().c_str(), "");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// first, look for an exact match
|
2017-05-17 05:16:26 +00:00
|
|
|
|
bool dummyScope;
|
|
|
|
|
TSymbol* symbol = symbolTable.find(call.getMangledName(), &builtIn, &dummyScope, &thisDepth);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (symbol)
|
|
|
|
|
return symbol->getAsFunction();
|
|
|
|
|
|
2016-08-25 00:34:43 +00:00
|
|
|
|
// no exact match, use the generic selector, parameterized by the GLSL rules
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
2016-08-25 00:34:43 +00:00
|
|
|
|
// create list of candidates to send
|
2016-08-19 13:27:28 +00:00
|
|
|
|
TVector<const TFunction*> candidateList;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
symbolTable.findFunctionNameList(call.getMangledName(), candidateList, builtIn);
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2017-05-17 05:16:26 +00:00
|
|
|
|
// These built-in ops can accept any type, so we bypass the argument selection
|
2016-11-17 22:04:20 +00:00
|
|
|
|
if (candidateList.size() == 1 && builtIn &&
|
|
|
|
|
(candidateList[0]->getBuiltInOp() == EOpMethodAppend ||
|
2017-04-10 14:19:21 +00:00
|
|
|
|
candidateList[0]->getBuiltInOp() == EOpMethodRestartStrip ||
|
|
|
|
|
candidateList[0]->getBuiltInOp() == EOpMethodIncrementCounter ||
|
2017-04-14 00:42:58 +00:00
|
|
|
|
candidateList[0]->getBuiltInOp() == EOpMethodDecrementCounter ||
|
|
|
|
|
candidateList[0]->getBuiltInOp() == EOpMethodAppend ||
|
|
|
|
|
candidateList[0]->getBuiltInOp() == EOpMethodConsume)) {
|
2016-11-17 22:04:20 +00:00
|
|
|
|
return candidateList[0];
|
|
|
|
|
}
|
|
|
|
|
|
HLSL: opcode specific promotion rules for interlocked ops
PR #577 addresses most but not all of the intrinsic promotion problems.
This PR resolves all known cases in the remainder.
Interlocked ops need special promotion rules because at the time
of function selection, the first argument has not been converted
to a buffer object. It's just an int or uint, but you don't want
to convert THAT argument, because that implies converting the
buffer object itself. Rather, you can convert other arguments,
but want to stay in the same "family" of functions. E.g, if
the first interlocked arg is a uint, use only the uint family,
never the int family, you can convert the other args as you please.
This PR allows making such opcode and arg specific choices by
passing the op and arg to the convertible lambda. The code in
the new test "hlsl.promote.atomic.frag" would not compile without
this change, but it must compile.
Also, it provides better handling of downconversions (to "worse"
types), which are permitted in HLSL. The existing method of
selecting upconversions is unchanged, but if that doesn't find
any valid ones, then it will allow downconversions. In effect
this always uses an upconversion if there is one.
2016-12-06 22:50:11 +00:00
|
|
|
|
bool allowOnlyUpConversions = true;
|
|
|
|
|
|
2016-08-25 00:34:43 +00:00
|
|
|
|
// can 'from' convert to 'to'?
|
HLSL: opcode specific promotion rules for interlocked ops
PR #577 addresses most but not all of the intrinsic promotion problems.
This PR resolves all known cases in the remainder.
Interlocked ops need special promotion rules because at the time
of function selection, the first argument has not been converted
to a buffer object. It's just an int or uint, but you don't want
to convert THAT argument, because that implies converting the
buffer object itself. Rather, you can convert other arguments,
but want to stay in the same "family" of functions. E.g, if
the first interlocked arg is a uint, use only the uint family,
never the int family, you can convert the other args as you please.
This PR allows making such opcode and arg specific choices by
passing the op and arg to the convertible lambda. The code in
the new test "hlsl.promote.atomic.frag" would not compile without
this change, but it must compile.
Also, it provides better handling of downconversions (to "worse"
types), which are permitted in HLSL. The existing method of
selecting upconversions is unchanged, but if that doesn't find
any valid ones, then it will allow downconversions. In effect
this always uses an upconversion if there is one.
2016-12-06 22:50:11 +00:00
|
|
|
|
const auto convertible = [&](const TType& from, const TType& to, TOperator op, int arg) -> bool {
|
2016-08-25 00:34:43 +00:00
|
|
|
|
if (from == to)
|
|
|
|
|
return true;
|
2016-08-25 21:57:56 +00:00
|
|
|
|
|
|
|
|
|
// no aggregate conversions
|
2017-01-06 07:34:48 +00:00
|
|
|
|
if (from.isArray() || to.isArray() ||
|
2016-08-25 21:57:56 +00:00
|
|
|
|
from.isStruct() || to.isStruct())
|
|
|
|
|
return false;
|
|
|
|
|
|
HLSL: opcode specific promotion rules for interlocked ops
PR #577 addresses most but not all of the intrinsic promotion problems.
This PR resolves all known cases in the remainder.
Interlocked ops need special promotion rules because at the time
of function selection, the first argument has not been converted
to a buffer object. It's just an int or uint, but you don't want
to convert THAT argument, because that implies converting the
buffer object itself. Rather, you can convert other arguments,
but want to stay in the same "family" of functions. E.g, if
the first interlocked arg is a uint, use only the uint family,
never the int family, you can convert the other args as you please.
This PR allows making such opcode and arg specific choices by
passing the op and arg to the convertible lambda. The code in
the new test "hlsl.promote.atomic.frag" would not compile without
this change, but it must compile.
Also, it provides better handling of downconversions (to "worse"
types), which are permitted in HLSL. The existing method of
selecting upconversions is unchanged, but if that doesn't find
any valid ones, then it will allow downconversions. In effect
this always uses an upconversion if there is one.
2016-12-06 22:50:11 +00:00
|
|
|
|
switch (op) {
|
|
|
|
|
case EOpInterlockedAdd:
|
|
|
|
|
case EOpInterlockedAnd:
|
|
|
|
|
case EOpInterlockedCompareExchange:
|
|
|
|
|
case EOpInterlockedCompareStore:
|
|
|
|
|
case EOpInterlockedExchange:
|
|
|
|
|
case EOpInterlockedMax:
|
|
|
|
|
case EOpInterlockedMin:
|
|
|
|
|
case EOpInterlockedOr:
|
|
|
|
|
case EOpInterlockedXor:
|
|
|
|
|
// We do not promote the texture or image type for these ocodes. Normally that would not
|
|
|
|
|
// be an issue because it's a buffer, but we haven't decomposed the opcode yet, and at this
|
|
|
|
|
// stage it's merely e.g, a basic integer type.
|
2017-01-06 07:34:48 +00:00
|
|
|
|
//
|
HLSL: opcode specific promotion rules for interlocked ops
PR #577 addresses most but not all of the intrinsic promotion problems.
This PR resolves all known cases in the remainder.
Interlocked ops need special promotion rules because at the time
of function selection, the first argument has not been converted
to a buffer object. It's just an int or uint, but you don't want
to convert THAT argument, because that implies converting the
buffer object itself. Rather, you can convert other arguments,
but want to stay in the same "family" of functions. E.g, if
the first interlocked arg is a uint, use only the uint family,
never the int family, you can convert the other args as you please.
This PR allows making such opcode and arg specific choices by
passing the op and arg to the convertible lambda. The code in
the new test "hlsl.promote.atomic.frag" would not compile without
this change, but it must compile.
Also, it provides better handling of downconversions (to "worse"
types), which are permitted in HLSL. The existing method of
selecting upconversions is unchanged, but if that doesn't find
any valid ones, then it will allow downconversions. In effect
this always uses an upconversion if there is one.
2016-12-06 22:50:11 +00:00
|
|
|
|
// Instead, we want to promote other arguments, but stay within the same family. In other
|
|
|
|
|
// words, InterlockedAdd(RWBuffer<int>, ...) will always use the int flavor, never the uint flavor,
|
|
|
|
|
// but it is allowed to promote its other arguments.
|
|
|
|
|
if (arg == 0)
|
|
|
|
|
return false;
|
2017-01-02 16:10:27 +00:00
|
|
|
|
break;
|
|
|
|
|
case EOpMethodSample:
|
|
|
|
|
case EOpMethodSampleBias:
|
|
|
|
|
case EOpMethodSampleCmp:
|
|
|
|
|
case EOpMethodSampleCmpLevelZero:
|
|
|
|
|
case EOpMethodSampleGrad:
|
|
|
|
|
case EOpMethodSampleLevel:
|
|
|
|
|
case EOpMethodLoad:
|
|
|
|
|
case EOpMethodGetDimensions:
|
|
|
|
|
case EOpMethodGetSamplePosition:
|
|
|
|
|
case EOpMethodGather:
|
|
|
|
|
case EOpMethodCalculateLevelOfDetail:
|
|
|
|
|
case EOpMethodCalculateLevelOfDetailUnclamped:
|
|
|
|
|
case EOpMethodGatherRed:
|
|
|
|
|
case EOpMethodGatherGreen:
|
|
|
|
|
case EOpMethodGatherBlue:
|
|
|
|
|
case EOpMethodGatherAlpha:
|
|
|
|
|
case EOpMethodGatherCmp:
|
|
|
|
|
case EOpMethodGatherCmpRed:
|
|
|
|
|
case EOpMethodGatherCmpGreen:
|
|
|
|
|
case EOpMethodGatherCmpBlue:
|
|
|
|
|
case EOpMethodGatherCmpAlpha:
|
|
|
|
|
case EOpMethodAppend:
|
|
|
|
|
case EOpMethodRestartStrip:
|
|
|
|
|
// those are method calls, the object type can not be changed
|
|
|
|
|
// they are equal if the dim and type match (is dim sufficient?)
|
|
|
|
|
if (arg == 0)
|
|
|
|
|
return from.getSampler().type == to.getSampler().type &&
|
|
|
|
|
from.getSampler().arrayed == to.getSampler().arrayed &&
|
|
|
|
|
from.getSampler().shadow == to.getSampler().shadow &&
|
|
|
|
|
from.getSampler().ms == to.getSampler().ms &&
|
|
|
|
|
from.getSampler().dim == to.getSampler().dim;
|
|
|
|
|
break;
|
HLSL: opcode specific promotion rules for interlocked ops
PR #577 addresses most but not all of the intrinsic promotion problems.
This PR resolves all known cases in the remainder.
Interlocked ops need special promotion rules because at the time
of function selection, the first argument has not been converted
to a buffer object. It's just an int or uint, but you don't want
to convert THAT argument, because that implies converting the
buffer object itself. Rather, you can convert other arguments,
but want to stay in the same "family" of functions. E.g, if
the first interlocked arg is a uint, use only the uint family,
never the int family, you can convert the other args as you please.
This PR allows making such opcode and arg specific choices by
passing the op and arg to the convertible lambda. The code in
the new test "hlsl.promote.atomic.frag" would not compile without
this change, but it must compile.
Also, it provides better handling of downconversions (to "worse"
types), which are permitted in HLSL. The existing method of
selecting upconversions is unchanged, but if that doesn't find
any valid ones, then it will allow downconversions. In effect
this always uses an upconversion if there is one.
2016-12-06 22:50:11 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 21:57:56 +00:00
|
|
|
|
// basic types have to be convertible
|
HLSL: opcode specific promotion rules for interlocked ops
PR #577 addresses most but not all of the intrinsic promotion problems.
This PR resolves all known cases in the remainder.
Interlocked ops need special promotion rules because at the time
of function selection, the first argument has not been converted
to a buffer object. It's just an int or uint, but you don't want
to convert THAT argument, because that implies converting the
buffer object itself. Rather, you can convert other arguments,
but want to stay in the same "family" of functions. E.g, if
the first interlocked arg is a uint, use only the uint family,
never the int family, you can convert the other args as you please.
This PR allows making such opcode and arg specific choices by
passing the op and arg to the convertible lambda. The code in
the new test "hlsl.promote.atomic.frag" would not compile without
this change, but it must compile.
Also, it provides better handling of downconversions (to "worse"
types), which are permitted in HLSL. The existing method of
selecting upconversions is unchanged, but if that doesn't find
any valid ones, then it will allow downconversions. In effect
this always uses an upconversion if there is one.
2016-12-06 22:50:11 +00:00
|
|
|
|
if (allowOnlyUpConversions)
|
|
|
|
|
if (! intermediate.canImplicitlyPromote(from.getBasicType(), to.getBasicType(), EOpFunctionCall))
|
|
|
|
|
return false;
|
2016-08-25 21:57:56 +00:00
|
|
|
|
|
|
|
|
|
// shapes have to be convertible
|
2016-11-11 22:37:10 +00:00
|
|
|
|
if ((from.isScalarOrVec1() && to.isScalarOrVec1()) ||
|
|
|
|
|
(from.isScalarOrVec1() && to.isVector()) ||
|
2017-06-09 20:36:46 +00:00
|
|
|
|
(from.isScalarOrVec1() && to.isMatrix()) ||
|
2016-08-25 21:57:56 +00:00
|
|
|
|
(from.isVector() && to.isVector() && from.getVectorSize() >= to.getVectorSize()))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// TODO: what are the matrix rules? they go here
|
|
|
|
|
|
|
|
|
|
return false;
|
2016-08-25 00:34:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Is 'to2' a better conversion than 'to1'?
|
|
|
|
|
// Ties should not be considered as better.
|
|
|
|
|
// Assumes 'convertible' already said true.
|
2016-10-13 17:23:39 +00:00
|
|
|
|
const auto better = [](const TType& from, const TType& to1, const TType& to2) -> bool {
|
2016-08-25 16:49:21 +00:00
|
|
|
|
// exact match is always better than mismatch
|
2016-08-25 00:34:43 +00:00
|
|
|
|
if (from == to2)
|
|
|
|
|
return from != to1;
|
|
|
|
|
if (from == to1)
|
|
|
|
|
return false;
|
|
|
|
|
|
2016-08-25 21:57:56 +00:00
|
|
|
|
// shape changes are always worse
|
|
|
|
|
if (from.isScalar() || from.isVector()) {
|
|
|
|
|
if (from.getVectorSize() == to2.getVectorSize() &&
|
|
|
|
|
from.getVectorSize() != to1.getVectorSize())
|
2016-08-25 16:49:21 +00:00
|
|
|
|
return true;
|
2016-08-25 21:57:56 +00:00
|
|
|
|
if (from.getVectorSize() == to1.getVectorSize() &&
|
|
|
|
|
from.getVectorSize() != to2.getVectorSize())
|
|
|
|
|
return false;
|
2016-08-25 16:49:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-24 01:56:57 +00:00
|
|
|
|
// Handle sampler betterness: An exact sampler match beats a non-exact match.
|
|
|
|
|
// (If we just looked at basic type, all EbtSamplers would look the same).
|
|
|
|
|
// If any type is not a sampler, just use the linearize function below.
|
|
|
|
|
if (from.getBasicType() == EbtSampler && to1.getBasicType() == EbtSampler && to2.getBasicType() == EbtSampler) {
|
|
|
|
|
// We can ignore the vector size in the comparison.
|
|
|
|
|
TSampler to1Sampler = to1.getSampler();
|
|
|
|
|
TSampler to2Sampler = to2.getSampler();
|
|
|
|
|
|
|
|
|
|
to1Sampler.vectorSize = to2Sampler.vectorSize = from.getSampler().vectorSize;
|
|
|
|
|
|
|
|
|
|
if (from.getSampler() == to2Sampler)
|
|
|
|
|
return from.getSampler() != to1Sampler;
|
|
|
|
|
if (from.getSampler() == to1Sampler)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 21:57:56 +00:00
|
|
|
|
// Might or might not be changing shape, which means basic type might
|
|
|
|
|
// or might not match, so within that, the question is how big a
|
|
|
|
|
// basic-type conversion is being done.
|
|
|
|
|
//
|
|
|
|
|
// Use a hierarchy of domains, translated to order of magnitude
|
|
|
|
|
// in a linearized view:
|
|
|
|
|
// - floating-point vs. integer
|
|
|
|
|
// - 32 vs. 64 bit (or width in general)
|
|
|
|
|
// - bool vs. non bool
|
|
|
|
|
// - signed vs. not signed
|
2016-10-13 17:23:39 +00:00
|
|
|
|
const auto linearize = [](const TBasicType& basicType) -> int {
|
2016-08-25 21:57:56 +00:00
|
|
|
|
switch (basicType) {
|
|
|
|
|
case EbtBool: return 1;
|
|
|
|
|
case EbtInt: return 10;
|
|
|
|
|
case EbtUint: return 11;
|
|
|
|
|
case EbtInt64: return 20;
|
|
|
|
|
case EbtUint64: return 21;
|
|
|
|
|
case EbtFloat: return 100;
|
|
|
|
|
case EbtDouble: return 110;
|
|
|
|
|
default: return 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return std::abs(linearize(to2.getBasicType()) - linearize(from.getBasicType())) <
|
|
|
|
|
std::abs(linearize(to1.getBasicType()) - linearize(from.getBasicType()));
|
2016-08-25 00:34:43 +00:00
|
|
|
|
};
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
2016-08-25 00:34:43 +00:00
|
|
|
|
// for ambiguity reporting
|
|
|
|
|
bool tie = false;
|
2017-01-06 07:34:48 +00:00
|
|
|
|
|
2016-08-25 00:34:43 +00:00
|
|
|
|
// send to the generic selector
|
|
|
|
|
const TFunction* bestMatch = selectFunction(candidateList, call, convertible, better, tie);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
HLSL: opcode specific promotion rules for interlocked ops
PR #577 addresses most but not all of the intrinsic promotion problems.
This PR resolves all known cases in the remainder.
Interlocked ops need special promotion rules because at the time
of function selection, the first argument has not been converted
to a buffer object. It's just an int or uint, but you don't want
to convert THAT argument, because that implies converting the
buffer object itself. Rather, you can convert other arguments,
but want to stay in the same "family" of functions. E.g, if
the first interlocked arg is a uint, use only the uint family,
never the int family, you can convert the other args as you please.
This PR allows making such opcode and arg specific choices by
passing the op and arg to the convertible lambda. The code in
the new test "hlsl.promote.atomic.frag" would not compile without
this change, but it must compile.
Also, it provides better handling of downconversions (to "worse"
types), which are permitted in HLSL. The existing method of
selecting upconversions is unchanged, but if that doesn't find
any valid ones, then it will allow downconversions. In effect
this always uses an upconversion if there is one.
2016-12-06 22:50:11 +00:00
|
|
|
|
if (bestMatch == nullptr) {
|
|
|
|
|
// If there is nothing selected by allowing only up-conversions (to a larger linearize() value),
|
|
|
|
|
// we instead try down-conversions, which are valid in HLSL, but not preferred if there are any
|
|
|
|
|
// upconversions possible.
|
|
|
|
|
allowOnlyUpConversions = false;
|
|
|
|
|
bestMatch = selectFunction(candidateList, call, convertible, better, tie);
|
|
|
|
|
}
|
|
|
|
|
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
if (bestMatch == nullptr) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
error(loc, "no matching overloaded function found", call.getName().c_str(), "");
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// For built-ins, we can convert across the arguments. This will happen in several steps:
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
// Step 1: If there's an exact match, use it.
|
|
|
|
|
// Step 2a: Otherwise, get the operator from the best match and promote arguments:
|
|
|
|
|
// Step 2b: reconstruct the TFunction based on the new arg types
|
|
|
|
|
// Step 3: Re-select after type promotion is applied, to find proper candidate.
|
|
|
|
|
if (builtIn) {
|
|
|
|
|
// Step 1: If there's an exact match, use it.
|
|
|
|
|
if (call.getMangledName() == bestMatch->getMangledName())
|
|
|
|
|
return bestMatch;
|
|
|
|
|
|
|
|
|
|
// Step 2a: Otherwise, get the operator from the best match and promote arguments as if we
|
|
|
|
|
// are that kind of operator.
|
|
|
|
|
if (args != nullptr) {
|
|
|
|
|
// The arg list can be a unary node, or an aggregate. We have to handle both.
|
|
|
|
|
// We will use the normal promote() facilities, which require an interm node.
|
|
|
|
|
TIntermOperator* promote = nullptr;
|
|
|
|
|
|
|
|
|
|
if (call.getParamCount() == 1) {
|
|
|
|
|
promote = new TIntermUnary(bestMatch->getBuiltInOp());
|
|
|
|
|
promote->getAsUnaryNode()->setOperand(args->getAsTyped());
|
|
|
|
|
} else {
|
|
|
|
|
promote = new TIntermAggregate(bestMatch->getBuiltInOp());
|
|
|
|
|
promote->getAsAggregate()->getSequence().swap(args->getAsAggregate()->getSequence());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! intermediate.promote(promote))
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
// Obtain the promoted arg list.
|
|
|
|
|
if (call.getParamCount() == 1) {
|
|
|
|
|
args = promote->getAsUnaryNode()->getOperand();
|
|
|
|
|
} else {
|
|
|
|
|
promote->getAsAggregate()->getSequence().swap(args->getAsAggregate()->getSequence());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 2b: reconstruct the TFunction based on the new arg types
|
|
|
|
|
TFunction convertedCall(&call.getName(), call.getType(), call.getBuiltInOp());
|
|
|
|
|
|
|
|
|
|
if (args->getAsAggregate()) {
|
|
|
|
|
// Handle aggregates: put all args into the new function call
|
|
|
|
|
for (int arg=0; arg<int(args->getAsAggregate()->getSequence().size()); ++arg) {
|
|
|
|
|
// TODO: But for constness, we could avoid the new & shallowCopy, and use the pointer directly.
|
2016-12-24 01:56:57 +00:00
|
|
|
|
TParameter param = { 0, new TType, nullptr };
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
param.type->shallowCopy(args->getAsAggregate()->getSequence()[arg]->getAsTyped()->getType());
|
|
|
|
|
convertedCall.addParameter(param);
|
|
|
|
|
}
|
|
|
|
|
} else if (args->getAsUnaryNode()) {
|
|
|
|
|
// Handle unaries: put all args into the new function call
|
2016-12-24 01:56:57 +00:00
|
|
|
|
TParameter param = { 0, new TType, nullptr };
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
param.type->shallowCopy(args->getAsUnaryNode()->getOperand()->getAsTyped()->getType());
|
|
|
|
|
convertedCall.addParameter(param);
|
|
|
|
|
} else if (args->getAsTyped()) {
|
|
|
|
|
// Handle bare e.g, floats, not in an aggregate.
|
2016-12-24 01:56:57 +00:00
|
|
|
|
TParameter param = { 0, new TType, nullptr };
|
HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float). In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.
These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).
Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition. If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases. This can be revisited once inout
conversions are in place.
Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*
Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous
conversion nodes.
A new function promoteAggregate is added, and used by findFunction. This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.
The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:
1. Attempt an exact match. If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
|
|
|
|
param.type->shallowCopy(args->getAsTyped()->getType());
|
|
|
|
|
convertedCall.addParameter(param);
|
|
|
|
|
} else {
|
|
|
|
|
assert(0); // unknown argument list.
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 3: Re-select after type promotion, to find proper candidate
|
|
|
|
|
// send to the generic selector
|
|
|
|
|
bestMatch = selectFunction(candidateList, convertedCall, convertible, better, tie);
|
|
|
|
|
|
|
|
|
|
// At this point, there should be no tie.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tie)
|
2016-08-25 00:34:43 +00:00
|
|
|
|
error(loc, "ambiguous best function under implicit type conversion", call.getName().c_str(), "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
2016-12-24 01:56:57 +00:00
|
|
|
|
// Append default parameter values if needed
|
|
|
|
|
if (!tie && bestMatch != nullptr) {
|
|
|
|
|
for (int defParam = call.getParamCount(); defParam < bestMatch->getParamCount(); ++defParam) {
|
|
|
|
|
handleFunctionArgument(&call, args, (*bestMatch)[defParam].defaultValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 00:34:43 +00:00
|
|
|
|
return bestMatch;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-05 06:02:40 +00:00
|
|
|
|
//
|
|
|
|
|
// Do everything necessary to handle a typedef declaration, for a single symbol.
|
2017-01-06 07:34:48 +00:00
|
|
|
|
//
|
2016-07-05 06:02:40 +00:00
|
|
|
|
// 'parseType' is the type part of the declaration (to the left)
|
|
|
|
|
// 'arraySizes' is the arrayness tagged on the identifier (to the right)
|
|
|
|
|
//
|
2017-03-29 05:43:10 +00:00
|
|
|
|
void HlslParseContext::declareTypedef(const TSourceLoc& loc, const TString& identifier, const TType& parseType)
|
2016-07-05 06:02:40 +00:00
|
|
|
|
{
|
2017-02-08 20:59:30 +00:00
|
|
|
|
TVariable* typeSymbol = new TVariable(&identifier, parseType, true);
|
2016-07-05 06:02:40 +00:00
|
|
|
|
if (! symbolTable.insert(*typeSymbol))
|
|
|
|
|
error(loc, "name already defined", "typedef", identifier.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 00:57:55 +00:00
|
|
|
|
// Do everything necessary to handle a struct declaration, including
|
|
|
|
|
// making IO aliases because HLSL allows mixed IO in a struct that specializes
|
|
|
|
|
// based on the usage (input, output, uniform, none).
|
|
|
|
|
void HlslParseContext::declareStruct(const TSourceLoc& loc, TString& structName, TType& type)
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
{
|
2017-02-04 00:57:55 +00:00
|
|
|
|
// If it was named, which means the type can be reused later, add
|
|
|
|
|
// it to the symbol table. (Unless it's a block, in which
|
|
|
|
|
// case the name is not a type.)
|
|
|
|
|
if (type.getBasicType() == EbtBlock || structName.size() == 0)
|
2017-02-02 01:09:17 +00:00
|
|
|
|
return;
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
|
2017-02-04 00:57:55 +00:00
|
|
|
|
TVariable* userTypeDef = new TVariable(&structName, type, true);
|
|
|
|
|
if (! symbolTable.insert(*userTypeDef)) {
|
|
|
|
|
error(loc, "redefinition", structName.c_str(), "struct");
|
2017-02-02 01:09:17 +00:00
|
|
|
|
return;
|
2017-02-04 00:57:55 +00:00
|
|
|
|
}
|
2016-12-19 22:48:01 +00:00
|
|
|
|
|
2017-02-04 00:57:55 +00:00
|
|
|
|
// See if we need IO aliases for the structure typeList
|
2017-01-25 17:03:17 +00:00
|
|
|
|
|
2017-02-06 03:27:30 +00:00
|
|
|
|
const auto condAlloc = [](bool pred, TTypeList*& list) {
|
|
|
|
|
if (pred && list == nullptr)
|
|
|
|
|
list = new TTypeList;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
tIoKinds newLists = { nullptr, nullptr, nullptr }; // allocate for each kind found
|
2017-02-04 00:57:55 +00:00
|
|
|
|
for (auto member = type.getStruct()->begin(); member != type.getStruct()->end(); ++member) {
|
2017-02-06 03:27:30 +00:00
|
|
|
|
condAlloc(hasUniform(member->type->getQualifier()), newLists.uniform);
|
|
|
|
|
condAlloc( hasInput(member->type->getQualifier()), newLists.input);
|
|
|
|
|
condAlloc( hasOutput(member->type->getQualifier()), newLists.output);
|
|
|
|
|
|
2017-02-04 00:57:55 +00:00
|
|
|
|
if (member->type->isStruct()) {
|
2017-02-06 03:27:30 +00:00
|
|
|
|
auto it = ioTypeMap.find(member->type->getStruct());
|
|
|
|
|
if (it != ioTypeMap.end()) {
|
|
|
|
|
condAlloc(it->second.uniform != nullptr, newLists.uniform);
|
|
|
|
|
condAlloc(it->second.input != nullptr, newLists.input);
|
|
|
|
|
condAlloc(it->second.output != nullptr, newLists.output);
|
2017-02-04 00:57:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-06 03:27:30 +00:00
|
|
|
|
if (newLists.uniform == nullptr &&
|
|
|
|
|
newLists.input == nullptr &&
|
2017-02-07 01:44:52 +00:00
|
|
|
|
newLists.output == nullptr) {
|
|
|
|
|
// Won't do any IO caching, clear up the type and get out now.
|
|
|
|
|
for (auto member = type.getStruct()->begin(); member != type.getStruct()->end(); ++member)
|
|
|
|
|
clearUniformInputOutput(member->type->getQualifier());
|
2017-02-04 00:57:55 +00:00
|
|
|
|
return;
|
2017-02-07 01:44:52 +00:00
|
|
|
|
}
|
2017-01-25 17:03:17 +00:00
|
|
|
|
|
2017-02-04 00:57:55 +00:00
|
|
|
|
// We have IO involved.
|
|
|
|
|
|
|
|
|
|
// Make a pure typeList for the symbol table, and cache side copies of IO versions.
|
|
|
|
|
for (auto member = type.getStruct()->begin(); member != type.getStruct()->end(); ++member) {
|
2017-02-06 03:27:30 +00:00
|
|
|
|
const auto inheritStruct = [&](TTypeList* s, TTypeLoc& ioMember) {
|
|
|
|
|
if (s != nullptr) {
|
|
|
|
|
ioMember.type = new TType;
|
|
|
|
|
ioMember.type->shallowCopy(*member->type);
|
|
|
|
|
ioMember.type->setStruct(s);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const auto newMember = [&](TTypeLoc& m) {
|
|
|
|
|
if (m.type == nullptr) {
|
|
|
|
|
m.type = new TType;
|
|
|
|
|
m.type->shallowCopy(*member->type);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TTypeLoc newUniformMember = { nullptr, member->loc };
|
|
|
|
|
TTypeLoc newInputMember = { nullptr, member->loc };
|
|
|
|
|
TTypeLoc newOutputMember = { nullptr, member->loc };
|
2017-02-04 00:57:55 +00:00
|
|
|
|
if (member->type->isStruct()) {
|
|
|
|
|
// swap in an IO child if there is one
|
|
|
|
|
auto it = ioTypeMap.find(member->type->getStruct());
|
2017-02-06 03:27:30 +00:00
|
|
|
|
if (it != ioTypeMap.end()) {
|
|
|
|
|
inheritStruct(it->second.uniform, newUniformMember);
|
|
|
|
|
inheritStruct(it->second.input, newInputMember);
|
|
|
|
|
inheritStruct(it->second.output, newOutputMember);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (newLists.uniform) {
|
|
|
|
|
newMember(newUniformMember);
|
2017-08-07 18:08:50 +00:00
|
|
|
|
|
|
|
|
|
// inherit default matrix layout (changeable via #pragma pack_matrix), if none given.
|
|
|
|
|
if (member->type->isMatrix() && member->type->getQualifier().layoutMatrix == ElmNone)
|
|
|
|
|
newUniformMember.type->getQualifier().layoutMatrix = globalUniformDefaults.layoutMatrix;
|
|
|
|
|
|
2017-02-06 03:27:30 +00:00
|
|
|
|
correctUniform(newUniformMember.type->getQualifier());
|
|
|
|
|
newLists.uniform->push_back(newUniformMember);
|
|
|
|
|
}
|
|
|
|
|
if (newLists.input) {
|
|
|
|
|
newMember(newInputMember);
|
|
|
|
|
correctInput(newInputMember.type->getQualifier());
|
|
|
|
|
newLists.input->push_back(newInputMember);
|
2017-02-04 00:57:55 +00:00
|
|
|
|
}
|
2017-02-06 03:27:30 +00:00
|
|
|
|
if (newLists.output) {
|
|
|
|
|
newMember(newOutputMember);
|
|
|
|
|
correctOutput(newOutputMember.type->getQualifier());
|
|
|
|
|
newLists.output->push_back(newOutputMember);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make original pure
|
|
|
|
|
clearUniformInputOutput(member->type->getQualifier());
|
2017-02-04 00:57:55 +00:00
|
|
|
|
}
|
2017-02-06 03:27:30 +00:00
|
|
|
|
ioTypeMap[type.getStruct()] = newLists;
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-02 21:30:59 +00:00
|
|
|
|
// Lookup a user-type by name.
|
|
|
|
|
// If found, fill in the type and return the defining symbol.
|
|
|
|
|
// If not found, return nullptr.
|
|
|
|
|
TSymbol* HlslParseContext::lookupUserType(const TString& typeName, TType& type)
|
|
|
|
|
{
|
|
|
|
|
TSymbol* symbol = symbolTable.find(typeName);
|
|
|
|
|
if (symbol && symbol->getAsVariable() && symbol->getAsVariable()->isUserType()) {
|
|
|
|
|
type.shallowCopy(symbol->getType());
|
|
|
|
|
return symbol;
|
|
|
|
|
} else
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Do everything necessary to handle a variable (non-block) declaration.
|
|
|
|
|
// Either redeclaring a variable, or making a new one, updating the symbol
|
|
|
|
|
// table, and all error checking.
|
|
|
|
|
//
|
|
|
|
|
// Returns a subtree node that computes an initializer, if needed.
|
|
|
|
|
// Returns nullptr if there is no code to execute for initialization.
|
|
|
|
|
//
|
2016-07-05 06:02:40 +00:00
|
|
|
|
// 'parseType' is the type part of the declaration (to the left)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// 'arraySizes' is the arrayness tagged on the identifier (to the right)
|
|
|
|
|
//
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermNode* HlslParseContext::declareVariable(const TSourceLoc& loc, const TString& identifier, TType& type,
|
|
|
|
|
TIntermTyped* initializer)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (voidErrorCheck(loc, identifier, type.getBasicType()))
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
WIP: HLSL: support global const initializers from non-constant rvalues
Semantic test left over from other source languages is removed, since this is permitted by HLSL.
Also, to support the functionality, a targeted test is performed for this case and it is
turned into a EvqGlobal qualifier to create an AST initialization segment when needed.
Constness is now propagated up aggregate chains during initializer construction. This
handles hierarchical cases such as the distinction between:
static const float2 a[2] = { { 1, 2 }, { 3, 4} };
vs
static const float2 a[2] = { { 1, 2 }, { cbuffer_member, 4} };
The first of which can use a first class constant initalization, and the second cannot.
2017-07-10 21:43:40 +00:00
|
|
|
|
// Global consts with initializers that are non-const act like EvqGlobal in HLSL.
|
|
|
|
|
// This test is implicitly recursive, because initializers propagate constness
|
|
|
|
|
// up the aggregate node tree during creation. E.g, for:
|
|
|
|
|
// { { 1, 2 }, { 3, 4 } }
|
|
|
|
|
// the initializer list is marked EvqConst at the top node, and remains so here. However:
|
|
|
|
|
// { 1, { myvar, 2 }, 3 }
|
|
|
|
|
// is not a const intializer, and still becomes EvqGlobal here.
|
|
|
|
|
|
|
|
|
|
const bool nonConstInitializer = (initializer != nullptr && initializer->getQualifier().storage != EvqConst);
|
|
|
|
|
|
|
|
|
|
if (type.getQualifier().storage == EvqConst && symbolTable.atGlobalLevel() && nonConstInitializer) {
|
|
|
|
|
// Force to global
|
|
|
|
|
type.getQualifier().storage = EvqGlobal;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-30 23:42:57 +00:00
|
|
|
|
// make const and initialization consistent
|
|
|
|
|
fixConstInit(loc, identifier, type, initializer);
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// Check for redeclaration of built-ins and/or attempting to declare a reserved name
|
2016-11-05 16:15:53 +00:00
|
|
|
|
TSymbol* symbol = nullptr;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
inheritGlobalDefaults(type.getQualifier());
|
|
|
|
|
|
2017-05-26 06:01:36 +00:00
|
|
|
|
const bool flattenVar = shouldFlatten(type);
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
|
2017-02-06 03:27:30 +00:00
|
|
|
|
// correct IO in the type
|
2017-01-25 17:03:17 +00:00
|
|
|
|
switch (type.getQualifier().storage) {
|
|
|
|
|
case EvqGlobal:
|
|
|
|
|
case EvqTemporary:
|
2017-02-06 03:27:30 +00:00
|
|
|
|
clearUniformInputOutput(type.getQualifier());
|
|
|
|
|
break;
|
|
|
|
|
case EvqUniform:
|
|
|
|
|
case EvqBuffer:
|
|
|
|
|
correctUniform(type.getQualifier());
|
2017-02-07 01:44:52 +00:00
|
|
|
|
if (type.isStruct()) {
|
|
|
|
|
auto it = ioTypeMap.find(type.getStruct());
|
|
|
|
|
if (it != ioTypeMap.end())
|
|
|
|
|
type.setStruct(it->second.uniform);
|
|
|
|
|
}
|
2017-02-24 01:04:12 +00:00
|
|
|
|
|
2017-02-06 03:27:30 +00:00
|
|
|
|
break;
|
2017-01-25 17:03:17 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-09-16 19:26:37 +00:00
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// Declare the variable
|
2016-09-27 20:38:57 +00:00
|
|
|
|
if (type.isArray()) {
|
|
|
|
|
// array case
|
2017-01-25 17:03:17 +00:00
|
|
|
|
declareArray(loc, identifier, type, symbol, !flattenVar);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
// non-array case
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (symbol == nullptr)
|
2017-01-25 17:03:17 +00:00
|
|
|
|
symbol = declareNonArray(loc, identifier, type, !flattenVar);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
else if (type != symbol->getType())
|
|
|
|
|
error(loc, "cannot change the type of", "redeclaration", symbol->getName().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-16 11:46:13 +00:00
|
|
|
|
if (symbol == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
if (flattenVar)
|
2017-08-07 01:42:42 +00:00
|
|
|
|
flatten(*symbol->getAsVariable(), symbolTable.atGlobalLevel());
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
|
2017-07-16 11:46:13 +00:00
|
|
|
|
if (initializer == nullptr)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
// Deal with initializer
|
2017-07-16 11:46:13 +00:00
|
|
|
|
TVariable* variable = symbol->getAsVariable();
|
|
|
|
|
if (variable == nullptr) {
|
|
|
|
|
error(loc, "initializer requires a variable, not a member", identifier.c_str(), "");
|
|
|
|
|
return nullptr;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
2017-07-16 11:46:13 +00:00
|
|
|
|
return executeInitializer(loc, initializer, variable, flattenVar);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pick up global defaults from the provide global defaults into dst.
|
|
|
|
|
void HlslParseContext::inheritGlobalDefaults(TQualifier& dst) const
|
|
|
|
|
{
|
|
|
|
|
if (dst.storage == EvqVaryingOut) {
|
|
|
|
|
if (! dst.hasStream() && language == EShLangGeometry)
|
|
|
|
|
dst.layoutStream = globalOutputDefaults.layoutStream;
|
|
|
|
|
if (! dst.hasXfbBuffer())
|
|
|
|
|
dst.layoutXfbBuffer = globalOutputDefaults.layoutXfbBuffer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Make an internal-only variable whose name is for debug purposes only
|
|
|
|
|
// and won't be searched for. Callers will only use the return value to use
|
|
|
|
|
// the variable, not the name to look it up. It is okay if the name
|
|
|
|
|
// is the same as other names; there won't be any conflict.
|
|
|
|
|
//
|
|
|
|
|
TVariable* HlslParseContext::makeInternalVariable(const char* name, const TType& type) const
|
|
|
|
|
{
|
2017-01-19 22:29:25 +00:00
|
|
|
|
TString* nameString = NewPoolTString(name);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
TVariable* variable = new TVariable(nameString, type);
|
|
|
|
|
symbolTable.makeInternalVariable(*variable);
|
|
|
|
|
|
|
|
|
|
return variable;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 17:47:42 +00:00
|
|
|
|
// Make a symbol node holding a new internal temporary variable.
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermSymbol* HlslParseContext::makeInternalVariableNode(const TSourceLoc& loc, const char* name,
|
|
|
|
|
const TType& type) const
|
2017-04-04 17:47:42 +00:00
|
|
|
|
{
|
|
|
|
|
TVariable* tmpVar = makeInternalVariable(name, type);
|
|
|
|
|
tmpVar->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
|
|
|
|
|
return intermediate.addSymbol(*tmpVar, loc);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Declare a non-array variable, the main point being there is no redeclaration
|
|
|
|
|
// for resizing allowed.
|
|
|
|
|
//
|
|
|
|
|
// Return the successfully declared variable.
|
|
|
|
|
//
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TVariable* HlslParseContext::declareNonArray(const TSourceLoc& loc, const TString& identifier, const TType& type,
|
|
|
|
|
bool track)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
// make a new variable
|
|
|
|
|
TVariable* variable = new TVariable(&identifier, type);
|
|
|
|
|
|
|
|
|
|
// add variable to symbol table
|
2016-11-05 16:15:53 +00:00
|
|
|
|
if (symbolTable.insert(*variable)) {
|
HLSL: Recursive composite flattening
This PR implements recursive type flattening. For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.
This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs. That will be handled separately with structure splitting,
which is not implemented by this PR. In the meantime, that case is detected and triggers an error.
The recursive flattening extends the following three aspects of single-level flattening:
- Flattening of structures to individual members with names such as "foo[0].samp[1]";
- Turning constant references to the nested composite type into a reference to a particular
flattened member.
- Shadow copies between arrays of flattened members and the nested composite type.
Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.
Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct
types are flattened. (The latter will change with structure splitting).
One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.
Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).
The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
|
|
|
|
if (track && symbolTable.atGlobalLevel())
|
2017-01-19 22:41:47 +00:00
|
|
|
|
trackLinkage(*variable);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return variable;
|
|
|
|
|
}
|
2016-11-05 16:15:53 +00:00
|
|
|
|
|
|
|
|
|
error(loc, "redefinition", variable->getName().c_str(), "");
|
|
|
|
|
return nullptr;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Handle all types of initializers from the grammar.
|
|
|
|
|
//
|
|
|
|
|
// Returning nullptr just means there is no code to execute to handle the
|
|
|
|
|
// initializer, which will, for example, be the case for constant initializers.
|
|
|
|
|
//
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermNode* HlslParseContext::executeInitializer(const TSourceLoc& loc, TIntermTyped* initializer, TVariable* variable,
|
|
|
|
|
bool flattened)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// Identifier must be of type constant, a global, or a temporary, and
|
|
|
|
|
// starting at version 120, desktop allows uniforms to have initializers.
|
|
|
|
|
//
|
|
|
|
|
TStorageQualifier qualifier = variable->getType().getQualifier().storage;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// If the initializer was from braces { ... }, we convert the whole subtree to a
|
|
|
|
|
// constructor-style subtree, allowing the rest of the code to operate
|
|
|
|
|
// identically for both kinds of initializers.
|
|
|
|
|
//
|
2017-01-05 17:28:26 +00:00
|
|
|
|
//
|
|
|
|
|
// Type can't be deduced from the initializer list, so a skeletal type to
|
|
|
|
|
// follow has to be passed in. Constness and specialization-constness
|
|
|
|
|
// should be deduced bottom up, not dictated by the skeletal type.
|
|
|
|
|
//
|
|
|
|
|
TType skeletalType;
|
|
|
|
|
skeletalType.shallowCopy(variable->getType());
|
|
|
|
|
skeletalType.getQualifier().makeTemporary();
|
2016-11-28 00:39:07 +00:00
|
|
|
|
if (initializer->getAsAggregate() && initializer->getAsAggregate()->getOp() == EOpNull)
|
2017-04-04 17:47:42 +00:00
|
|
|
|
initializer = convertInitializerList(loc, skeletalType, initializer, nullptr);
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (initializer == nullptr) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// error recovery; don't leave const without constant values
|
|
|
|
|
if (qualifier == EvqConst)
|
|
|
|
|
variable->getWritableType().getQualifier().storage = EvqTemporary;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fix outer arrayness if variable is unsized, getting size from the initializer
|
|
|
|
|
if (initializer->getType().isExplicitlySizedArray() &&
|
|
|
|
|
variable->getType().isImplicitlySizedArray())
|
|
|
|
|
variable->getWritableType().changeOuterArraySize(initializer->getType().getOuterArraySize());
|
|
|
|
|
|
|
|
|
|
// Inner arrayness can also get set by an initializer
|
|
|
|
|
if (initializer->getType().isArrayOfArrays() && variable->getType().isArrayOfArrays() &&
|
|
|
|
|
initializer->getType().getArraySizes()->getNumDims() ==
|
|
|
|
|
variable->getType().getArraySizes()->getNumDims()) {
|
|
|
|
|
// adopt unsized sizes from the initializer's sizes
|
|
|
|
|
for (int d = 1; d < variable->getType().getArraySizes()->getNumDims(); ++d) {
|
|
|
|
|
if (variable->getType().getArraySizes()->getDimSize(d) == UnsizedArraySize)
|
|
|
|
|
variable->getWritableType().getArraySizes().setDimSize(d, initializer->getType().getArraySizes()->getDimSize(d));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Uniform and global consts require a constant initializer
|
|
|
|
|
if (qualifier == EvqUniform && initializer->getType().getQualifier().storage != EvqConst) {
|
|
|
|
|
error(loc, "uniform initializers must be constant", "=", "'%s'", variable->getType().getCompleteString().c_str());
|
|
|
|
|
variable->getWritableType().getQualifier().storage = EvqTemporary;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-07 21:33:08 +00:00
|
|
|
|
// Const variables require a constant initializer
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (qualifier == EvqConst) {
|
|
|
|
|
if (initializer->getType().getQualifier().storage != EvqConst) {
|
|
|
|
|
variable->getWritableType().getQualifier().storage = EvqConstReadOnly;
|
|
|
|
|
qualifier = EvqConstReadOnly;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (qualifier == EvqConst || qualifier == EvqUniform) {
|
|
|
|
|
// Compile-time tagging of the variable with its constant value...
|
|
|
|
|
|
|
|
|
|
initializer = intermediate.addConversion(EOpAssign, variable->getType(), initializer);
|
2017-04-12 20:56:52 +00:00
|
|
|
|
if (initializer != nullptr && variable->getType() != initializer->getType())
|
2017-04-19 03:07:05 +00:00
|
|
|
|
initializer = intermediate.addUniShapeConversion(EOpAssign, variable->getType(), initializer);
|
2017-04-12 20:56:52 +00:00
|
|
|
|
if (initializer == nullptr || !initializer->getAsConstantUnion() ||
|
|
|
|
|
variable->getType() != initializer->getType()) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
error(loc, "non-matching or non-convertible constant type for const initializer",
|
|
|
|
|
variable->getType().getStorageQualifierString(), "");
|
|
|
|
|
variable->getWritableType().getQualifier().storage = EvqTemporary;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable->setConstArray(initializer->getAsConstantUnion()->getConstArray());
|
|
|
|
|
} else {
|
|
|
|
|
// normal assigning of a value to a variable...
|
|
|
|
|
specializationCheck(loc, initializer->getType(), "initializer");
|
|
|
|
|
TIntermSymbol* intermSymbol = intermediate.addSymbol(*variable, loc);
|
|
|
|
|
|
2017-07-16 11:46:13 +00:00
|
|
|
|
// If we are flattening, it could be due to setting opaques, which must be handled
|
|
|
|
|
// as aliases, and the 'initializer' node cannot actually be emitted, because it
|
|
|
|
|
// itself stores the result of the constructor, and we can't store to opaques.
|
|
|
|
|
// handleAssign() will emit the initializer.
|
|
|
|
|
TIntermNode* initNode = nullptr;
|
|
|
|
|
if (flattened && intermSymbol->getType().containsOpaque())
|
2017-07-30 22:54:02 +00:00
|
|
|
|
return executeFlattenedInitializer(loc, intermSymbol, *initializer->getAsAggregate());
|
2017-07-16 11:46:13 +00:00
|
|
|
|
else {
|
|
|
|
|
initNode = handleAssign(loc, EOpAssign, intermSymbol, initializer);
|
|
|
|
|
if (initNode == nullptr)
|
|
|
|
|
assignError(loc, "=", intermSymbol->getCompleteString(), initializer->getCompleteString());
|
|
|
|
|
return initNode;
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Reprocess any initializer-list { ... } parts of the initializer.
|
|
|
|
|
// Need to hierarchically assign correct types and implicit
|
|
|
|
|
// conversions. Will do this mimicking the same process used for
|
|
|
|
|
// creating a constructor-style initializer, ensuring we get the
|
|
|
|
|
// same form.
|
|
|
|
|
//
|
2016-11-28 05:51:36 +00:00
|
|
|
|
// Returns a node representing an expression for the initializer list expressed
|
|
|
|
|
// as the correct type.
|
|
|
|
|
//
|
|
|
|
|
// Returns nullptr if there is an error.
|
|
|
|
|
//
|
2017-04-04 17:47:42 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::convertInitializerList(const TSourceLoc& loc, const TType& type,
|
|
|
|
|
TIntermTyped* initializer, TIntermTyped* scalarInit)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
// Will operate recursively. Once a subtree is found that is constructor style,
|
|
|
|
|
// everything below it is already good: Only the "top part" of the initializer
|
|
|
|
|
// can be an initializer list, where "top part" can extend for several (or all) levels.
|
|
|
|
|
|
|
|
|
|
// see if we have bottomed out in the tree within the initializer-list part
|
|
|
|
|
TIntermAggregate* initList = initializer->getAsAggregate();
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (initList == nullptr || initList->getOp() != EOpNull) {
|
2016-11-28 00:39:07 +00:00
|
|
|
|
// We don't have a list, but if it's a scalar and the 'type' is a
|
|
|
|
|
// composite, we need to lengthen below to make it useful.
|
|
|
|
|
// Otherwise, this is an already formed object to initialize with.
|
|
|
|
|
if (type.isScalar() || !initializer->getType().isScalar())
|
|
|
|
|
return initializer;
|
|
|
|
|
else
|
|
|
|
|
initList = intermediate.makeAggregate(initializer);
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
// Of the initializer-list set of nodes, need to process bottom up,
|
|
|
|
|
// so recurse deep, then process on the way up.
|
|
|
|
|
|
|
|
|
|
// Go down the tree here...
|
|
|
|
|
if (type.isArray()) {
|
|
|
|
|
// The type's array might be unsized, which could be okay, so base sizes on the size of the aggregate.
|
|
|
|
|
// Later on, initializer execution code will deal with array size logic.
|
|
|
|
|
TType arrayType;
|
|
|
|
|
arrayType.shallowCopy(type); // sharing struct stuff is fine
|
|
|
|
|
arrayType.newArraySizes(*type.getArraySizes()); // but get a fresh copy of the array information, to edit below
|
|
|
|
|
|
|
|
|
|
// edit array sizes to fill in unsized dimensions
|
2016-11-28 00:39:07 +00:00
|
|
|
|
if (type.isImplicitlySizedArray())
|
|
|
|
|
arrayType.changeOuterArraySize((int)initList->getSequence().size());
|
2016-12-30 22:59:28 +00:00
|
|
|
|
|
|
|
|
|
// set unsized array dimensions that can be derived from the initializer's first element
|
|
|
|
|
if (arrayType.isArrayOfArrays() && initList->getSequence().size() > 0) {
|
|
|
|
|
TIntermTyped* firstInit = initList->getSequence()[0]->getAsTyped();
|
|
|
|
|
if (firstInit->getType().isArray() &&
|
|
|
|
|
arrayType.getArraySizes().getNumDims() == firstInit->getType().getArraySizes()->getNumDims() + 1) {
|
|
|
|
|
for (int d = 1; d < arrayType.getArraySizes().getNumDims(); ++d) {
|
|
|
|
|
if (arrayType.getArraySizes().getDimSize(d) == UnsizedArraySize)
|
|
|
|
|
arrayType.getArraySizes().setDimSize(d, firstInit->getType().getArraySizes()->getDimSize(d - 1));
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 00:39:07 +00:00
|
|
|
|
// lengthen list to be long enough
|
2017-04-04 17:47:42 +00:00
|
|
|
|
lengthenList(loc, initList->getSequence(), arrayType.getOuterArraySize(), scalarInit);
|
2016-11-28 00:39:07 +00:00
|
|
|
|
|
|
|
|
|
// recursively process each element
|
2016-03-13 03:11:22 +00:00
|
|
|
|
TType elementType(arrayType, 0); // dereferenced type
|
2016-11-28 00:39:07 +00:00
|
|
|
|
for (int i = 0; i < arrayType.getOuterArraySize(); ++i) {
|
2017-07-28 22:20:13 +00:00
|
|
|
|
initList->getSequence()[i] = convertInitializerList(loc, elementType,
|
|
|
|
|
initList->getSequence()[i]->getAsTyped(), scalarInit);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (initList->getSequence()[i] == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-28 21:29:35 +00:00
|
|
|
|
return addConstructor(loc, initList, arrayType);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
} else if (type.isStruct()) {
|
2016-11-28 00:39:07 +00:00
|
|
|
|
// lengthen list to be long enough
|
2017-04-04 17:47:42 +00:00
|
|
|
|
lengthenList(loc, initList->getSequence(), static_cast<int>(type.getStruct()->size()), scalarInit);
|
2016-11-28 00:39:07 +00:00
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (type.getStruct()->size() != initList->getSequence().size()) {
|
|
|
|
|
error(loc, "wrong number of structure members", "initializer list", "");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
for (size_t i = 0; i < type.getStruct()->size(); ++i) {
|
2017-07-28 22:20:13 +00:00
|
|
|
|
initList->getSequence()[i] = convertInitializerList(loc, *(*type.getStruct())[i].type,
|
|
|
|
|
initList->getSequence()[i]->getAsTyped(), scalarInit);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (initList->getSequence()[i] == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
} else if (type.isMatrix()) {
|
2016-08-24 20:36:13 +00:00
|
|
|
|
if (type.computeNumComponents() == (int)initList->getSequence().size()) {
|
|
|
|
|
// This means the matrix is initialized component-wise, rather than as
|
|
|
|
|
// a series of rows and columns. We can just use the list directly as
|
|
|
|
|
// a constructor; no further processing needed.
|
|
|
|
|
} else {
|
2016-11-28 00:39:07 +00:00
|
|
|
|
// lengthen list to be long enough
|
2017-04-04 17:47:42 +00:00
|
|
|
|
lengthenList(loc, initList->getSequence(), type.getMatrixCols(), scalarInit);
|
2016-11-28 00:39:07 +00:00
|
|
|
|
|
2016-08-24 20:36:13 +00:00
|
|
|
|
if (type.getMatrixCols() != (int)initList->getSequence().size()) {
|
|
|
|
|
error(loc, "wrong number of matrix columns:", "initializer list", type.getCompleteString().c_str());
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return nullptr;
|
2016-08-24 20:36:13 +00:00
|
|
|
|
}
|
|
|
|
|
TType vectorType(type, 0); // dereferenced type
|
|
|
|
|
for (int i = 0; i < type.getMatrixCols(); ++i) {
|
2017-07-28 22:20:13 +00:00
|
|
|
|
initList->getSequence()[i] = convertInitializerList(loc, vectorType,
|
|
|
|
|
initList->getSequence()[i]->getAsTyped(), scalarInit);
|
2016-08-24 20:36:13 +00:00
|
|
|
|
if (initList->getSequence()[i] == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (type.isVector()) {
|
2016-11-28 00:39:07 +00:00
|
|
|
|
// lengthen list to be long enough
|
2017-04-04 17:47:42 +00:00
|
|
|
|
lengthenList(loc, initList->getSequence(), type.getVectorSize(), scalarInit);
|
2016-11-28 00:39:07 +00:00
|
|
|
|
|
|
|
|
|
// error check; we're at bottom, so work is finished below
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (type.getVectorSize() != (int)initList->getSequence().size()) {
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "wrong vector size (or rows in a matrix column):", "initializer list",
|
|
|
|
|
type.getCompleteString().c_str());
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2016-07-30 16:36:09 +00:00
|
|
|
|
} else if (type.isScalar()) {
|
2016-12-30 22:59:28 +00:00
|
|
|
|
// lengthen list to be long enough
|
2017-04-04 17:47:42 +00:00
|
|
|
|
lengthenList(loc, initList->getSequence(), 1, scalarInit);
|
2016-12-30 22:59:28 +00:00
|
|
|
|
|
2016-07-30 16:36:09 +00:00
|
|
|
|
if ((int)initList->getSequence().size() != 1) {
|
|
|
|
|
error(loc, "scalar expected one element:", "initializer list", type.getCompleteString().c_str());
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2016-11-28 00:39:07 +00:00
|
|
|
|
} else {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
error(loc, "unexpected initializer-list type:", "initializer list", type.getCompleteString().c_str());
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-30 00:22:22 +00:00
|
|
|
|
// Now that the subtree is processed, process this node as if the
|
|
|
|
|
// initializer list is a set of arguments to a constructor.
|
2017-04-04 03:48:37 +00:00
|
|
|
|
TIntermTyped* emulatedConstructorArguments;
|
2016-07-30 00:22:22 +00:00
|
|
|
|
if (initList->getSequence().size() == 1)
|
2017-04-04 03:48:37 +00:00
|
|
|
|
emulatedConstructorArguments = initList->getSequence()[0]->getAsTyped();
|
2016-07-30 00:22:22 +00:00
|
|
|
|
else
|
|
|
|
|
emulatedConstructorArguments = initList;
|
2016-11-28 00:39:07 +00:00
|
|
|
|
|
2017-01-05 17:45:32 +00:00
|
|
|
|
return addConstructor(loc, emulatedConstructorArguments, type);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 00:39:07 +00:00
|
|
|
|
// Lengthen list to be long enough to cover any gap from the current list size
|
|
|
|
|
// to 'size'. If the list is longer, do nothing.
|
|
|
|
|
// The value to lengthen with is the default for short lists.
|
2017-04-04 17:47:42 +00:00
|
|
|
|
//
|
|
|
|
|
// By default, lists that are too short due to lack of initializers initialize to zero.
|
|
|
|
|
// Alternatively, it could be a scalar initializer for a structure. Both cases are handled,
|
|
|
|
|
// based on whether something is passed in as 'scalarInit'.
|
|
|
|
|
//
|
|
|
|
|
// 'scalarInit' must be safe to use each time this is called (no side effects replication).
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::lengthenList(const TSourceLoc& loc, TIntermSequence& list, int size, TIntermTyped* scalarInit)
|
2016-11-28 00:39:07 +00:00
|
|
|
|
{
|
2017-04-04 17:47:42 +00:00
|
|
|
|
for (int c = (int)list.size(); c < size; ++c) {
|
|
|
|
|
if (scalarInit == nullptr)
|
|
|
|
|
list.push_back(intermediate.addConstantUnion(0, loc));
|
|
|
|
|
else
|
|
|
|
|
list.push_back(scalarInit);
|
|
|
|
|
}
|
2016-11-28 00:39:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Test for the correctness of the parameters passed to various constructor functions
|
|
|
|
|
// and also convert them to the right data type, if allowed and required.
|
|
|
|
|
//
|
|
|
|
|
// Returns nullptr for an error or the constructed node (aggregate or typed) for no error.
|
|
|
|
|
//
|
2017-04-04 03:48:37 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::handleConstructor(const TSourceLoc& loc, TIntermTyped* node, const TType& type)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
2017-04-04 03:48:37 +00:00
|
|
|
|
if (node == nullptr)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
return nullptr;
|
|
|
|
|
|
2017-04-04 17:47:42 +00:00
|
|
|
|
// Handle the idiom "(struct type)<scalar value>"
|
|
|
|
|
if (type.isStruct() && isScalarConstructor(node)) {
|
|
|
|
|
// 'node' will almost always get used multiple times, so should not be used directly,
|
|
|
|
|
// it would create a DAG instead of a tree, which might be okay (would
|
|
|
|
|
// like to formalize that for constants and symbols), but if it has
|
|
|
|
|
// side effects, they would get executed multiple times, which is not okay.
|
|
|
|
|
if (node->getAsConstantUnion() == nullptr && node->getAsSymbolNode() == nullptr) {
|
|
|
|
|
TIntermAggregate* seq = intermediate.makeAggregate(loc);
|
|
|
|
|
TIntermSymbol* copy = makeInternalVariableNode(loc, "scalarCopy", node->getType());
|
|
|
|
|
seq = intermediate.growAggregate(seq, intermediate.addBinaryNode(EOpAssign, copy, node, loc));
|
|
|
|
|
seq = intermediate.growAggregate(seq, convertInitializerList(loc, type, intermediate.makeAggregate(loc), copy));
|
|
|
|
|
seq->setOp(EOpComma);
|
|
|
|
|
seq->setType(type);
|
|
|
|
|
return seq;
|
|
|
|
|
} else
|
|
|
|
|
return convertInitializerList(loc, type, intermediate.makeAggregate(loc), node);
|
|
|
|
|
}
|
2016-11-28 05:51:36 +00:00
|
|
|
|
|
2017-04-04 03:48:37 +00:00
|
|
|
|
return addConstructor(loc, node, type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add a constructor, either from the grammar, or other programmatic reasons.
|
|
|
|
|
//
|
2017-06-14 05:13:10 +00:00
|
|
|
|
// 'node' is what to construct from.
|
|
|
|
|
// 'type' is what type to construct.
|
|
|
|
|
//
|
|
|
|
|
// Returns the constructed object.
|
2017-04-04 03:48:37 +00:00
|
|
|
|
// Return nullptr if it can't be done.
|
|
|
|
|
//
|
|
|
|
|
TIntermTyped* HlslParseContext::addConstructor(const TSourceLoc& loc, TIntermTyped* node, const TType& type)
|
|
|
|
|
{
|
2016-07-28 21:29:35 +00:00
|
|
|
|
TOperator op = intermediate.mapTypeToConstructorOp(type);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
// Combined texture-sampler constructors are completely semantic checked
|
|
|
|
|
// in constructorTextureSamplerError()
|
|
|
|
|
if (op == EOpConstructTextureSampler)
|
2017-06-14 05:13:10 +00:00
|
|
|
|
return intermediate.setAggregateOperator(node->getAsAggregate(), op, type, loc);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
TTypeList::const_iterator memberTypes;
|
|
|
|
|
if (op == EOpConstructStruct)
|
|
|
|
|
memberTypes = type.getStruct()->begin();
|
|
|
|
|
|
|
|
|
|
TType elementType;
|
|
|
|
|
if (type.isArray()) {
|
|
|
|
|
TType dereferenced(type, 0);
|
|
|
|
|
elementType.shallowCopy(dereferenced);
|
|
|
|
|
} else
|
|
|
|
|
elementType.shallowCopy(type);
|
|
|
|
|
|
|
|
|
|
bool singleArg;
|
2017-06-14 05:13:10 +00:00
|
|
|
|
TIntermAggregate* aggrNode = node->getAsAggregate();
|
|
|
|
|
if (aggrNode != nullptr) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (aggrNode->getOp() != EOpNull || aggrNode->getSequence().size() == 1)
|
|
|
|
|
singleArg = true;
|
|
|
|
|
else
|
|
|
|
|
singleArg = false;
|
|
|
|
|
} else
|
|
|
|
|
singleArg = true;
|
|
|
|
|
|
|
|
|
|
TIntermTyped *newNode;
|
|
|
|
|
if (singleArg) {
|
2017-06-14 05:13:10 +00:00
|
|
|
|
// Handle array -> array conversion
|
|
|
|
|
// Constructing an array of one type from an array of another type is allowed,
|
|
|
|
|
// assuming there are enough components available (semantic-checked earlier).
|
|
|
|
|
if (type.isArray() && node->isArray())
|
|
|
|
|
newNode = convertArray(node, type);
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// If structure constructor or array constructor is being called
|
|
|
|
|
// for only one parameter inside the structure, we need to call constructAggregate function once.
|
2017-06-14 05:13:10 +00:00
|
|
|
|
else if (type.isArray())
|
2016-03-13 03:11:22 +00:00
|
|
|
|
newNode = constructAggregate(node, elementType, 1, node->getLoc());
|
|
|
|
|
else if (op == EOpConstructStruct)
|
|
|
|
|
newNode = constructAggregate(node, *(*memberTypes).type, 1, node->getLoc());
|
2017-06-09 20:36:46 +00:00
|
|
|
|
else {
|
|
|
|
|
// shape conversion for matrix constructor from scalar. HLSL semantics are: scalar
|
|
|
|
|
// is replicated into every element of the matrix (not just the diagnonal), so
|
|
|
|
|
// that is handled specially here.
|
|
|
|
|
if (type.isMatrix() && node->getType().isScalarOrVec1())
|
|
|
|
|
node = intermediate.addShapeConversion(type, node);
|
|
|
|
|
|
2017-04-04 03:48:37 +00:00
|
|
|
|
newNode = constructBuiltIn(type, op, node, node->getLoc(), false);
|
2017-06-09 20:36:46 +00:00
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
if (newNode && (type.isArray() || op == EOpConstructStruct))
|
|
|
|
|
newNode = intermediate.setAggregateOperator(newNode, EOpConstructStruct, type, loc);
|
|
|
|
|
|
|
|
|
|
return newNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Handle list of arguments.
|
|
|
|
|
//
|
|
|
|
|
TIntermSequence &sequenceVector = aggrNode->getSequence(); // Stores the information about the parameter to the constructor
|
|
|
|
|
// if the structure constructor contains more than one parameter, then construct
|
|
|
|
|
// each parameter
|
|
|
|
|
|
|
|
|
|
int paramCount = 0; // keeps a track of the constructor parameter number being checked
|
|
|
|
|
|
|
|
|
|
// for each parameter to the constructor call, check to see if the right type is passed or convert them
|
|
|
|
|
// to the right type if possible (and allowed).
|
|
|
|
|
// for structure constructors, just check if the right type is passed, no conversion is allowed.
|
|
|
|
|
|
|
|
|
|
for (TIntermSequence::iterator p = sequenceVector.begin();
|
|
|
|
|
p != sequenceVector.end(); p++, paramCount++) {
|
|
|
|
|
if (type.isArray())
|
|
|
|
|
newNode = constructAggregate(*p, elementType, paramCount + 1, node->getLoc());
|
|
|
|
|
else if (op == EOpConstructStruct)
|
|
|
|
|
newNode = constructAggregate(*p, *(memberTypes[paramCount]).type, paramCount + 1, node->getLoc());
|
|
|
|
|
else
|
|
|
|
|
newNode = constructBuiltIn(type, op, (*p)->getAsTyped(), node->getLoc(), true);
|
|
|
|
|
|
|
|
|
|
if (newNode)
|
|
|
|
|
*p = newNode;
|
|
|
|
|
else
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermTyped* constructor = intermediate.setAggregateOperator(aggrNode, op, type, loc);
|
|
|
|
|
|
|
|
|
|
return constructor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Function for constructor implementation. Calls addUnaryMath with appropriate EOp value
|
|
|
|
|
// for the parameter to the constructor (passed to this function). Essentially, it converts
|
|
|
|
|
// the parameter types correctly. If a constructor expects an int (like ivec2) and is passed a
|
|
|
|
|
// float, then float is converted to int.
|
|
|
|
|
//
|
|
|
|
|
// Returns nullptr for an error or the constructed node.
|
|
|
|
|
//
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::constructBuiltIn(const TType& type, TOperator op, TIntermTyped* node,
|
|
|
|
|
const TSourceLoc& loc, bool subset)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
TIntermTyped* newNode;
|
|
|
|
|
TOperator basicOp;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// First, convert types as needed.
|
|
|
|
|
//
|
|
|
|
|
switch (op) {
|
|
|
|
|
case EOpConstructVec2:
|
|
|
|
|
case EOpConstructVec3:
|
|
|
|
|
case EOpConstructVec4:
|
|
|
|
|
case EOpConstructMat2x2:
|
|
|
|
|
case EOpConstructMat2x3:
|
|
|
|
|
case EOpConstructMat2x4:
|
|
|
|
|
case EOpConstructMat3x2:
|
|
|
|
|
case EOpConstructMat3x3:
|
|
|
|
|
case EOpConstructMat3x4:
|
|
|
|
|
case EOpConstructMat4x2:
|
|
|
|
|
case EOpConstructMat4x3:
|
|
|
|
|
case EOpConstructMat4x4:
|
|
|
|
|
case EOpConstructFloat:
|
|
|
|
|
basicOp = EOpConstructFloat;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EOpConstructDVec2:
|
|
|
|
|
case EOpConstructDVec3:
|
|
|
|
|
case EOpConstructDVec4:
|
|
|
|
|
case EOpConstructDMat2x2:
|
|
|
|
|
case EOpConstructDMat2x3:
|
|
|
|
|
case EOpConstructDMat2x4:
|
|
|
|
|
case EOpConstructDMat3x2:
|
|
|
|
|
case EOpConstructDMat3x3:
|
|
|
|
|
case EOpConstructDMat3x4:
|
|
|
|
|
case EOpConstructDMat4x2:
|
|
|
|
|
case EOpConstructDMat4x3:
|
|
|
|
|
case EOpConstructDMat4x4:
|
|
|
|
|
case EOpConstructDouble:
|
|
|
|
|
basicOp = EOpConstructDouble;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EOpConstructIVec2:
|
|
|
|
|
case EOpConstructIVec3:
|
|
|
|
|
case EOpConstructIVec4:
|
2017-05-21 03:40:27 +00:00
|
|
|
|
case EOpConstructIMat2x2:
|
|
|
|
|
case EOpConstructIMat2x3:
|
|
|
|
|
case EOpConstructIMat2x4:
|
|
|
|
|
case EOpConstructIMat3x2:
|
|
|
|
|
case EOpConstructIMat3x3:
|
|
|
|
|
case EOpConstructIMat3x4:
|
|
|
|
|
case EOpConstructIMat4x2:
|
|
|
|
|
case EOpConstructIMat4x3:
|
|
|
|
|
case EOpConstructIMat4x4:
|
2016-03-13 03:11:22 +00:00
|
|
|
|
case EOpConstructInt:
|
|
|
|
|
basicOp = EOpConstructInt;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EOpConstructUVec2:
|
|
|
|
|
case EOpConstructUVec3:
|
|
|
|
|
case EOpConstructUVec4:
|
2017-05-21 03:40:27 +00:00
|
|
|
|
case EOpConstructUMat2x2:
|
|
|
|
|
case EOpConstructUMat2x3:
|
|
|
|
|
case EOpConstructUMat2x4:
|
|
|
|
|
case EOpConstructUMat3x2:
|
|
|
|
|
case EOpConstructUMat3x3:
|
|
|
|
|
case EOpConstructUMat3x4:
|
|
|
|
|
case EOpConstructUMat4x2:
|
|
|
|
|
case EOpConstructUMat4x3:
|
|
|
|
|
case EOpConstructUMat4x4:
|
2016-03-13 03:11:22 +00:00
|
|
|
|
case EOpConstructUint:
|
|
|
|
|
basicOp = EOpConstructUint;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EOpConstructBVec2:
|
|
|
|
|
case EOpConstructBVec3:
|
|
|
|
|
case EOpConstructBVec4:
|
2017-05-21 03:40:27 +00:00
|
|
|
|
case EOpConstructBMat2x2:
|
|
|
|
|
case EOpConstructBMat2x3:
|
|
|
|
|
case EOpConstructBMat2x4:
|
|
|
|
|
case EOpConstructBMat3x2:
|
|
|
|
|
case EOpConstructBMat3x3:
|
|
|
|
|
case EOpConstructBMat3x4:
|
|
|
|
|
case EOpConstructBMat4x2:
|
|
|
|
|
case EOpConstructBMat4x3:
|
|
|
|
|
case EOpConstructBMat4x4:
|
2016-03-13 03:11:22 +00:00
|
|
|
|
case EOpConstructBool:
|
|
|
|
|
basicOp = EOpConstructBool;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
error(loc, "unsupported construction", "", "");
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
newNode = intermediate.addUnaryMath(basicOp, node, node->getLoc());
|
|
|
|
|
if (newNode == nullptr) {
|
|
|
|
|
error(loc, "can't convert", "constructor", "");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Now, if there still isn't an operation to do the construction, and we need one, add one.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// Otherwise, skip out early.
|
|
|
|
|
if (subset || (newNode != node && newNode->getType() == type))
|
|
|
|
|
return newNode;
|
|
|
|
|
|
|
|
|
|
// setAggregateOperator will insert a new node for the constructor, as needed.
|
|
|
|
|
return intermediate.setAggregateOperator(newNode, op, type, loc);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 05:13:10 +00:00
|
|
|
|
// Convert the array in node to the requested type, which is also an array.
|
|
|
|
|
// Returns nullptr on failure, otherwise returns aggregate holding the list of
|
|
|
|
|
// elements needed to construct the array.
|
|
|
|
|
TIntermTyped* HlslParseContext::convertArray(TIntermTyped* node, const TType& type)
|
|
|
|
|
{
|
|
|
|
|
assert(node->isArray() && type.isArray());
|
|
|
|
|
if (node->getType().computeNumComponents() < type.computeNumComponents())
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
// TODO: write an argument replicator, for the case the argument should not be
|
|
|
|
|
// executed multiple times, yet multiple copies are needed.
|
|
|
|
|
|
|
|
|
|
TIntermTyped* constructee = node->getAsTyped();
|
|
|
|
|
// track where we are in consuming the argument
|
|
|
|
|
int constructeeElement = 0;
|
|
|
|
|
int constructeeComponent = 0;
|
|
|
|
|
|
|
|
|
|
// bump up to the next component to consume
|
|
|
|
|
const auto getNextComponent = [&]() {
|
|
|
|
|
TIntermTyped* component;
|
|
|
|
|
component = handleBracketDereference(node->getLoc(), constructee,
|
|
|
|
|
intermediate.addConstantUnion(constructeeElement, node->getLoc()));
|
|
|
|
|
if (component->isVector())
|
|
|
|
|
component = handleBracketDereference(node->getLoc(), component,
|
|
|
|
|
intermediate.addConstantUnion(constructeeComponent, node->getLoc()));
|
|
|
|
|
// bump component pointer up
|
|
|
|
|
++constructeeComponent;
|
|
|
|
|
if (constructeeComponent == constructee->getVectorSize()) {
|
|
|
|
|
constructeeComponent = 0;
|
|
|
|
|
++constructeeElement;
|
|
|
|
|
}
|
|
|
|
|
return component;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// make one subnode per constructed array element
|
|
|
|
|
TIntermAggregate* constructor = nullptr;
|
|
|
|
|
TType derefType(type, 0);
|
|
|
|
|
TType speculativeComponentType(derefType, 0);
|
|
|
|
|
TType* componentType = derefType.isVector() ? &speculativeComponentType : &derefType;
|
|
|
|
|
TOperator componentOp = intermediate.mapTypeToConstructorOp(*componentType);
|
|
|
|
|
TType crossType(node->getBasicType(), EvqTemporary, type.getVectorSize());
|
|
|
|
|
for (int e = 0; e < type.getOuterArraySize(); ++e) {
|
|
|
|
|
// construct an element
|
|
|
|
|
TIntermTyped* elementArg;
|
|
|
|
|
if (type.getVectorSize() == constructee->getVectorSize()) {
|
|
|
|
|
// same element shape
|
|
|
|
|
elementArg = handleBracketDereference(node->getLoc(), constructee,
|
|
|
|
|
intermediate.addConstantUnion(e, node->getLoc()));
|
|
|
|
|
} else {
|
|
|
|
|
// mismatched element shapes
|
|
|
|
|
if (type.getVectorSize() == 1)
|
|
|
|
|
elementArg = getNextComponent();
|
|
|
|
|
else {
|
|
|
|
|
// make a vector
|
|
|
|
|
TIntermAggregate* elementConstructee = nullptr;
|
|
|
|
|
for (int c = 0; c < type.getVectorSize(); ++c)
|
|
|
|
|
elementConstructee = intermediate.growAggregate(elementConstructee, getNextComponent());
|
|
|
|
|
elementArg = addConstructor(node->getLoc(), elementConstructee, crossType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// convert basic types
|
|
|
|
|
elementArg = intermediate.addConversion(componentOp, derefType, elementArg);
|
|
|
|
|
if (elementArg == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
// combine with top-level constructor
|
|
|
|
|
constructor = intermediate.growAggregate(constructor, elementArg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return constructor;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// This function tests for the type of the parameters to the structure or array constructor. Raises
|
|
|
|
|
// an error message if the expected type does not match the parameter passed to the constructor.
|
|
|
|
|
//
|
|
|
|
|
// Returns nullptr for an error or the input node itself if the expected and the given parameter types match.
|
|
|
|
|
//
|
2017-06-14 05:13:10 +00:00
|
|
|
|
TIntermTyped* HlslParseContext::constructAggregate(TIntermNode* node, const TType& type, int paramCount,
|
|
|
|
|
const TSourceLoc& loc)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
2017-06-14 05:13:10 +00:00
|
|
|
|
// Handle cases that map more 1:1 between constructor arguments and constructed.
|
2016-03-13 03:11:22 +00:00
|
|
|
|
TIntermTyped* converted = intermediate.addConversion(EOpConstructStruct, type, node->getAsTyped());
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (converted == nullptr || converted->getType() != type) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
error(loc, "", "constructor", "cannot convert parameter %d from '%s' to '%s'", paramCount,
|
|
|
|
|
node->getAsTyped()->getType().getCompleteString().c_str(), type.getCompleteString().c_str());
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return converted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Do everything needed to add an interface block.
|
|
|
|
|
//
|
2016-07-25 22:05:33 +00:00
|
|
|
|
void HlslParseContext::declareBlock(const TSourceLoc& loc, TType& type, const TString* instanceName, TArraySizes* arraySizes)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
2016-07-25 22:05:33 +00:00
|
|
|
|
assert(type.getWritableStruct() != nullptr);
|
|
|
|
|
|
2017-02-07 01:44:52 +00:00
|
|
|
|
// Clean up top-level decorations that don't belong.
|
|
|
|
|
switch (type.getQualifier().storage) {
|
|
|
|
|
case EvqUniform:
|
|
|
|
|
case EvqBuffer:
|
|
|
|
|
correctUniform(type.getQualifier());
|
|
|
|
|
break;
|
|
|
|
|
case EvqVaryingIn:
|
|
|
|
|
correctInput(type.getQualifier());
|
|
|
|
|
break;
|
|
|
|
|
case EvqVaryingOut:
|
|
|
|
|
correctOutput(type.getQualifier());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-25 22:05:33 +00:00
|
|
|
|
TTypeList& typeList = *type.getWritableStruct();
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// fix and check for member storage qualifiers and types that don't belong within a block
|
|
|
|
|
for (unsigned int member = 0; member < typeList.size(); ++member) {
|
|
|
|
|
TType& memberType = *typeList[member].type;
|
|
|
|
|
TQualifier& memberQualifier = memberType.getQualifier();
|
|
|
|
|
const TSourceLoc& memberLoc = typeList[member].loc;
|
|
|
|
|
globalQualifierFix(memberLoc, memberQualifier);
|
2016-07-25 22:05:33 +00:00
|
|
|
|
memberQualifier.storage = type.getQualifier().storage;
|
2017-02-07 01:44:52 +00:00
|
|
|
|
|
|
|
|
|
if (memberType.isStruct()) {
|
|
|
|
|
// clean up and pick up the right set of decorations
|
|
|
|
|
auto it = ioTypeMap.find(memberType.getStruct());
|
|
|
|
|
switch (type.getQualifier().storage) {
|
|
|
|
|
case EvqUniform:
|
|
|
|
|
case EvqBuffer:
|
|
|
|
|
correctUniform(type.getQualifier());
|
|
|
|
|
if (it != ioTypeMap.end() && it->second.uniform)
|
2017-08-04 21:40:53 +00:00
|
|
|
|
memberType.setStruct(it->second.uniform);
|
2017-02-07 01:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case EvqVaryingIn:
|
|
|
|
|
correctInput(type.getQualifier());
|
|
|
|
|
if (it != ioTypeMap.end() && it->second.input)
|
2017-08-04 21:40:53 +00:00
|
|
|
|
memberType.setStruct(it->second.input);
|
2017-02-07 01:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case EvqVaryingOut:
|
|
|
|
|
correctOutput(type.getQualifier());
|
|
|
|
|
if (it != ioTypeMap.end() && it->second.output)
|
2017-08-04 21:40:53 +00:00
|
|
|
|
memberType.setStruct(it->second.output);
|
2017-02-07 01:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make default block qualification, and adjust the member qualifications
|
|
|
|
|
|
|
|
|
|
TQualifier defaultQualification;
|
2016-07-25 22:05:33 +00:00
|
|
|
|
switch (type.getQualifier().storage) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
case EvqUniform: defaultQualification = globalUniformDefaults; break;
|
|
|
|
|
case EvqBuffer: defaultQualification = globalBufferDefaults; break;
|
|
|
|
|
case EvqVaryingIn: defaultQualification = globalInputDefaults; break;
|
|
|
|
|
case EvqVaryingOut: defaultQualification = globalOutputDefaults; break;
|
|
|
|
|
default: defaultQualification.clear(); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Special case for "push_constant uniform", which has a default of std430,
|
|
|
|
|
// contrary to normal uniform defaults, and can't have a default tracked for it.
|
2016-07-25 22:05:33 +00:00
|
|
|
|
if (type.getQualifier().layoutPushConstant && ! type.getQualifier().hasPacking())
|
|
|
|
|
type.getQualifier().layoutPacking = ElpStd430;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
// fix and check for member layout qualifiers
|
|
|
|
|
|
2016-07-25 22:05:33 +00:00
|
|
|
|
mergeObjectLayoutQualifiers(defaultQualification, type.getQualifier(), true);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
bool memberWithLocation = false;
|
|
|
|
|
bool memberWithoutLocation = false;
|
|
|
|
|
for (unsigned int member = 0; member < typeList.size(); ++member) {
|
|
|
|
|
TQualifier& memberQualifier = typeList[member].type->getQualifier();
|
|
|
|
|
const TSourceLoc& memberLoc = typeList[member].loc;
|
|
|
|
|
if (memberQualifier.hasStream()) {
|
|
|
|
|
if (defaultQualification.layoutStream != memberQualifier.layoutStream)
|
|
|
|
|
error(memberLoc, "member cannot contradict block", "stream", "");
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// "This includes a block's inheritance of the
|
|
|
|
|
// current global default buffer, a block member's inheritance of the block's
|
|
|
|
|
// buffer, and the requirement that any *xfb_buffer* declared on a block
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// member must match the buffer inherited from the block."
|
|
|
|
|
if (memberQualifier.hasXfbBuffer()) {
|
|
|
|
|
if (defaultQualification.layoutXfbBuffer != memberQualifier.layoutXfbBuffer)
|
|
|
|
|
error(memberLoc, "member cannot contradict block (or what block inherited from global)", "xfb_buffer", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (memberQualifier.hasLocation()) {
|
2016-07-25 22:05:33 +00:00
|
|
|
|
switch (type.getQualifier().storage) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
case EvqVaryingIn:
|
|
|
|
|
case EvqVaryingOut:
|
|
|
|
|
memberWithLocation = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
memberWithoutLocation = true;
|
|
|
|
|
|
|
|
|
|
TQualifier newMemberQualification = defaultQualification;
|
2016-09-16 23:10:39 +00:00
|
|
|
|
mergeQualifiers(newMemberQualification, memberQualifier);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
memberQualifier = newMemberQualification;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Process the members
|
2016-07-25 22:05:33 +00:00
|
|
|
|
fixBlockLocations(loc, type.getQualifier(), typeList, memberWithLocation, memberWithoutLocation);
|
|
|
|
|
fixBlockXfbOffsets(type.getQualifier(), typeList);
|
|
|
|
|
fixBlockUniformOffsets(type.getQualifier(), typeList);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
// reverse merge, so that currentBlockQualifier now has all layout information
|
|
|
|
|
// (can't use defaultQualification directly, it's missing other non-layout-default-class qualifiers)
|
2016-07-25 22:05:33 +00:00
|
|
|
|
mergeObjectLayoutQualifiers(type.getQualifier(), defaultQualification, true);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Build and add the interface block as a new type named 'blockName'
|
|
|
|
|
//
|
|
|
|
|
|
2016-09-21 20:19:40 +00:00
|
|
|
|
// Use the instance name as the interface name if one exists, else the block name.
|
|
|
|
|
const TString& interfaceName = (instanceName && !instanceName->empty()) ? *instanceName : type.getTypeName();
|
|
|
|
|
|
|
|
|
|
TType blockType(&typeList, interfaceName, type.getQualifier());
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (arraySizes)
|
|
|
|
|
blockType.newArraySizes(*arraySizes);
|
|
|
|
|
|
|
|
|
|
// Add the variable, as anonymous or named instanceName.
|
|
|
|
|
// Make an anonymous variable if no name was provided.
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (instanceName == nullptr)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
instanceName = NewPoolTString("");
|
|
|
|
|
|
|
|
|
|
TVariable& variable = *new TVariable(instanceName, blockType);
|
|
|
|
|
if (! symbolTable.insert(variable)) {
|
|
|
|
|
if (*instanceName == "")
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "nameless block contains a member that already has a name at global scope",
|
|
|
|
|
"" /* blockName->c_str() */, "");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
else
|
|
|
|
|
error(loc, "block instance name redefinition", variable.getName().c_str(), "");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save it in the AST for linker use.
|
2017-01-19 22:41:47 +00:00
|
|
|
|
trackLinkage(variable);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// "For a block, this process applies to the entire block, or until the first member
|
|
|
|
|
// is reached that has a location layout qualifier. When a block member is declared with a location
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// qualifier, its location comes from that qualifier: The member's location qualifier overrides the block-level
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// declaration. Subsequent members are again assigned consecutive locations, based on the newest location,
|
|
|
|
|
// until the next member declared with a location qualifier. The values used for locations do not have to be
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// declared in increasing order."
|
|
|
|
|
void HlslParseContext::fixBlockLocations(const TSourceLoc& loc, TQualifier& qualifier, TTypeList& typeList, bool memberWithLocation, bool memberWithoutLocation)
|
|
|
|
|
{
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// "If a block has no block-level location layout qualifier, it is required that either all or none of its members
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// have a location layout qualifier, or a compile-time error results."
|
|
|
|
|
if (! qualifier.hasLocation() && memberWithLocation && memberWithoutLocation)
|
|
|
|
|
error(loc, "either the block needs a location, or all members need a location, or no members have a location", "location", "");
|
|
|
|
|
else {
|
|
|
|
|
if (memberWithLocation) {
|
|
|
|
|
// remove any block-level location and make it per *every* member
|
|
|
|
|
int nextLocation = 0; // by the rule above, initial value is not relevant
|
|
|
|
|
if (qualifier.hasAnyLocation()) {
|
|
|
|
|
nextLocation = qualifier.layoutLocation;
|
|
|
|
|
qualifier.layoutLocation = TQualifier::layoutLocationEnd;
|
|
|
|
|
if (qualifier.hasComponent()) {
|
|
|
|
|
// "It is a compile-time error to apply the *component* qualifier to a ... block"
|
|
|
|
|
error(loc, "cannot apply to a block", "component", "");
|
|
|
|
|
}
|
|
|
|
|
if (qualifier.hasIndex()) {
|
|
|
|
|
error(loc, "cannot apply to a block", "index", "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (unsigned int member = 0; member < typeList.size(); ++member) {
|
|
|
|
|
TQualifier& memberQualifier = typeList[member].type->getQualifier();
|
|
|
|
|
const TSourceLoc& memberLoc = typeList[member].loc;
|
|
|
|
|
if (! memberQualifier.hasLocation()) {
|
|
|
|
|
if (nextLocation >= (int)TQualifier::layoutLocationEnd)
|
|
|
|
|
error(memberLoc, "location is too large", "location", "");
|
|
|
|
|
memberQualifier.layoutLocation = nextLocation;
|
|
|
|
|
memberQualifier.layoutComponent = 0;
|
|
|
|
|
}
|
2017-07-28 22:20:13 +00:00
|
|
|
|
nextLocation = memberQualifier.layoutLocation +
|
|
|
|
|
intermediate.computeTypeLocationSize(*typeList[member].type);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HlslParseContext::fixBlockXfbOffsets(TQualifier& qualifier, TTypeList& typeList)
|
|
|
|
|
{
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// "If a block is qualified with xfb_offset, all its
|
|
|
|
|
// members are assigned transform feedback buffer offsets. If a block is not qualified with xfb_offset, any
|
|
|
|
|
// members of that block not qualified with an xfb_offset will not be assigned transform feedback buffer
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// offsets."
|
|
|
|
|
|
|
|
|
|
if (! qualifier.hasXfbBuffer() || ! qualifier.hasXfbOffset())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int nextOffset = qualifier.layoutXfbOffset;
|
|
|
|
|
for (unsigned int member = 0; member < typeList.size(); ++member) {
|
|
|
|
|
TQualifier& memberQualifier = typeList[member].type->getQualifier();
|
|
|
|
|
bool containsDouble = false;
|
|
|
|
|
int memberSize = intermediate.computeTypeXfbSize(*typeList[member].type, containsDouble);
|
|
|
|
|
// see if we need to auto-assign an offset to this member
|
|
|
|
|
if (! memberQualifier.hasXfbOffset()) {
|
|
|
|
|
// "if applied to an aggregate containing a double, the offset must also be a multiple of 8"
|
|
|
|
|
if (containsDouble)
|
|
|
|
|
RoundToPow2(nextOffset, 8);
|
|
|
|
|
memberQualifier.layoutXfbOffset = nextOffset;
|
|
|
|
|
} else
|
|
|
|
|
nextOffset = memberQualifier.layoutXfbOffset;
|
|
|
|
|
nextOffset += memberSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The above gave all block members an offset, so we can take it off the block now,
|
|
|
|
|
// which will avoid double counting the offset usage.
|
|
|
|
|
qualifier.layoutXfbOffset = TQualifier::layoutXfbOffsetEnd;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// Calculate and save the offset of each block member, using the recursively
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// defined block offset rules and the user-provided offset and align.
|
|
|
|
|
//
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// Also, compute and save the total size of the block. For the block's size, arrayness
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// is not taken into account, as each element is backed by a separate buffer.
|
|
|
|
|
//
|
2016-09-28 01:13:05 +00:00
|
|
|
|
void HlslParseContext::fixBlockUniformOffsets(const TQualifier& qualifier, TTypeList& typeList)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (! qualifier.isUniformOrBuffer())
|
|
|
|
|
return;
|
|
|
|
|
if (qualifier.layoutPacking != ElpStd140 && qualifier.layoutPacking != ElpStd430)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int offset = 0;
|
|
|
|
|
int memberSize;
|
|
|
|
|
for (unsigned int member = 0; member < typeList.size(); ++member) {
|
|
|
|
|
TQualifier& memberQualifier = typeList[member].type->getQualifier();
|
|
|
|
|
const TSourceLoc& memberLoc = typeList[member].loc;
|
|
|
|
|
|
|
|
|
|
// "When align is applied to an array, it effects only the start of the array, not the array's internal stride."
|
|
|
|
|
|
|
|
|
|
// modify just the children's view of matrix layout, if there is one for this member
|
|
|
|
|
TLayoutMatrix subMatrixLayout = typeList[member].type->getQualifier().layoutMatrix;
|
|
|
|
|
int dummyStride;
|
2016-09-28 01:13:05 +00:00
|
|
|
|
int memberAlignment = intermediate.getBaseAlignment(*typeList[member].type, memberSize, dummyStride,
|
|
|
|
|
qualifier.layoutPacking == ElpStd140,
|
2017-07-28 22:20:13 +00:00
|
|
|
|
subMatrixLayout != ElmNone
|
|
|
|
|
? subMatrixLayout == ElmRowMajor
|
|
|
|
|
: qualifier.layoutMatrix == ElmRowMajor);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
if (memberQualifier.hasOffset()) {
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// "The specified offset must be a multiple
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// of the base alignment of the type of the block member it qualifies, or a compile-time error results."
|
|
|
|
|
if (! IsMultipleOfPow2(memberQualifier.layoutOffset, memberAlignment))
|
|
|
|
|
error(memberLoc, "must be a multiple of the member's alignment", "offset", "");
|
|
|
|
|
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// "The offset qualifier forces the qualified member to start at or after the specified
|
|
|
|
|
// integral-constant expression, which will be its byte offset from the beginning of the buffer.
|
|
|
|
|
// "The actual offset of a member is computed as
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// follows: If offset was declared, start with that offset, otherwise start with the next available offset."
|
|
|
|
|
offset = std::max(offset, memberQualifier.layoutOffset);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// "The actual alignment of a member will be the greater of the specified align alignment and the standard
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// (e.g., std140) base alignment for the member's type."
|
|
|
|
|
if (memberQualifier.hasAlign())
|
|
|
|
|
memberAlignment = std::max(memberAlignment, memberQualifier.layoutAlign);
|
|
|
|
|
|
|
|
|
|
// "If the resulting offset is not a multiple of the actual alignment,
|
2017-01-06 07:34:48 +00:00
|
|
|
|
// increase it to the first offset that is a multiple of
|
2016-03-13 03:11:22 +00:00
|
|
|
|
// the actual alignment."
|
|
|
|
|
RoundToPow2(offset, memberAlignment);
|
|
|
|
|
typeList[member].type->getQualifier().layoutOffset = offset;
|
|
|
|
|
offset += memberSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For an identifier that is already declared, add more qualification to it.
|
|
|
|
|
void HlslParseContext::addQualifierToExisting(const TSourceLoc& loc, TQualifier qualifier, const TString& identifier)
|
|
|
|
|
{
|
|
|
|
|
TSymbol* symbol = symbolTable.find(identifier);
|
2017-06-19 22:25:44 +00:00
|
|
|
|
if (symbol == nullptr) {
|
2016-03-13 03:11:22 +00:00
|
|
|
|
error(loc, "identifier not previously declared", identifier.c_str(), "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (symbol->getAsFunction()) {
|
|
|
|
|
error(loc, "cannot re-qualify a function name", identifier.c_str(), "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (qualifier.isAuxiliary() ||
|
|
|
|
|
qualifier.isMemory() ||
|
|
|
|
|
qualifier.isInterpolation() ||
|
|
|
|
|
qualifier.hasLayout() ||
|
|
|
|
|
qualifier.storage != EvqTemporary ||
|
|
|
|
|
qualifier.precision != EpqNone) {
|
|
|
|
|
error(loc, "cannot add storage, auxiliary, memory, interpolation, layout, or precision qualifier to an existing variable", identifier.c_str(), "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For read-only built-ins, add a new symbol for holding the modified qualifier.
|
|
|
|
|
// This will bring up an entire block, if a block type has to be modified (e.g., gl_Position inside a block)
|
|
|
|
|
if (symbol->isReadOnly())
|
|
|
|
|
symbol = symbolTable.copyUp(symbol);
|
|
|
|
|
|
|
|
|
|
if (qualifier.invariant) {
|
|
|
|
|
if (intermediate.inIoAccessed(identifier))
|
|
|
|
|
error(loc, "cannot change qualification after use", "invariant", "");
|
|
|
|
|
symbol->getWritableType().getQualifier().invariant = true;
|
2016-05-04 18:36:14 +00:00
|
|
|
|
} else if (qualifier.noContraction) {
|
|
|
|
|
if (intermediate.inIoAccessed(identifier))
|
|
|
|
|
error(loc, "cannot change qualification after use", "precise", "");
|
|
|
|
|
symbol->getWritableType().getQualifier().noContraction = true;
|
|
|
|
|
} else if (qualifier.specConstant) {
|
|
|
|
|
symbol->getWritableType().getQualifier().makeSpecConstant();
|
|
|
|
|
if (qualifier.hasSpecConstantId())
|
|
|
|
|
symbol->getWritableType().getQualifier().layoutSpecConstantId = qualifier.layoutSpecConstantId;
|
2016-03-13 03:11:22 +00:00
|
|
|
|
} else
|
|
|
|
|
warn(loc, "unknown requalification", "", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HlslParseContext::addQualifierToExisting(const TSourceLoc& loc, TQualifier qualifier, TIdentifierList& identifiers)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned int i = 0; i < identifiers.size(); ++i)
|
|
|
|
|
addQualifierToExisting(loc, qualifier, *identifiers[i]);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 22:04:20 +00:00
|
|
|
|
//
|
|
|
|
|
// Update the intermediate for the given input geometry
|
|
|
|
|
//
|
|
|
|
|
bool HlslParseContext::handleInputGeometry(const TSourceLoc& loc, const TLayoutGeometry& geometry)
|
|
|
|
|
{
|
|
|
|
|
switch (geometry) {
|
|
|
|
|
case ElgPoints: // fall through
|
|
|
|
|
case ElgLines: // ...
|
|
|
|
|
case ElgTriangles: // ...
|
|
|
|
|
case ElgLinesAdjacency: // ...
|
|
|
|
|
case ElgTrianglesAdjacency: // ...
|
|
|
|
|
if (! intermediate.setInputPrimitive(geometry)) {
|
|
|
|
|
error(loc, "input primitive geometry redefinition", TQualifier::getGeometryString(geometry), "");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
error(loc, "cannot apply to 'in'", TQualifier::getGeometryString(geometry), "");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Update the intermediate for the given output geometry
|
|
|
|
|
//
|
|
|
|
|
bool HlslParseContext::handleOutputGeometry(const TSourceLoc& loc, const TLayoutGeometry& geometry)
|
|
|
|
|
{
|
|
|
|
|
switch (geometry) {
|
|
|
|
|
case ElgPoints:
|
|
|
|
|
case ElgLineStrip:
|
|
|
|
|
case ElgTriangleStrip:
|
|
|
|
|
if (! intermediate.setOutputPrimitive(geometry)) {
|
|
|
|
|
error(loc, "output primitive geometry redefinition", TQualifier::getGeometryString(geometry), "");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
error(loc, "cannot apply to 'out'", TQualifier::getGeometryString(geometry), "");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 15:23:40 +00:00
|
|
|
|
//
|
|
|
|
|
// Selection hints
|
|
|
|
|
//
|
|
|
|
|
TSelectionControl HlslParseContext::handleSelectionControl(const TAttributeMap& attributes) const
|
|
|
|
|
{
|
|
|
|
|
if (attributes.contains(EatFlatten))
|
|
|
|
|
return ESelectionControlFlatten;
|
|
|
|
|
else if (attributes.contains(EatBranch))
|
|
|
|
|
return ESelectionControlDontFlatten;
|
|
|
|
|
else
|
|
|
|
|
return ESelectionControlNone;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-03 02:14:50 +00:00
|
|
|
|
//
|
|
|
|
|
// Loop hints
|
|
|
|
|
//
|
|
|
|
|
TLoopControl HlslParseContext::handleLoopControl(const TAttributeMap& attributes) const
|
|
|
|
|
{
|
|
|
|
|
if (attributes.contains(EatUnroll))
|
|
|
|
|
return ELoopControlUnroll;
|
|
|
|
|
else if (attributes.contains(EatLoop))
|
|
|
|
|
return ELoopControlDontUnroll;
|
|
|
|
|
else
|
|
|
|
|
return ELoopControlNone;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
//
|
|
|
|
|
// Updating default qualifier for the case of a declaration with just a qualifier,
|
|
|
|
|
// no type, block, or identifier.
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::updateStandaloneQualifierDefaults(const TSourceLoc& loc, const TPublicType& publicType)
|
|
|
|
|
{
|
|
|
|
|
if (publicType.shaderQualifiers.vertices != TQualifier::layoutNotSet) {
|
|
|
|
|
assert(language == EShLangTessControl || language == EShLangGeometry);
|
2016-07-09 04:09:10 +00:00
|
|
|
|
// const char* id = (language == EShLangTessControl) ? "vertices" : "max_vertices";
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
if (publicType.shaderQualifiers.invocations != TQualifier::layoutNotSet) {
|
|
|
|
|
if (! intermediate.setInvocations(publicType.shaderQualifiers.invocations))
|
|
|
|
|
error(loc, "cannot change previously set layout value", "invocations", "");
|
|
|
|
|
}
|
|
|
|
|
if (publicType.shaderQualifiers.geometry != ElgNone) {
|
|
|
|
|
if (publicType.qualifier.storage == EvqVaryingIn) {
|
|
|
|
|
switch (publicType.shaderQualifiers.geometry) {
|
|
|
|
|
case ElgPoints:
|
|
|
|
|
case ElgLines:
|
|
|
|
|
case ElgLinesAdjacency:
|
|
|
|
|
case ElgTriangles:
|
|
|
|
|
case ElgTrianglesAdjacency:
|
|
|
|
|
case ElgQuads:
|
|
|
|
|
case ElgIsolines:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "cannot apply to input", TQualifier::getGeometryString(publicType.shaderQualifiers.geometry),
|
|
|
|
|
"");
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (publicType.qualifier.storage == EvqVaryingOut) {
|
2016-11-17 22:04:20 +00:00
|
|
|
|
handleOutputGeometry(loc, publicType.shaderQualifiers.geometry);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
} else
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "cannot apply to:", TQualifier::getGeometryString(publicType.shaderQualifiers.geometry),
|
|
|
|
|
GetStorageQualifierString(publicType.qualifier.storage));
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
if (publicType.shaderQualifiers.spacing != EvsNone)
|
|
|
|
|
intermediate.setVertexSpacing(publicType.shaderQualifiers.spacing);
|
|
|
|
|
if (publicType.shaderQualifiers.order != EvoNone)
|
|
|
|
|
intermediate.setVertexOrder(publicType.shaderQualifiers.order);
|
|
|
|
|
if (publicType.shaderQualifiers.pointMode)
|
|
|
|
|
intermediate.setPointMode();
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
|
if (publicType.shaderQualifiers.localSize[i] > 1) {
|
|
|
|
|
int max = 0;
|
|
|
|
|
switch (i) {
|
|
|
|
|
case 0: max = resources.maxComputeWorkGroupSizeX; break;
|
|
|
|
|
case 1: max = resources.maxComputeWorkGroupSizeY; break;
|
|
|
|
|
case 2: max = resources.maxComputeWorkGroupSizeZ; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
if (intermediate.getLocalSize(i) > (unsigned int)max)
|
|
|
|
|
error(loc, "too large; see gl_MaxComputeWorkGroupSize", "local_size", "");
|
|
|
|
|
|
|
|
|
|
// Fix the existing constant gl_WorkGroupSize with this new information.
|
|
|
|
|
TVariable* workGroupSize = getEditableVariable("gl_WorkGroupSize");
|
|
|
|
|
workGroupSize->getWritableConstArray()[i].setUConst(intermediate.getLocalSize(i));
|
|
|
|
|
}
|
|
|
|
|
if (publicType.shaderQualifiers.localSizeSpecId[i] != TQualifier::layoutNotSet) {
|
|
|
|
|
intermediate.setLocalSizeSpecId(i, publicType.shaderQualifiers.localSizeSpecId[i]);
|
|
|
|
|
// Set the workgroup built-in variable as a specialization constant
|
|
|
|
|
TVariable* workGroupSize = getEditableVariable("gl_WorkGroupSize");
|
|
|
|
|
workGroupSize->getWritableType().getQualifier().specConstant = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (publicType.shaderQualifiers.earlyFragmentTests)
|
|
|
|
|
intermediate.setEarlyFragmentTests();
|
|
|
|
|
|
|
|
|
|
const TQualifier& qualifier = publicType.qualifier;
|
|
|
|
|
|
|
|
|
|
switch (qualifier.storage) {
|
|
|
|
|
case EvqUniform:
|
|
|
|
|
if (qualifier.hasMatrix())
|
|
|
|
|
globalUniformDefaults.layoutMatrix = qualifier.layoutMatrix;
|
|
|
|
|
if (qualifier.hasPacking())
|
|
|
|
|
globalUniformDefaults.layoutPacking = qualifier.layoutPacking;
|
|
|
|
|
break;
|
|
|
|
|
case EvqBuffer:
|
|
|
|
|
if (qualifier.hasMatrix())
|
|
|
|
|
globalBufferDefaults.layoutMatrix = qualifier.layoutMatrix;
|
|
|
|
|
if (qualifier.hasPacking())
|
|
|
|
|
globalBufferDefaults.layoutPacking = qualifier.layoutPacking;
|
|
|
|
|
break;
|
|
|
|
|
case EvqVaryingIn:
|
|
|
|
|
break;
|
|
|
|
|
case EvqVaryingOut:
|
|
|
|
|
if (qualifier.hasStream())
|
|
|
|
|
globalOutputDefaults.layoutStream = qualifier.layoutStream;
|
|
|
|
|
if (qualifier.hasXfbBuffer())
|
|
|
|
|
globalOutputDefaults.layoutXfbBuffer = qualifier.layoutXfbBuffer;
|
|
|
|
|
if (globalOutputDefaults.hasXfbBuffer() && qualifier.hasXfbStride()) {
|
|
|
|
|
if (! intermediate.setXfbBufferStride(globalOutputDefaults.layoutXfbBuffer, qualifier.layoutXfbStride))
|
2017-07-28 22:20:13 +00:00
|
|
|
|
error(loc, "all stride settings must match for xfb buffer", "xfb_stride", "%d",
|
|
|
|
|
qualifier.layoutXfbBuffer);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
error(loc, "default qualifier requires 'uniform', 'buffer', 'in', or 'out' storage qualification", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Take the sequence of statements that has been built up since the last case/default,
|
|
|
|
|
// put it on the list of top-level nodes for the current (inner-most) switch statement,
|
|
|
|
|
// and follow that by the case/default we are on now. (See switch topology comment on
|
|
|
|
|
// TIntermSwitch.)
|
|
|
|
|
//
|
|
|
|
|
void HlslParseContext::wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode)
|
|
|
|
|
{
|
|
|
|
|
TIntermSequence* switchSequence = switchSequenceStack.back();
|
|
|
|
|
|
|
|
|
|
if (statements) {
|
|
|
|
|
statements->setOperator(EOpSequence);
|
|
|
|
|
switchSequence->push_back(statements);
|
|
|
|
|
}
|
|
|
|
|
if (branchNode) {
|
|
|
|
|
// check all previous cases for the same label (or both are 'default')
|
|
|
|
|
for (unsigned int s = 0; s < switchSequence->size(); ++s) {
|
|
|
|
|
TIntermBranch* prevBranch = (*switchSequence)[s]->getAsBranchNode();
|
|
|
|
|
if (prevBranch) {
|
|
|
|
|
TIntermTyped* prevExpression = prevBranch->getExpression();
|
|
|
|
|
TIntermTyped* newExpression = branchNode->getAsBranchNode()->getExpression();
|
|
|
|
|
if (prevExpression == nullptr && newExpression == nullptr)
|
|
|
|
|
error(branchNode->getLoc(), "duplicate label", "default", "");
|
|
|
|
|
else if (prevExpression != nullptr &&
|
|
|
|
|
newExpression != nullptr &&
|
|
|
|
|
prevExpression->getAsConstantUnion() &&
|
|
|
|
|
newExpression->getAsConstantUnion() &&
|
|
|
|
|
prevExpression->getAsConstantUnion()->getConstArray()[0].getIConst() ==
|
|
|
|
|
newExpression->getAsConstantUnion()->getConstArray()[0].getIConst())
|
|
|
|
|
error(branchNode->getLoc(), "duplicated value", "case", "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
switchSequence->push_back(branchNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Turn the top-level node sequence built up of wrapupSwitchSubsequence
|
|
|
|
|
// into a switch node.
|
|
|
|
|
//
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermNode* HlslParseContext::addSwitch(const TSourceLoc& loc, TIntermTyped* expression,
|
|
|
|
|
TIntermAggregate* lastStatements, TSelectionControl control)
|
2016-03-13 03:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
wrapupSwitchSubsequence(lastStatements, nullptr);
|
|
|
|
|
|
|
|
|
|
if (expression == nullptr ||
|
|
|
|
|
(expression->getBasicType() != EbtInt && expression->getBasicType() != EbtUint) ||
|
|
|
|
|
expression->getType().isArray() || expression->getType().isMatrix() || expression->getType().isVector())
|
|
|
|
|
error(loc, "condition must be a scalar integer expression", "switch", "");
|
|
|
|
|
|
|
|
|
|
// If there is nothing to do, drop the switch but still execute the expression
|
|
|
|
|
TIntermSequence* switchSequence = switchSequenceStack.back();
|
|
|
|
|
if (switchSequence->size() == 0)
|
|
|
|
|
return expression;
|
|
|
|
|
|
|
|
|
|
if (lastStatements == nullptr) {
|
|
|
|
|
// emulate a break for error recovery
|
|
|
|
|
lastStatements = intermediate.makeAggregate(intermediate.addBranch(EOpBreak, loc));
|
|
|
|
|
lastStatements->setOperator(EOpSequence);
|
|
|
|
|
switchSequence->push_back(lastStatements);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermAggregate* body = new TIntermAggregate(EOpSequence);
|
|
|
|
|
body->getSequence() = *switchSequenceStack.back();
|
|
|
|
|
body->setLoc(loc);
|
|
|
|
|
|
|
|
|
|
TIntermSwitch* switchNode = new TIntermSwitch(expression, body);
|
|
|
|
|
switchNode->setLoc(loc);
|
2017-07-04 15:23:40 +00:00
|
|
|
|
switchNode->setSelectionControl(control);
|
2016-03-13 03:11:22 +00:00
|
|
|
|
|
|
|
|
|
return switchNode;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-22 05:56:40 +00:00
|
|
|
|
// Make a new symbol-table level that is made out of the members of a structure.
|
|
|
|
|
// This should be done as an anonymous struct (name is "") so that the symbol table
|
2017-05-17 05:16:26 +00:00
|
|
|
|
// finds the members with no explicit reference to a 'this' variable.
|
|
|
|
|
void HlslParseContext::pushThisScope(const TType& thisStruct, const TVector<TFunctionDeclarator>& functionDeclarators)
|
2017-03-22 05:56:40 +00:00
|
|
|
|
{
|
2017-05-17 05:16:26 +00:00
|
|
|
|
// member variables
|
2017-03-22 05:56:40 +00:00
|
|
|
|
TVariable& thisVariable = *new TVariable(NewPoolTString(""), thisStruct);
|
|
|
|
|
symbolTable.pushThis(thisVariable);
|
2017-05-17 05:16:26 +00:00
|
|
|
|
|
|
|
|
|
// member functions
|
|
|
|
|
for (auto it = functionDeclarators.begin(); it != functionDeclarators.end(); ++it) {
|
|
|
|
|
// member should have a prefix matching currentTypePrefix.back()
|
|
|
|
|
// but, symbol lookup within the class scope will just use the
|
|
|
|
|
// unprefixed name. Hence, there are two: one fully prefixed and
|
|
|
|
|
// one with no prefix.
|
|
|
|
|
TFunction& member = *it->function->clone();
|
|
|
|
|
member.removePrefix(currentTypePrefix.back());
|
|
|
|
|
symbolTable.insert(member);
|
|
|
|
|
}
|
2017-03-22 05:56:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-19 18:24:29 +00:00
|
|
|
|
// Track levels of class/struct/namespace nesting with a prefix string using
|
2017-03-11 21:13:00 +00:00
|
|
|
|
// the type names separated by the scoping operator. E.g., two levels
|
|
|
|
|
// would look like:
|
|
|
|
|
//
|
|
|
|
|
// outer::inner
|
|
|
|
|
//
|
|
|
|
|
// The string is empty when at normal global level.
|
|
|
|
|
//
|
2017-03-19 18:24:29 +00:00
|
|
|
|
void HlslParseContext::pushNamespace(const TString& typeName)
|
2017-03-11 21:13:00 +00:00
|
|
|
|
{
|
|
|
|
|
// make new type prefix
|
|
|
|
|
TString newPrefix;
|
2017-05-17 05:16:26 +00:00
|
|
|
|
if (currentTypePrefix.size() > 0)
|
2017-03-11 21:13:00 +00:00
|
|
|
|
newPrefix = currentTypePrefix.back();
|
|
|
|
|
newPrefix.append(typeName);
|
2017-05-17 05:16:26 +00:00
|
|
|
|
newPrefix.append(scopeMangler);
|
2017-03-11 21:13:00 +00:00
|
|
|
|
currentTypePrefix.push_back(newPrefix);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-19 18:24:29 +00:00
|
|
|
|
// Opposite of pushNamespace(), see above
|
|
|
|
|
void HlslParseContext::popNamespace()
|
2017-03-11 21:13:00 +00:00
|
|
|
|
{
|
|
|
|
|
currentTypePrefix.pop_back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use the class/struct nesting string to create a global name for
|
2017-03-19 18:24:29 +00:00
|
|
|
|
// a member of a class/struct.
|
2017-03-29 05:43:10 +00:00
|
|
|
|
void HlslParseContext::getFullNamespaceName(const TString*& name) const
|
2017-03-11 21:13:00 +00:00
|
|
|
|
{
|
2017-03-29 05:43:10 +00:00
|
|
|
|
if (currentTypePrefix.size() == 0)
|
|
|
|
|
return;
|
2017-03-11 21:13:00 +00:00
|
|
|
|
|
2017-03-29 05:43:10 +00:00
|
|
|
|
TString* fullName = NewPoolTString(currentTypePrefix.back().c_str());
|
|
|
|
|
fullName->append(*name);
|
|
|
|
|
name = fullName;
|
2017-03-11 21:13:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-19 18:24:29 +00:00
|
|
|
|
// Helper function to add the namespace scope mangling syntax to a string.
|
|
|
|
|
void HlslParseContext::addScopeMangler(TString& name)
|
|
|
|
|
{
|
|
|
|
|
name.append(scopeMangler);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 21:13:43 +00:00
|
|
|
|
// Potentially rename shader entry point function
|
2017-03-29 05:43:10 +00:00
|
|
|
|
void HlslParseContext::renameShaderFunction(const TString*& name) const
|
2016-10-31 21:13:43 +00:00
|
|
|
|
{
|
|
|
|
|
// Replace the entry point name given in the shader with the real entry point name,
|
|
|
|
|
// if there is a substitution.
|
|
|
|
|
if (name != nullptr && *name == sourceEntryPointName)
|
2017-01-19 22:29:25 +00:00
|
|
|
|
name = NewPoolTString(intermediate.getEntryPointName().c_str());
|
2016-10-31 21:13:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 03:27:30 +00:00
|
|
|
|
// Return true if this has uniform-interface like decorations.
|
|
|
|
|
bool HlslParseContext::hasUniform(const TQualifier& qualifier) const
|
|
|
|
|
{
|
|
|
|
|
return qualifier.hasUniformLayout() ||
|
|
|
|
|
qualifier.layoutPushConstant;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Potentially not the opposite of hasUniform(), as if some characteristic is
|
|
|
|
|
// ever used for more than one thing (e.g., uniform or input), hasUniform() should
|
|
|
|
|
// say it exists, but clearUniform() should leave it in place.
|
|
|
|
|
void HlslParseContext::clearUniform(TQualifier& qualifier)
|
|
|
|
|
{
|
|
|
|
|
qualifier.clearUniformLayout();
|
|
|
|
|
qualifier.layoutPushConstant = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return false if builtIn by itself doesn't force this qualifier to be an input qualifier.
|
|
|
|
|
bool HlslParseContext::isInputBuiltIn(const TQualifier& qualifier) const
|
|
|
|
|
{
|
|
|
|
|
switch (qualifier.builtIn) {
|
|
|
|
|
case EbvPosition:
|
|
|
|
|
case EbvPointSize:
|
|
|
|
|
return language != EShLangVertex && language != EShLangCompute && language != EShLangFragment;
|
|
|
|
|
case EbvClipDistance:
|
|
|
|
|
case EbvCullDistance:
|
|
|
|
|
return language != EShLangVertex && language != EShLangCompute;
|
|
|
|
|
case EbvFragCoord:
|
|
|
|
|
case EbvFace:
|
|
|
|
|
case EbvHelperInvocation:
|
|
|
|
|
case EbvLayer:
|
|
|
|
|
case EbvPointCoord:
|
|
|
|
|
case EbvSampleId:
|
|
|
|
|
case EbvSampleMask:
|
|
|
|
|
case EbvSamplePosition:
|
|
|
|
|
case EbvViewportIndex:
|
|
|
|
|
return language == EShLangFragment;
|
|
|
|
|
case EbvGlobalInvocationId:
|
|
|
|
|
case EbvLocalInvocationIndex:
|
|
|
|
|
case EbvLocalInvocationId:
|
|
|
|
|
case EbvNumWorkGroups:
|
|
|
|
|
case EbvWorkGroupId:
|
|
|
|
|
case EbvWorkGroupSize:
|
|
|
|
|
return language == EShLangCompute;
|
|
|
|
|
case EbvInvocationId:
|
|
|
|
|
return language == EShLangTessControl || language == EShLangTessEvaluation || language == EShLangGeometry;
|
|
|
|
|
case EbvPatchVertices:
|
|
|
|
|
return language == EShLangTessControl || language == EShLangTessEvaluation;
|
|
|
|
|
case EbvInstanceId:
|
|
|
|
|
case EbvInstanceIndex:
|
|
|
|
|
case EbvVertexId:
|
|
|
|
|
case EbvVertexIndex:
|
|
|
|
|
return language == EShLangVertex;
|
|
|
|
|
case EbvPrimitiveId:
|
|
|
|
|
return language == EShLangGeometry || language == EShLangFragment;
|
|
|
|
|
case EbvTessLevelInner:
|
|
|
|
|
case EbvTessLevelOuter:
|
|
|
|
|
return language == EShLangTessEvaluation;
|
2017-03-19 04:24:14 +00:00
|
|
|
|
case EbvTessCoord:
|
|
|
|
|
return language == EShLangTessEvaluation;
|
2017-02-06 03:27:30 +00:00
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 01:44:52 +00:00
|
|
|
|
// Return true if there are decorations to preserve for input-like storage.
|
2017-02-06 03:27:30 +00:00
|
|
|
|
bool HlslParseContext::hasInput(const TQualifier& qualifier) const
|
|
|
|
|
{
|
|
|
|
|
if (qualifier.hasAnyLocation())
|
|
|
|
|
return true;
|
|
|
|
|
|
2017-02-07 01:44:52 +00:00
|
|
|
|
if (language == EShLangFragment && (qualifier.isInterpolation() || qualifier.centroid || qualifier.sample))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (language == EShLangTessEvaluation && qualifier.patch)
|
2017-02-06 03:27:30 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (isInputBuiltIn(qualifier))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return false if builtIn by itself doesn't force this qualifier to be an output qualifier.
|
|
|
|
|
bool HlslParseContext::isOutputBuiltIn(const TQualifier& qualifier) const
|
|
|
|
|
{
|
|
|
|
|
switch (qualifier.builtIn) {
|
|
|
|
|
case EbvPosition:
|
|
|
|
|
case EbvPointSize:
|
|
|
|
|
case EbvClipVertex:
|
|
|
|
|
case EbvClipDistance:
|
|
|
|
|
case EbvCullDistance:
|
|
|
|
|
return language != EShLangFragment && language != EShLangCompute;
|
|
|
|
|
case EbvFragDepth:
|
2017-02-07 01:44:52 +00:00
|
|
|
|
case EbvFragDepthGreater:
|
|
|
|
|
case EbvFragDepthLesser:
|
2017-02-06 03:27:30 +00:00
|
|
|
|
case EbvSampleMask:
|
|
|
|
|
return language == EShLangFragment;
|
|
|
|
|
case EbvLayer:
|
|
|
|
|
case EbvViewportIndex:
|
|
|
|
|
return language == EShLangGeometry;
|
|
|
|
|
case EbvPrimitiveId:
|
|
|
|
|
return language == EShLangGeometry || language == EShLangTessControl || language == EShLangTessEvaluation;
|
|
|
|
|
case EbvTessLevelInner:
|
|
|
|
|
case EbvTessLevelOuter:
|
|
|
|
|
return language == EShLangTessControl;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 01:44:52 +00:00
|
|
|
|
// Return true if there are decorations to preserve for output-like storage.
|
2017-02-06 03:27:30 +00:00
|
|
|
|
bool HlslParseContext::hasOutput(const TQualifier& qualifier) const
|
|
|
|
|
{
|
|
|
|
|
if (qualifier.hasAnyLocation())
|
|
|
|
|
return true;
|
|
|
|
|
|
2017-02-07 01:44:52 +00:00
|
|
|
|
if (language != EShLangFragment && language != EShLangCompute && qualifier.hasXfb())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (language == EShLangTessControl && qualifier.patch)
|
2017-02-06 03:27:30 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (language == EShLangGeometry && qualifier.hasStream())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (isOutputBuiltIn(qualifier))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make the IO decorations etc. be appropriate only for an input interface.
|
|
|
|
|
void HlslParseContext::correctInput(TQualifier& qualifier)
|
|
|
|
|
{
|
|
|
|
|
clearUniform(qualifier);
|
|
|
|
|
if (language == EShLangVertex)
|
|
|
|
|
qualifier.clearInterstage();
|
2017-02-07 01:44:52 +00:00
|
|
|
|
if (language != EShLangTessEvaluation)
|
|
|
|
|
qualifier.patch = false;
|
|
|
|
|
if (language != EShLangFragment) {
|
|
|
|
|
qualifier.clearInterpolation();
|
|
|
|
|
qualifier.sample = false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-11 06:17:26 +00:00
|
|
|
|
// TODO: handle clip/cull on the input side; this doesn't work, see overwrite of .layoutLocation later
|
HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared. There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling
This is implements that ability. Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable. The new variable name is
taken from one of the declared ones, so the old tests are unchanged.
Several new tests are added to test various packing scenarios.
Only two semantic IDs are supported: 0, and 1, per HLSL rules. This is
encapsulated in
static const int maxClipCullRegs = 2;
and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg? Probably, and this algorithm assumes so).
2017-07-05 17:33:06 +00:00
|
|
|
|
if (isClipOrCullDistance(qualifier))
|
|
|
|
|
qualifier.layoutLocation = TQualifier::layoutLocationEnd;
|
|
|
|
|
|
2017-02-06 03:27:30 +00:00
|
|
|
|
qualifier.clearStreamLayout();
|
|
|
|
|
qualifier.clearXfbLayout();
|
|
|
|
|
|
|
|
|
|
if (! isInputBuiltIn(qualifier))
|
|
|
|
|
qualifier.builtIn = EbvNone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make the IO decorations etc. be appropriate only for an output interface.
|
|
|
|
|
void HlslParseContext::correctOutput(TQualifier& qualifier)
|
|
|
|
|
{
|
|
|
|
|
clearUniform(qualifier);
|
|
|
|
|
if (language == EShLangFragment)
|
|
|
|
|
qualifier.clearInterstage();
|
|
|
|
|
if (language != EShLangGeometry)
|
|
|
|
|
qualifier.clearStreamLayout();
|
|
|
|
|
if (language == EShLangFragment)
|
|
|
|
|
qualifier.clearXfbLayout();
|
2017-02-07 01:44:52 +00:00
|
|
|
|
if (language != EShLangTessControl)
|
|
|
|
|
qualifier.patch = false;
|
2017-02-06 03:27:30 +00:00
|
|
|
|
|
|
|
|
|
switch (qualifier.builtIn) {
|
|
|
|
|
case EbvFragDepthGreater:
|
|
|
|
|
intermediate.setDepth(EldGreater);
|
|
|
|
|
qualifier.builtIn = EbvFragDepth;
|
|
|
|
|
break;
|
|
|
|
|
case EbvFragDepthLesser:
|
|
|
|
|
intermediate.setDepth(EldLess);
|
|
|
|
|
qualifier.builtIn = EbvFragDepth;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! isOutputBuiltIn(qualifier))
|
|
|
|
|
qualifier.builtIn = EbvNone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make the IO decorations etc. be appropriate only for uniform type interfaces.
|
|
|
|
|
void HlslParseContext::correctUniform(TQualifier& qualifier)
|
|
|
|
|
{
|
2017-04-24 01:44:28 +00:00
|
|
|
|
if (qualifier.declaredBuiltIn == EbvNone)
|
|
|
|
|
qualifier.declaredBuiltIn = qualifier.builtIn;
|
|
|
|
|
|
2017-02-06 03:27:30 +00:00
|
|
|
|
qualifier.builtIn = EbvNone;
|
|
|
|
|
qualifier.clearInterstage();
|
|
|
|
|
qualifier.clearInterstageLayout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clear out all IO/Uniform stuff, so this has nothing to do with being an IO interface.
|
|
|
|
|
void HlslParseContext::clearUniformInputOutput(TQualifier& qualifier)
|
|
|
|
|
{
|
|
|
|
|
clearUniform(qualifier);
|
|
|
|
|
correctUniform(qualifier);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 00:39:25 +00:00
|
|
|
|
|
2017-08-04 19:51:54 +00:00
|
|
|
|
// Return a symbol for the tessellation linkage variable of the given TBuiltInVariable type
|
|
|
|
|
TIntermSymbol* HlslParseContext::findTessLinkageSymbol(TBuiltInVariable biType) const
|
2017-03-23 00:39:25 +00:00
|
|
|
|
{
|
2017-08-04 19:51:54 +00:00
|
|
|
|
const auto it = builtInTessLinkageSymbols.find(biType);
|
|
|
|
|
if (it == builtInTessLinkageSymbols.end()) // if it wasn't declared by the user, return nullptr
|
2017-03-23 00:39:25 +00:00
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
return intermediate.addSymbol(*it->second->getAsVariable());
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 14:19:21 +00:00
|
|
|
|
// Finalization step: Add patch constant function invocation
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
void HlslParseContext::addPatchConstantInvocation()
|
|
|
|
|
{
|
|
|
|
|
TSourceLoc loc;
|
|
|
|
|
loc.init();
|
|
|
|
|
|
|
|
|
|
// If there's no patch constant function, or we're not a HS, do nothing.
|
|
|
|
|
if (patchConstantFunctionName.empty() || language != EShLangTessControl)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (symbolTable.isFunctionNameVariable(patchConstantFunctionName)) {
|
|
|
|
|
error(loc, "can't use variable in patch constant function", patchConstantFunctionName.c_str(), "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString mangledName = patchConstantFunctionName + "(";
|
|
|
|
|
|
|
|
|
|
// create list of PCF candidates
|
|
|
|
|
TVector<const TFunction*> candidateList;
|
|
|
|
|
bool builtIn;
|
|
|
|
|
symbolTable.findFunctionNameList(mangledName, candidateList, builtIn);
|
|
|
|
|
|
|
|
|
|
// We have to have one and only one, or we don't know which to pick: the patchconstantfunc does not
|
|
|
|
|
// allow any disambiguation of overloads.
|
|
|
|
|
if (candidateList.empty()) {
|
|
|
|
|
error(loc, "patch constant function not found", patchConstantFunctionName.c_str(), "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Based on directed experiments, it appears that if there are overloaded patchconstantfunctions,
|
|
|
|
|
// HLSL picks the last one in shader source order. Since that isn't yet implemented here, error
|
|
|
|
|
// out if there is more than one candidate.
|
|
|
|
|
if (candidateList.size() > 1) {
|
|
|
|
|
error(loc, "ambiguous patch constant function", patchConstantFunctionName.c_str(), "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// Look for built-in variables in a function's parameter list.
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
const auto findBuiltIns = [&](const TFunction& function, std::set<tInterstageIoData>& builtIns) {
|
|
|
|
|
for (int p=0; p<function.getParamCount(); ++p) {
|
2017-04-01 21:34:48 +00:00
|
|
|
|
TStorageQualifier storage = function[p].type->getQualifier().storage;
|
|
|
|
|
|
|
|
|
|
if (storage == EvqConstReadOnly) // treated identically to input
|
|
|
|
|
storage = EvqIn;
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
2017-04-24 01:44:28 +00:00
|
|
|
|
if (function[p].getDeclaredBuiltIn() != EbvNone)
|
|
|
|
|
builtIns.insert(HlslParseContext::tInterstageIoData(function[p].getDeclaredBuiltIn(), storage));
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
else
|
2017-03-09 17:48:59 +00:00
|
|
|
|
builtIns.insert(HlslParseContext::tInterstageIoData(function[p].type->getQualifier().builtIn, storage));
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// If we synthesize a built-in interface variable, we must add it to the linkage.
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
const auto addToLinkage = [&](const TType& type, const TString* name, TIntermSymbol** symbolNode) {
|
|
|
|
|
if (name == nullptr) {
|
|
|
|
|
error(loc, "unable to locate patch function parameter name", "", "");
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
TVariable& variable = *new TVariable(name, type);
|
|
|
|
|
if (! symbolTable.insert(variable)) {
|
|
|
|
|
error(loc, "unable to declare patch constant function interface variable", name->c_str(), "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
globalQualifierFix(loc, variable.getWritableType().getQualifier());
|
|
|
|
|
|
|
|
|
|
if (symbolNode != nullptr)
|
|
|
|
|
*symbolNode = intermediate.addSymbol(variable);
|
|
|
|
|
|
|
|
|
|
trackLinkage(variable);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-04-01 21:34:48 +00:00
|
|
|
|
const auto isOutputPatch = [this](TFunction& patchConstantFunction, int param) {
|
|
|
|
|
const TType& type = *patchConstantFunction[param].type;
|
2017-04-24 01:44:28 +00:00
|
|
|
|
const TBuiltInVariable biType = patchConstantFunction[param].getDeclaredBuiltIn();
|
2017-04-01 21:34:48 +00:00
|
|
|
|
|
|
|
|
|
return type.isArray() && !type.isRuntimeSizedArray() && biType == EbvOutputPatch;
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// We will perform these steps. Each is in a scoped block for separation: they could
|
|
|
|
|
// become separate functions to make addPatchConstantInvocation shorter.
|
|
|
|
|
//
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// 1. Union the interfaces, and create built-ins for anything present in the PCF and
|
|
|
|
|
// declared as a built-in variable that isn't present in the entry point's signature.
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
//
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// 2. Synthesizes a call to the patchconstfunction using built-in variables from either main,
|
|
|
|
|
// or the ones we created. Matching is based on built-in type. We may use synthesized
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
// variables from (1) above.
|
2017-03-14 23:37:10 +00:00
|
|
|
|
//
|
|
|
|
|
// 2B: Synthesize per control point invocations of wrapped entry point if the PCF requires them.
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
//
|
|
|
|
|
// 3. Create a return sequence: copy the return value (if any) from the PCF to a
|
|
|
|
|
// (non-sanitized) output variable. In case this may involve multiple copies, such as for
|
|
|
|
|
// an arrayed variable, a temporary copy of the PCF output is created to avoid multiple
|
|
|
|
|
// indirections into a complex R-value coming from the call to the PCF.
|
2017-03-14 23:37:10 +00:00
|
|
|
|
//
|
|
|
|
|
// 4. Create a barrier.
|
|
|
|
|
//
|
|
|
|
|
// 5/5B. Call the PCF inside an if test for (invocation id == 0).
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
|
|
|
|
TFunction& patchConstantFunction = const_cast<TFunction&>(*candidateList[0]);
|
|
|
|
|
const int pcfParamCount = patchConstantFunction.getParamCount();
|
2017-08-04 19:51:54 +00:00
|
|
|
|
TIntermSymbol* invocationIdSym = findTessLinkageSymbol(EbvInvocationId);
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
TIntermSequence& epBodySeq = entryPointFunctionBody->getAsAggregate()->getSequence();
|
|
|
|
|
|
2017-04-01 21:34:48 +00:00
|
|
|
|
int outPatchParam = -1; // -1 means there isn't one.
|
2017-03-14 23:37:10 +00:00
|
|
|
|
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
// ================ Step 1A: Union Interfaces ================
|
|
|
|
|
// Our patch constant function.
|
|
|
|
|
{
|
2017-07-30 22:54:02 +00:00
|
|
|
|
std::set<tInterstageIoData> pcfBuiltIns; // patch constant function built-ins
|
|
|
|
|
std::set<tInterstageIoData> epfBuiltIns; // entry point function built-ins
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
|
|
|
|
assert(entryPointFunction);
|
|
|
|
|
assert(entryPointFunctionBody);
|
|
|
|
|
|
|
|
|
|
findBuiltIns(patchConstantFunction, pcfBuiltIns);
|
|
|
|
|
findBuiltIns(*entryPointFunction, epfBuiltIns);
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// Find the set of built-ins in the PCF that are not present in the entry point.
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
std::set<tInterstageIoData> notInEntryPoint;
|
|
|
|
|
|
|
|
|
|
notInEntryPoint = pcfBuiltIns;
|
|
|
|
|
|
2017-03-09 17:48:59 +00:00
|
|
|
|
// std::set_difference not usable on unordered containers
|
|
|
|
|
for (auto bi = epfBuiltIns.begin(); bi != epfBuiltIns.end(); ++bi)
|
|
|
|
|
notInEntryPoint.erase(*bi);
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
|
|
|
|
// Now we'll add those to the entry and to the linkage.
|
|
|
|
|
for (int p=0; p<pcfParamCount; ++p) {
|
2017-04-24 01:44:28 +00:00
|
|
|
|
const TBuiltInVariable biType = patchConstantFunction[p].getDeclaredBuiltIn();
|
2017-04-01 21:34:48 +00:00
|
|
|
|
TStorageQualifier storage = patchConstantFunction[p].type->getQualifier().storage;
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
2017-04-01 21:34:48 +00:00
|
|
|
|
// Track whether there is an output patch param
|
|
|
|
|
if (isOutputPatch(patchConstantFunction, p)) {
|
|
|
|
|
if (outPatchParam >= 0) {
|
|
|
|
|
// Presently we only support one per ctrl pt input.
|
|
|
|
|
error(loc, "unimplemented: multiple output patches in patch constant function", "", "");
|
2017-03-14 23:37:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-04-01 21:34:48 +00:00
|
|
|
|
outPatchParam = p;
|
2017-03-14 23:37:10 +00:00
|
|
|
|
}
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
2017-03-14 23:37:10 +00:00
|
|
|
|
if (biType != EbvNone) {
|
|
|
|
|
TType* paramType = patchConstantFunction[p].type->clone();
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
2017-04-01 21:34:48 +00:00
|
|
|
|
if (storage == EvqConstReadOnly) // treated identically to input
|
|
|
|
|
storage = EvqIn;
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// Presently, the only non-built-in we support is InputPatch, which is treated as
|
|
|
|
|
// a pseudo-built-in.
|
2017-04-01 21:34:48 +00:00
|
|
|
|
if (biType == EbvInputPatch) {
|
2017-08-04 19:51:54 +00:00
|
|
|
|
builtInTessLinkageSymbols[biType] = inputPatch;
|
2017-04-01 21:34:48 +00:00
|
|
|
|
} else if (biType == EbvOutputPatch) {
|
|
|
|
|
// Nothing...
|
|
|
|
|
} else {
|
|
|
|
|
// Use the original declaration type for the linkage
|
|
|
|
|
paramType->getQualifier().builtIn = biType;
|
|
|
|
|
|
|
|
|
|
if (notInEntryPoint.count(tInterstageIoData(biType, storage)) == 1)
|
|
|
|
|
addToLinkage(*paramType, patchConstantFunction[p].name, nullptr);
|
|
|
|
|
}
|
2017-03-14 23:37:10 +00:00
|
|
|
|
}
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we didn't find it because the shader made one, add our own.
|
|
|
|
|
if (invocationIdSym == nullptr) {
|
|
|
|
|
TType invocationIdType(EbtUint, EvqIn, 1);
|
|
|
|
|
TString* invocationIdName = NewPoolTString("InvocationId");
|
|
|
|
|
invocationIdType.getQualifier().builtIn = EbvInvocationId;
|
|
|
|
|
addToLinkage(invocationIdType, invocationIdName, &invocationIdSym);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(invocationIdSym);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIntermTyped* pcfArguments = nullptr;
|
2017-03-14 23:37:10 +00:00
|
|
|
|
TVariable* perCtrlPtVar = nullptr;
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
|
|
|
|
// ================ Step 1B: Argument synthesis ================
|
|
|
|
|
// Create pcfArguments for synthesis of patchconstantfunction invocation
|
|
|
|
|
// TODO: handle struct or array inputs
|
|
|
|
|
{
|
|
|
|
|
for (int p=0; p<pcfParamCount; ++p) {
|
2017-03-14 23:37:10 +00:00
|
|
|
|
TIntermSymbol* inputArg = nullptr;
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
2017-04-01 21:34:48 +00:00
|
|
|
|
if (p == outPatchParam) {
|
2017-03-14 23:37:10 +00:00
|
|
|
|
if (perCtrlPtVar == nullptr) {
|
2017-04-01 21:34:48 +00:00
|
|
|
|
perCtrlPtVar = makeInternalVariable(*patchConstantFunction[outPatchParam].name,
|
|
|
|
|
*patchConstantFunction[outPatchParam].type);
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
2017-03-14 23:37:10 +00:00
|
|
|
|
perCtrlPtVar->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
}
|
|
|
|
|
inputArg = intermediate.addSymbol(*perCtrlPtVar, loc);
|
|
|
|
|
} else {
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// find which built-in it is
|
2017-04-24 01:44:28 +00:00
|
|
|
|
const TBuiltInVariable biType = patchConstantFunction[p].getDeclaredBuiltIn();
|
2017-03-14 23:37:10 +00:00
|
|
|
|
|
2017-08-04 19:51:54 +00:00
|
|
|
|
inputArg = findTessLinkageSymbol(biType);
|
2017-04-01 21:34:48 +00:00
|
|
|
|
|
2017-03-14 23:37:10 +00:00
|
|
|
|
if (inputArg == nullptr) {
|
2017-07-30 22:54:02 +00:00
|
|
|
|
error(loc, "unable to find patch constant function built-in variable", "", "");
|
2017-03-14 23:37:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pcfParamCount == 1)
|
2017-03-14 23:37:10 +00:00
|
|
|
|
pcfArguments = inputArg;
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
else
|
2017-03-14 23:37:10 +00:00
|
|
|
|
pcfArguments = intermediate.growAggregate(pcfArguments, inputArg);
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ================ Step 2: Synthesize call to PCF ================
|
2017-03-14 23:37:10 +00:00
|
|
|
|
TIntermAggregate* pcfCallSequence = nullptr;
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
TIntermTyped* pcfCall = nullptr;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Create a function call to the patchconstantfunction
|
|
|
|
|
if (pcfArguments)
|
|
|
|
|
addInputArgumentConversions(patchConstantFunction, pcfArguments);
|
|
|
|
|
|
|
|
|
|
// Synthetic call.
|
|
|
|
|
pcfCall = intermediate.setAggregateOperator(pcfArguments, EOpFunctionCall, patchConstantFunction.getType(), loc);
|
|
|
|
|
pcfCall->getAsAggregate()->setUserDefined();
|
|
|
|
|
pcfCall->getAsAggregate()->setName(patchConstantFunction.getMangledName());
|
2017-03-14 23:37:10 +00:00
|
|
|
|
intermediate.addToCallGraph(infoSink, intermediate.getEntryPointMangledName().c_str(),
|
|
|
|
|
patchConstantFunction.getMangledName());
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
|
|
|
|
if (pcfCall->getAsAggregate()) {
|
|
|
|
|
TQualifierList& qualifierList = pcfCall->getAsAggregate()->getQualifierList();
|
|
|
|
|
for (int i = 0; i < patchConstantFunction.getParamCount(); ++i) {
|
|
|
|
|
TStorageQualifier qual = patchConstantFunction[i].type->getQualifier().storage;
|
|
|
|
|
qualifierList.push_back(qual);
|
|
|
|
|
}
|
|
|
|
|
pcfCall = addOutputArgumentConversions(patchConstantFunction, *pcfCall->getAsOperator());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 23:37:10 +00:00
|
|
|
|
// ================ Step 2B: Per Control Point synthesis ================
|
|
|
|
|
// If there is per control point data, we must either emulate that with multiple
|
|
|
|
|
// invocations of the entry point to build up an array, or (TODO:) use a yet
|
|
|
|
|
// unavailable extension to look across the SIMD lanes. This is the former
|
|
|
|
|
// as a placeholder for the latter.
|
2017-04-01 21:34:48 +00:00
|
|
|
|
if (outPatchParam >= 0) {
|
2017-03-14 23:37:10 +00:00
|
|
|
|
// We must introduce a local temp variable of the type wanted by the PCF input.
|
2017-04-01 21:34:48 +00:00
|
|
|
|
const int arraySize = patchConstantFunction[outPatchParam].type->getOuterArraySize();
|
2017-03-14 23:37:10 +00:00
|
|
|
|
|
|
|
|
|
if (entryPointFunction->getType().getBasicType() == EbtVoid) {
|
|
|
|
|
error(loc, "entry point must return a value for use with patch constant function", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create calls to wrapped main to fill in the array. We will substitute fixed values
|
|
|
|
|
// of invocation ID when calling the wrapped main.
|
|
|
|
|
|
|
|
|
|
// This is the type of the each member of the per ctrl point array.
|
|
|
|
|
const TType derefType(perCtrlPtVar->getType(), 0);
|
|
|
|
|
|
|
|
|
|
for (int cpt = 0; cpt < arraySize; ++cpt) {
|
|
|
|
|
// TODO: improve. substr(1) here is to avoid the '@' that was grafted on but isn't in the symtab
|
|
|
|
|
// for this function.
|
|
|
|
|
const TString origName = entryPointFunction->getName().substr(1);
|
|
|
|
|
TFunction callee(&origName, TType(EbtVoid));
|
|
|
|
|
TIntermTyped* callingArgs = nullptr;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < entryPointFunction->getParamCount(); i++) {
|
|
|
|
|
TParameter& param = (*entryPointFunction)[i];
|
|
|
|
|
TType& paramType = *param.type;
|
|
|
|
|
|
|
|
|
|
if (paramType.getQualifier().isParamOutput()) {
|
|
|
|
|
error(loc, "unimplemented: entry point outputs in patch constant function invocation", "", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (paramType.getQualifier().isParamInput()) {
|
|
|
|
|
TIntermTyped* arg = nullptr;
|
2017-04-24 01:44:28 +00:00
|
|
|
|
if ((*entryPointFunction)[i].getDeclaredBuiltIn() == EbvInvocationId) {
|
2017-03-14 23:37:10 +00:00
|
|
|
|
// substitute invocation ID with the array element ID
|
|
|
|
|
arg = intermediate.addConstantUnion(cpt, loc);
|
|
|
|
|
} else {
|
|
|
|
|
TVariable* argVar = makeInternalVariable(*param.name, *param.type);
|
|
|
|
|
argVar->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
arg = intermediate.addSymbol(*argVar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleFunctionArgument(&callee, callingArgs, arg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call and assign to per ctrl point variable
|
|
|
|
|
currentCaller = intermediate.getEntryPointMangledName().c_str();
|
|
|
|
|
TIntermTyped* callReturn = handleFunctionCall(loc, &callee, callingArgs);
|
|
|
|
|
TIntermTyped* index = intermediate.addConstantUnion(cpt, loc);
|
|
|
|
|
TIntermSymbol* perCtrlPtSym = intermediate.addSymbol(*perCtrlPtVar, loc);
|
|
|
|
|
TIntermTyped* element = intermediate.addIndex(EOpIndexDirect, perCtrlPtSym, index, loc);
|
|
|
|
|
element->setType(derefType);
|
|
|
|
|
element->setLoc(loc);
|
|
|
|
|
|
|
|
|
|
pcfCallSequence = intermediate.growAggregate(pcfCallSequence,
|
|
|
|
|
handleAssign(loc, EOpAssign, element, callReturn));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
// ================ Step 3: Create return Sequence ================
|
|
|
|
|
// Return sequence: copy PCF result to a temporary, then to shader output variable.
|
|
|
|
|
if (pcfCall->getBasicType() != EbtVoid) {
|
|
|
|
|
const TType* retType = &patchConstantFunction.getType(); // return type from the PCF
|
|
|
|
|
TType outType; // output type that goes with the return type.
|
|
|
|
|
outType.shallowCopy(*retType);
|
|
|
|
|
|
|
|
|
|
// substitute the output type
|
|
|
|
|
const auto newLists = ioTypeMap.find(retType->getStruct());
|
|
|
|
|
if (newLists != ioTypeMap.end())
|
|
|
|
|
outType.setStruct(newLists->second.output);
|
|
|
|
|
|
2017-07-30 22:54:02 +00:00
|
|
|
|
// Substitute the top level type's built-in type
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
if (patchConstantFunction.getDeclaredBuiltInType() != EbvNone)
|
|
|
|
|
outType.getQualifier().builtIn = patchConstantFunction.getDeclaredBuiltInType();
|
|
|
|
|
|
2017-03-14 23:37:10 +00:00
|
|
|
|
outType.getQualifier().patch = true; // make it a per-patch variable
|
|
|
|
|
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
TVariable* pcfOutput = makeInternalVariable("@patchConstantOutput", outType);
|
|
|
|
|
pcfOutput->getWritableType().getQualifier().storage = EvqVaryingOut;
|
|
|
|
|
|
2017-08-02 23:08:43 +00:00
|
|
|
|
if (pcfOutput->getType().containsBuiltIn())
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
split(*pcfOutput);
|
|
|
|
|
|
2017-06-20 09:20:59 +00:00
|
|
|
|
assignToInterface(*pcfOutput);
|
2017-03-14 23:37:10 +00:00
|
|
|
|
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
TIntermSymbol* pcfOutputSym = intermediate.addSymbol(*pcfOutput, loc);
|
|
|
|
|
|
|
|
|
|
// The call to the PCF is a complex R-value: we want to store it in a temp to avoid
|
|
|
|
|
// repeated calls to the PCF:
|
|
|
|
|
TVariable* pcfCallResult = makeInternalVariable("@patchConstantResult", *retType);
|
|
|
|
|
pcfCallResult->getWritableType().getQualifier().makeTemporary();
|
|
|
|
|
|
2017-03-14 23:37:10 +00:00
|
|
|
|
TIntermSymbol* pcfResultVar = intermediate.addSymbol(*pcfCallResult, loc);
|
|
|
|
|
TIntermNode* pcfResultAssign = handleAssign(loc, EOpAssign, pcfResultVar, pcfCall);
|
2017-07-28 22:20:13 +00:00
|
|
|
|
TIntermNode* pcfResultToOut = handleAssign(loc, EOpAssign, pcfOutputSym,
|
|
|
|
|
intermediate.addSymbol(*pcfCallResult, loc));
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
|
2017-03-14 23:37:10 +00:00
|
|
|
|
pcfCallSequence = intermediate.growAggregate(pcfCallSequence, pcfResultAssign);
|
|
|
|
|
pcfCallSequence = intermediate.growAggregate(pcfCallSequence, pcfResultToOut);
|
|
|
|
|
} else {
|
|
|
|
|
pcfCallSequence = intermediate.growAggregate(pcfCallSequence, pcfCall);
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ================ Step 4: Barrier ================
|
|
|
|
|
TIntermTyped* barrier = new TIntermAggregate(EOpBarrier);
|
|
|
|
|
barrier->setLoc(loc);
|
|
|
|
|
barrier->setType(TType(EbtVoid));
|
|
|
|
|
epBodySeq.insert(epBodySeq.end(), barrier);
|
|
|
|
|
|
2017-03-14 23:37:10 +00:00
|
|
|
|
// ================ Step 5: Test on invocation ID ================
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
TIntermTyped* zero = intermediate.addConstantUnion(0, loc, true);
|
|
|
|
|
TIntermTyped* cmp = intermediate.addBinaryNode(EOpEqual, invocationIdSym, zero, loc, TType(EbtBool));
|
|
|
|
|
|
2017-03-14 23:37:10 +00:00
|
|
|
|
|
|
|
|
|
// ================ Step 5B: Create if statement on Invocation ID == 0 ================
|
|
|
|
|
intermediate.setAggregateOperator(pcfCallSequence, EOpSequence, TType(EbtVoid), loc);
|
|
|
|
|
TIntermTyped* invocationIdTest = new TIntermSelection(cmp, pcfCallSequence, nullptr);
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
invocationIdTest->setLoc(loc);
|
|
|
|
|
|
|
|
|
|
// add our test sequence before the return.
|
|
|
|
|
epBodySeq.insert(epBodySeq.end(), invocationIdTest);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 14:19:21 +00:00
|
|
|
|
// Finalization step: remove unused buffer blocks from linkage (we don't know until the
|
|
|
|
|
// shader is entirely compiled)
|
|
|
|
|
void HlslParseContext::removeUnusedStructBufferCounters()
|
|
|
|
|
{
|
|
|
|
|
const auto endIt = std::remove_if(linkageSymbols.begin(), linkageSymbols.end(),
|
|
|
|
|
[this](const TSymbol* sym) {
|
|
|
|
|
const auto sbcIt = structBufferCounter.find(sym->getName());
|
|
|
|
|
return sbcIt != structBufferCounter.end() && !sbcIt->second;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
linkageSymbols.erase(endIt, linkageSymbols.end());
|
|
|
|
|
}
|
|
|
|
|
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
// post-processing
|
|
|
|
|
void HlslParseContext::finish()
|
|
|
|
|
{
|
2017-05-12 23:14:31 +00:00
|
|
|
|
// Error check: There was a dangling .mips operator. These are not nested constructs in the grammar, so
|
|
|
|
|
// cannot be detected there. This is not strictly needed in a non-validating parser; it's just helpful.
|
|
|
|
|
if (! mipsOperatorMipArg.empty()) {
|
|
|
|
|
error(mipsOperatorMipArg.back().loc, "unterminated mips operator:", "", "");
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 14:19:21 +00:00
|
|
|
|
removeUnusedStructBufferCounters();
|
Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version
here uses entry point wrapping.
This is a limited implementation of tessellation shaders. In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.
* patchconstantfunctions accepting per-control-point input values, such as
const OutputPatch <hs_out_t, 3> cpv are not implemented.
* patchconstantfunctions whose signature requires an aggregate input type such as
a structure containing builtin variables. Code to synthesize such calls is not
yet present.
These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.
PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user
variables in the PCF signature will result in an error. Overloaded PCF functions will also result in
an error.
[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
|
|
|
|
addPatchConstantInvocation();
|
HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case.
The salient points of this PR are:
* Structure splitting has been changed from "always between stages" to "only into the VS and out of
the PS". It had previously happened between stages because it's not legal to pass a struct
containing a builtin IO variable.
* Structs passed between stages are now split into a struct containing ONLY user types, and a
collection of loose builtin IO variables, if any. The user-part is passed as a normal struct
between stages, which is valid SPIR-V now that the builtin IO is removed.
* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
functions can work unmodified.
* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
the array reference is moved to the split-off loose variable, which is given the array dimension
itself.
When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change. However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.
When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.
Above strategy arrived at with talks with @johnkslang.
This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-14 22:22:25 +00:00
|
|
|
|
|
|
|
|
|
TParseContextBase::finish();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:11:22 +00:00
|
|
|
|
} // end namespace glslang
|