Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLSL: add methods to handle user structures in texture template type. #1017

Merged
merged 1 commit into from Aug 19, 2017
Merged

Conversation

ghost
Copy link

@ghost ghost commented Aug 15, 2017

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 return type 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 differ, 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.

@ghost ghost changed the title WIP: HLSL: add methods to track user structure in texture return type. WIP: HLSL: add methods to handle user structures in texture template type. Aug 15, 2017
@ghost
Copy link
Author

ghost commented Aug 15, 2017

Current form calls sample operation too many times while unpacking results into user struct. Probably nominally gets the right answer, but inefficiently. Will push a fix.

@ghost
Copy link
Author

ghost commented Aug 15, 2017

Repush with changes to copy texture sample result into temporary variable, to avoid issuing redundant sample operations. The temp is now indirected when copying into the user struct type from the vec4 sample result.

@ghost
Copy link
Author

ghost commented Aug 15, 2017

Repush with added test for textures templatized on the same core struct type, to ensure e.g, fn signature matching works as expected.

@ghost ghost changed the title WIP: HLSL: add methods to handle user structures in texture template type. HLSL: add methods to handle user structures in texture template type. Aug 15, 2017
@ghost
Copy link
Author

ghost commented Aug 15, 2017

Minor nonfunctional code and comment updates, removed WIP. Edit: ... and again to merge with recent master changes. No conflicts, but good to establish test sanity on merged result.

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.
@johnkslang johnkslang merged commit b207daa into KhronosGroup:master Aug 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant