diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-11-29 11:45:15 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-29 11:45:15 -0800 |
| commit | b487516880f56fd69ff76bf7cb3f0f1711bc356d (patch) | |
| tree | 0f1464a22ac7f52053ab4f8f768967c1383c597c /slang.h | |
| parent | 713938038a87b9e4a69f198f09f1bf231be6f72f (diff) | |
Add API to query stage of varying parameter (#302)
Fixes #301
The problem here is that if you have input GLSL code like:
```glsl
// example.vs
in vec3 pos;
```
and:
```glsl
// example.fs
in vec3 worldPos;
```
Then both `pos` and `worldPos` are reflected as global variables (parameters of the *program*), which both get bound to "varying input" resources, but there is no way to tell through the API that `pos` is a vertex parameter while `worldPos` is a fragment one.
The original request in issue #301 was to expose parameters like this not as a global variables, but rather as parameters of the entry point in their specific file. That is, treat it as if the user had written, e.g.:
```glsl
// example.vs
void vsMain(in vec3 pos) { ... }
```
Doing that would unify the GLSL and HLSL/Slang cases a bit, but would require the Slang reflection API to lie about the structure of code the user wrote. At a more basic level, that would have been hard to implement because the current reflection API just exposes the underlying AST, and the AST *needs* to leave `pos` at the global scope so that when we go and spit GLSL back out we retain the original structure.
This PR implements a more simplistic solution, where the user is allowed to query the stage that a varying parameter "belongs" to. For right now I'm only enabling this to work for varying parameters (but it doesn't care if they are entry-point or global-scope varyings). Despite what I said on #301, this should work for both the top-level parameter's variable layout, *and* any variable layouts for fields within its type reflection.
In terms of implementation, I took the simple but wasteful route: every `VarLayout` now has a `stage` field that is by default initialized to `SLANG_STAGE_NONE`. When collecting varying parameters, I take advantage of the fact that everything bottlenecks through `processEntryPointParameter()` which takes an `EntryPointParameterState` so that I can set the `VarLayout::stage` field for any varying parameter in one place.
While I was making this change, I also did a bit of cleanup so that the "official" names for the varying parameter categories are `VARYING_INPUT` and `VARYING_OUTPUT`, with `VERTEX_INPUT` and `FRAGMENT_OUTPUT` being "deprecated" in principle. I didn't do the bulk rename inside the codebase yet.
Diffstat (limited to 'slang.h')
| -rw-r--r-- | slang.h | 33 |
1 files changed, 29 insertions, 4 deletions
@@ -589,8 +589,8 @@ extern "C" SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER, SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE, SLANG_PARAMETER_CATEGORY_UNORDERED_ACCESS, - SLANG_PARAMETER_CATEGORY_VERTEX_INPUT, - SLANG_PARAMETER_CATEGORY_FRAGMENT_OUTPUT, + SLANG_PARAMETER_CATEGORY_VARYING_INPUT, + SLANG_PARAMETER_CATEGORY_VARYING_OUTPUT, SLANG_PARAMETER_CATEGORY_SAMPLER_STATE, SLANG_PARAMETER_CATEGORY_UNIFORM, SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT, @@ -605,6 +605,11 @@ extern "C" // SLANG_PARAMETER_CATEGORY_COUNT, + + + // DEPRECATED: + SLANG_PARAMETER_CATEGORY_VERTEX_INPUT = SLANG_PARAMETER_CATEGORY_VARYING_INPUT, + SLANG_PARAMETER_CATEGORY_FRAGMENT_OUTPUT = SLANG_PARAMETER_CATEGORY_VARYING_OUTPUT, }; typedef SlangUInt32 SlangStage; @@ -618,6 +623,7 @@ extern "C" SLANG_STAGE_FRAGMENT, SLANG_STAGE_COMPUTE, + // alias: SLANG_STAGE_PIXEL = SLANG_STAGE_FRAGMENT, }; @@ -672,6 +678,16 @@ extern "C" SLANG_API char const* spReflectionVariableLayout_GetSemanticName(SlangReflectionVariableLayout* var); SLANG_API size_t spReflectionVariableLayout_GetSemanticIndex(SlangReflectionVariableLayout* var); + /** Get the stage that a variable belongs to (if any). + + A variable "belongs" to a specific stage when it is a varying input/output + parameter either defined as part of the parameter list for an entry + point *or* at the global scope of a stage-specific GLSL code file (e.g., + an `in` parameter in a GLSL `.vs` file belongs to the vertex stage). + */ + SLANG_API SlangStage spReflectionVariableLayout_getStage( + SlangReflectionVariableLayout* var); + // Shader Parameter Reflection typedef SlangReflectionVariableLayout SlangReflectionParameter; @@ -857,8 +873,8 @@ namespace slang ConstantBuffer = SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER, ShaderResource = SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE, UnorderedAccess = SLANG_PARAMETER_CATEGORY_UNORDERED_ACCESS, - VertexInput = SLANG_PARAMETER_CATEGORY_VERTEX_INPUT, - FragmentOutput = SLANG_PARAMETER_CATEGORY_FRAGMENT_OUTPUT, + VaryingInput = SLANG_PARAMETER_CATEGORY_VARYING_INPUT, + VaryingOutput = SLANG_PARAMETER_CATEGORY_VARYING_OUTPUT, SamplerState = SLANG_PARAMETER_CATEGORY_SAMPLER_STATE, Uniform = SLANG_PARAMETER_CATEGORY_UNIFORM, DescriptorTableSlot = SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT, @@ -866,6 +882,10 @@ namespace slang PushConstantBuffer = SLANG_PARAMETER_CATEGORY_PUSH_CONSTANT_BUFFER, RegisterSpace = SLANG_PARAMETER_CATEGORY_REGISTER_SPACE, GenericResource = SLANG_PARAMETER_CATEGORY_GENERIC, + + // DEPRECATED: + VertexInput = SLANG_PARAMETER_CATEGORY_VERTEX_INPUT, + FragmentOutput = SLANG_PARAMETER_CATEGORY_FRAGMENT_OUTPUT, }; struct TypeLayoutReflection @@ -1057,6 +1077,11 @@ namespace slang { return spReflectionVariableLayout_GetSemanticIndex((SlangReflectionVariableLayout*) this); } + + SlangStage getStage() + { + return spReflectionVariableLayout_getStage((SlangReflectionVariableLayout*) this); + } }; struct EntryPointReflection |
