An implicit object is translated into the first argument to the
method call. If the implicit object is of struct type and its
fields have associated counters, we need to assign its associated
counters accordingly like other normal arguments.
For each such method, we generate associated counters for its
implicit object. At a call site, we assign the associated counters
from the real object to the ones associated with the method implict
object.
Also refreshed SPIRV-Tools
* [spirv] Better handling of ternary and binary ops.
This change does type handling more properly and removes a hack
regarding binary ops. Also fixes the way ternary ops provide hints about
usage of literal types.
This commit supports assigning nested structs as a whole,
which means to go over all fields' associated counters and
assign to the corresponding fields. The front end parsing
and semantic analysis should guarantee the type matching.
For structs containing RW/Append/Consume structured buffers, to
properly track aliasing and use the correct associated counter
for each buffer after legalization, we need to create temporary
counter variables for all struct fields that are RW/Append/Consume
structured buffers and assign them accordingly if the corresponding
buffer field is updated.
Because of structs, now we have four forms an alias RW/Append/
Consume structured buffer can be in:
* 1 (AssocCounter#1). A stand-alone variable,
* 2 (AssocCounter#2). A struct field,
* 3 (AssocCounter#3). A struct containing alias fields,
* 4 (AssocCounter#4). A nested struct containing alias fields.
For AssocCounter#3 and AssocCounter#4, it means we need to update
all fields' associated counters.
This commit only handles the first three forms.
* Loading the pointer from an alias variable turns the evaluation
info into lavalue again.
* loadIfGLValue() should suppress the immediate LValueToRValue
implicit cast.
* Counter variable emission is merged into getTypeForPotentialAliasVar
* Changed to use DeclaratorDecl instead of ValueDecl for some methods
* collectArrayStructIndices is extended to suppor raw index
Previously we will return defaultRowMajor as long as the type
is an array. That will hit an assertion failure in translateType()
for arrays of non-matrices.
Also refreshed SPIRV-Tools
When using a storage image on the lhs of a compound assignment,
we need to load the image and do the calculation with rhs first
before actually assigning back to the storage image again. That
load won't result in an OpAccessChain, actually it will result
in a rvalue.
We still want to make sure that the generated raw SPIR-V does not
have other validation errors except for allocating variables
containing pointers and returning pointers.
We need to change the type of these struct fields to have an extra
level of pointer.
A local resource always has void as its layout rule (because local
resource is not in the Uniform storage class). So in the TypeTranslator,
when we are trying to translate a structured/byte buffer resource that
has void layout rule, we know it must be a local resource. Then we
apply an extra level of pointer to it. Because of TypeTranslator is
recursive, that automatically handles both stand-alone local resources
and the ones in structs.
In the SPIRVEmitter, we need to have a way to tell whether a resource
is a local resource or not because if it is a local resource, we need to
OpLoad once to get the pointer to the aliased-to global resource.
That's why we have the containsAlias field in SpirvEvalInfo. We set it to
true in getTypeForPotentialAliasVar() for local resources. And do an
extra OpLoad to get the pointer in SPIRVEmitter if it is true.
Static variables are in the Private storage class but all methods
are generated to take pointers of the Function storage class. So
to call a method on a static variable, we need first create a
temporary variable initialized with the contents of the static
variable. After the method call, we also need to write the contents
back to the static variable in case there are side effects.
Instead of checking whether the function signature contains
some opaque types, we check in storeValue(). Since all function
argument evaluation and value return calls storeValue().
* [spirv] Update the handling of literal types.
Try to figure out what is the intended usage for a literal type (e.g.
'literal int' or 'literal float').
Provide a hint to the TypeTranslator and translateAP{Int|Float} methods
so they better reflect the usage of literal types.
This is to aid legalization passes to do their work.
For non-external variables of the following types
* (RW)StructuredBuffer
* (RW)ByteAddressBuffer
* AppendStructuredBuffer
* ConsumeStructuredBuffer
An extra level of pointer is applied. We use this extra level of
pointer to indicate that they are aliases. Loads and stores of
these alias variables will get the pointers of the aliased-to-
variables.
Associated counters is not handled in this commit.