HLSL allows a range of types for clip and cull distances. There are
three dimensions, including arrayness, vectorness, and semantic ID.
SPIR-V requires clip and cull distance be a single array of floats in
all cases.
This code provides input side conversion between the SPIR-V form and
the HLSL form. (Output conversion was added in PR #947 and #997).
This PR extends HlslParseContext::assignClipCullDistance to cope with
the input side conversion. Not as much changed as appears: there was
also a lot of renaming to reflect the fact that the code now handles
either direction.
Currently, non-{frag,vert} stages are not handled, and are explicitly
rejected.
Fixes#1026.
Some languages allow a restricted set of user structure types returned from texture sampling
operations. Restrictions include the total vector size of all components may not exceed 4,
and the basic types of all members must be identical.
This adds underpinnings for that ability. Because storing a whole TType or even a simple
TTypeList in the TSampler would be expensive, the structure definition is held in a
table outside the TType. The TSampler contains a small bitfield index, currently 4 bits
to support up to 15 separate texture template structure types, but that can be adjusted
up or down. Vector returns are handled as before.
There are abstraction methods accepting and returning a TType (such as may have been parsed
from a grammar). The new methods will accept a texture template type and set the
sampler to the structure if possible, checking a range of error conditions such as whether
the total structure vector components exceed 4, or whether their basic types differe, or
whether the struct contains non-vector-or-scalar members. Another query returns the
appropriate TType for the sampler.
High level summary of design:
In the TSampler, this holds an index into the texture structure return type table:
unsigned int structReturnIndex : structReturnIndexBits;
These are the methods to set or get the return type from the TSampler. They work for vector or structure returns, and potentially could be expanded to handle other things (small arrays?) if ever needed.
bool setTextureReturnType(TSampler& sampler, const TType& retType, const TSourceLoc& loc);
void getTextureReturnType(const TSampler& sampler, const TType& retType, const TSourceLoc& loc) const;
The ``convertReturn`` lambda in ``HlslParseContext::decomposeSampleMethods`` is greatly expanded to know how to copy a vec4 sample return to whatever the structure type should be. This is a little awkward since it involves introducing a comma expression to return the proper aggregate value after a set of memberwise copies.
This adds support for #pragma pack_matrix() to the HLSL front end.
The pragma sets the default matrix layout for subsequent unqualified matrices
in structs or buffers. Explicit qualification overrides the pragma value. Matrix
layout is not permitted at the structure level in HLSL, so only leaves which are
matrix types can be so qualified.
Note that due to the semantic (not layout) difference in first matrix indirections
between HLSL and SPIR-V, the sense of row and column major are flipped. That's
independent of this PR: just a factor to note. A column_major qualifier appears
as a RowMajor member decoration in SPIR-V modules, and vice versa.
The HLSL FE tracks four versions of a declared type to avoid losing information, since it
is not (at type-decl time) known how the type will be used downstream. If such a type
was used in a cbuffer declaration, the cbuffer type's members should have been using
the uniform form of the original user structure type, but were not.
This would manifest as matrix qualifiers (and other things, such as pack offsets) on user struct
members going missing in the SPIR-V module if the struct type was a member of a cbuffer, like so:
struct MyBuffer
{
row_major float4x4 mat1;
column_major float4x4 mat2;
};
cbuffer Example
{
MyBuffer g_MyBuffer;
};
Fixes: #789
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).
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.
In HLSL, there are three (TODO: ??) dimensions of clip and cull
distance values:
* The semantic's value N, ala SV_ClipDistanceN.
* The array demension, if the value is an array.
* The vector element, if the value is a vector or array of vectors.
In SPIR-V, clip and cull distance are arrays of scalar floats, always.
This PR currently ignores the semantic N axis, and handles the other
two axes by sequentially copying each vector element of each array member
into sequential floats in the output array.
Fixes: #946
This fixes:
1. A compilation error when assigning scalars to matricies
2. A semantic error in matrix construction from scalars. This was
initializing the diagonal, where HLSL semantics require the scalar be
replicated to every matrix element.
3. Functions accepting mats can be called with scalars, which will
be shape-converted to the matrix type. This was previously failing
to match the function signature.
NOTE: this does not yet handle complex scalars (a function call,
say) used to construct matricies. That'll be added when the
node replicator service is available. For now, there's an assert.
There's one new test (hlsl.scalar2matrix.frag). An existing test
lsl.type.half.frag changes, because of (2) above, and a negative
test error message changes due to (3) above.
Fixes#923.
For "s.m = t", a sampler member assigned a sampler, make t an alias
for s.m, and when s.m is flattened, it will flatten to the alias t.
Normally, assignments to samplers are disallowed.
This changes no functional code. There was a bit of a testing hole
in that textures templatized on sub-vec4 types were not being exercised
with any intrinsics. This adds some basic sanity coverage of that case.
Adds a transformation step to the post processing step.
Two modes are available:
1) keep
- Keeps samplers, textures and sampled textures as is
2) transform pure texture into sampled texture and remove pure samplers
- removes all pure samplers
- transforms all pure textures into its sampled counter part
Change-Id: If54972e8052961db66c23f4b7e719d363cf6edbd
Name mangling did not account for the vector size in the template type of a texture.
This adds that. The mangle is as it ever was for the vec4 case, which leaves
all GLSL behavior and most HLSL behavior uneffected. For vec1-3 the size is added
to the mangle.
Current limitation: textures cannot presently be templatized on structured types,
so this works only for vectors of basic types.
Fixes#895.
OpSpecConstantOp contains an embedded opcode which is given as a literal
argument to the OpSpecConstantOp. The subsequent arguments are as the
embedded op would expect, which may be a mixture of IDs and literals. This
adds support for that to the remapper binary parser. Upon seeing such an
embedded op, the parser flips over to parsing the argument list as
appropriate for that opcode.
Fixes#882.
Also, provides an option to auto-assign locations.
Existing tests use this option, to avoid the error message,
however, it is not fully implemented yet.
This modifies function parameter passing to pass the counter
buffer associated with a struct buffer to a function as a
hidden parameter. Similarly function declarations will have
hidden parameters added to accept the associated counter buffers.
There is a limitation: if a SB type may or may not have an associated
counter, passing it as a function parameter will assume that it does, and
the counter will appear in the linkage whether or not there is a counter
method used on the object.
This implements mytex.mips[mip][coord] for texture types. There is
some error testing, but not comprehensive. The constructs can be
nested, e.g in this case the inner .mips is parsed before the completion
of the outer [][] operator.
tx.mips[tx.mips[a][b].x][c]
Using GS methods such as Append() in non-GS stages should be ignored, but was
creating errors due to the lack of a stream output symbol for the non-GS stage.