summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2017-07-18Don't allow varying parameters to be merged in reflection dataTim Foley
All varying input/output parameters need to be specified to the entry point that declared them. In the case of HLSL/Slang this happens for free, but in the case of GLSL we need to be careful not to merge global-scope `in` or `out` parameters in ways that don't make sense.
2017-07-17Merge pull request #114 from tfoleyNV/csm-shadow-sampler-fixTim Foley
Make sure to treat imported modules as Slang
2017-07-17Make sure to treat imported modules as SlangTim Foley
- When generating parameter binding/reflection info, treated imported modules as Slang code, instead of the source language of the outer translation unit - This fixes an issue where global-scope shader parameters in a `.slang` file were getting ignored for binding-generation purposes when imported by a GLSL file
2017-07-17Merge pull request #112 from tfoleyNV/gh-94Tim Foley
Handle `Buffer` types more like textures
2017-07-17Handle `Buffer` types more like texturesTim Foley
Fixes #94 We'd been handling HLSL `Buffer` and `RWBuffer` in a one-off fashion, and that led to a lot of code duplication, and also to the issue that we weren't handling `RasterizerOrderedBuffer` at all. This change basically folds `Buffer` in so that it is conceptually a texture type (just with a unique shape). Hopefully all the other logic still works.
2017-07-17Merge pull request #111 from tfoleyNV/falcor-shadows-fixesTim Foley
Falcor shadows fixes
2017-07-17Handle arrays when scalarizing "resources in structs"Tim Foley
The basic idea is that an array of `struct`s will get scalarized into per-field arrays (for any fields that need to be scalarized). So given: struct Foo { float x; Texture2D t; }; cbuffer C { Foo foo[4]; } We'll get output like: struct Foo { float x; }; cbuffer C { Foo foo[4]; } Texture2D C_foo_t[4]; (Of course the output would also be translated over to GLSL, but I'm only concerned about this one transformation here).
2017-07-17Map HLSL `SampleGrad` to GLSL `textureGrad[Offset]`Tim Foley
- This was an easy case, as far as these things go.
2017-07-17Add hacky GLSL lowering for `GetDimensions`Tim Foley
This is hacky for two big reasons: 1. It uses "operator comma" in the output to deal with calling multiple functions in an expression context 2. The way I'm lowering things to GLSL ends up using certain function arguments more than once, which means they get emitted as GLSL more than once, which means their *side effects* get evaluated more than once. Please don't put an expression with side effects in as an argument to `GetDimensions` when cross-compiling. Solving these issues requires the translation of builtins to be more directly handled as part of lowering, rather than a purely textual operation done during emission. I don't have time to fix that right now.
2017-07-17Improve handling of `SampleCmpLevelZero`Tim Foley
- We map `SampleCmpLevelZero` to either `textureLod` or `textureGrad` based on what the GLSL spec seems to allow - We map `SamplerComparisonState` to `samplerShadow` (instead of just `sampler`)
2017-07-17Map HLSL `linear` to GLSL... nothingTim Foley
The behavior of the `linear` modifier should be the default interpolation behavior in GLSL.
2017-07-17Merge pull request #110 from tfoleyNV/gl-layer-pick-versionTim Foley
Pick correct GLSL version when `gl_Layer` used
2017-07-17Pick correct GLSL version when `gl_Layer` usedTim Foley
`gl_Layer` as a fragment input requires at least version 4.30 of GLSL, so we try to track that information when we see the name used. Note that this does *not* override a user-specified `#version` line. This required re-ordering when lowering happens relative to emitting the `#version` directive, since this code works by actually modifying the chosen profile for the entry point. Yes, that is kind of gross and we should do something cleaner in the long term.
2017-07-17Merge pull request #108 from tfoleyNV/gh-105Tim Foley
Don't crash-fail on errors in entry point parameters
2017-07-17Merge pull request #107 from tfoleyNV/glsl-matrix-mult-bugTim Foley
Add explicit operator overloads for scalar/matrix cases
2017-07-17Add emit logic for generic app expressionsTim Foley
Work on #105 These can occur in unchecked code (or code that had a semantic error), so we need to be able to handle them.
2017-07-17Fix AST node type for `TriangleStream`Tim Foley
- This was being mapped to `HLSLLineStreamType` because of a copy-paste typo
2017-07-17Skip unknown types during parameter-binding/-reflection stepTim Foley
Work on #105 If a semantic error occurs in the type of an entry-point parameter, we need to be able to skip over it when doing parameter binding and reflection-generation work.
2017-07-17Add explicit operator overloads for scalar/matrix casesTim Foley
Fixes #103 - Previously I was relying on scalar-to-vector promotion to pick the right type in these cases, but I hadn't implemented scalar-to-matrix promotion (I should...) - Rather than relying on promotion behavior, this change goes ahead and adds explicit overloads. I think this is probably a better decision in the long term, since one might want to support these cases for operators, while warning (or erroring) on the more general cases of implicit conversion. - This covers matrix/scalar, scalar/matrix, vector/scalar, and scalar/vector cases
2017-07-17Merge pull request #106 from tfoleyNV/varying-integerTim Foley
Handle `flat` interpolation cases in cross compilation
2017-07-17Handle `flat` interpolation cases in cross compilationTim Foley
Fixes #104 - Map HLSL `nointerpolation` to GLSL `flat` - When lowering a `struct` type varying input/output, look for interpolation modifiers along the "chain" from the leaf field up to the original shader input variable (and take the first one found) - Not sure if this is strictly needed, but it seems like a reasonable policy - Add `flat` to varying input of integer type, with no other interpolation modifier - Note: I do *not* do anything to ignore a manually imposed interpolation modifier that might be incorrect
2017-07-14Merge pull request #92 from tfoleyNV/glsl-thread-group-sizeTim Foley
Add reflection support for GLSL thread-group-size modifier
2017-07-14Add reflection support for GLSL thread-group-size modifierTim Foley
Fixes #15 These are the modifiers like: layout(local_size_x = 16) in; Unlike the HLSL case, these don't get attache to the entry point function itself, so there is a bit more work involed in looking them up. Just to make sure I didn't mess up the HLSL case, I went ahead and added two tests for this capability: one for GLSL and one for HLSL.
2017-07-14Merge pull request #90 from tfoleyNV/cbuffer-field-layout-fixTim Foley
Adjust type layout when parameter block constains member using the sa…
2017-07-14Adjust type layout when parameter block constains member using the same resourceTim Foley
If we have something like to following in HLSL: cbuffer C { Texture2D t; ... } and we are compiling to GLSL, then both `C` and `C.t` consume the same kind of resource (a descriptor-table slot). The way reflection was working right now, querying the index of `C` would return its binding (let's say it is `4` just to be concrete) and then a query on `C::t` would give its offset, which was being computed as `0` because it is the first field in the logical `struct` type. That obviously leads to bad math and requires some subtle `+1`s in cases to get things right (e.g., when scalaring during lowering, I had to carefully add one in some cases). It is unreasonable to expect users to deal with this. This commit changes it so that the offset of field `C::t` is `1` so that hopefully more things Just Work. The special-case logic in lowering is now gone. One important catch here is that this pretty much only works in the case where the element type of a parameter block is a `struct` type (which is really all that makes sense right now). If we ever want to generalize this in the future, then it will probably be necessary to change the `TypeLayout` case for parameter blocks to store a `VarLayout` for the element, rather than just a `TypeLayout`.
2017-07-14Merge pull request #89 from tfoleyNV/glpervertex-location-fixTim Foley
Don't use "auto locations" mode in glslang
2017-07-14Don't assign a `binding` to a `push_constant` bufferTim Foley
Fixes #12 - This was a latent issue, but the previous commit brought it to the front. - As indicated in #12, I don't allocate a descriptor-table slot to the block - Instead I allocate a `PushConstantBuffer` - Unlike what #12 asks for, I don't use a different resource type for the contents of the block - Pretty much all the logic is easiest if these continue to be just plain `Uniform` data
2017-07-14Don't use "auto locations" mode in glslangTim Foley
Fixes #88 The code was using `glslang::TShader::setAutoMapLocations` as a workaround for an old glslang issue, but apparently this mode has a bug where it ends up applying a `location` layout to the implicitly-created `gl_PerVertex` definition (which shouldn't be allowed). This change drops the call to `setAutoMapLocations` (and `setAutoMapBindings`) since it should no longer be required.
2017-07-13Merge pull request #87 from tfoleyNV/debug-dumpTim Foley
Add support for dumping intermediates for debugging.
2017-07-13Add support for dumping intermediates for debugging.Tim Foley
Calling: spSetDumpIntermedites(compileRequest, true); will set up a mode where Slang tries to dump every intermediate HLSL, GLSL, DXBC, SPIR-V, etc. file it generates. If SPIR-V or DXBC is requested then we also dump assembly of those. Right now the files are all named as `slang-<counter>.<ext>`, and get dropped in whatever the working directory is, but I'm open to ideas on how to improve that. Note: this change introduces a new binary interface to `glslang`, so pulling it requires an updated `glslang.dll`.
2017-07-13Merge pull request #86 from tfoleyNV/resource-array-layout-fixTim Foley
An array of resources in Vulkan only consumes one binding
2017-07-13Merge pull request #85 from tfoleyNV/workingTim Foley
Various bug fixes
2017-07-13An array of resources in Vulkan only consumes one bindingTim Foley
Fixes #84 - When computing resource usage for an array type, don't multiply the resource usage of the element type by the element count foor descriptor-table-slot resources. - When reporting the "stride" of an array type through reflection, report the stride for descriptor table slots as zero, always.
2017-07-13Add several missing GLSL qualifiersTim Foley
Fixes #81 - This is based on a san over the GLSL spec (but is probably not exhaustive) - There are some qualifiers that are currently being handled by general-case code for all languages, and some of these happen to cover GLSL qualifiers too - Some of the qualifiers being handled by the general-case mechanism are *accidentally* working for GLSL (e.g., the HLSL `shared` qualifier doesn't mean the same thing as GLSL `shared`, but as long as we spit it back out nobody seems to care). - This should be fixed sooner or later.
2017-07-13Allow GLSL `#version` to be selected based on profileTim Foley
Fixes #83 - The basic idea is that I added a bunch of more specific profile names line `glsl_vertex_430` which indicate the desired GLSL version the user wants. - An explicit `#version` line in the code always overrides one specified by profile, though
2017-07-13Allow `spGetEntryPointCode` to return text results tooTim Foley
Fixes #77 - The `spGetEntryPointSource` function is now no longer needed, but I'm not going to "deprecate" it just yet
2017-07-13Don't emit C-style `#line` directives when directly generating GLSLTim Foley
- This fixes the render tests, which aren't tested by the continuous integration setup - This was broken in the commit that decided to use C-style directives all the time. - This works for stuff that eventually passes through glslang (or at least our build of it) - It *doensn't* work if we take the GLSL and pass it off to an OpenGL driver (which is what I do for testing) - A longer-term fix is still required to deal with line directives properly
2017-07-13Update version of `glslang` in submoduleTim Foley
2017-07-12Merge pull request #80 from tfoleyNV/falcor-workTim Foley
Fixes for shader cross-compilation
2017-07-12Add ability for intrinsics to require GLSL extensionsTim Foley
When cross-compiling, we need to detect when an intrinsic is used that required non-default GLSL capabilities and emit an appropriate `#extension ... : require` line. I'm handling this by attaching a custom modifier to declarations that require an extension in order to be callable.
2017-07-12Don't report error on assigning to an erroneous expressionTim Foley
An expression with error type may still fail the l-value check, but we don't want to emit an error in that case.
2017-07-12Don't emit interpolation modifiers on struct fields when outputting GLSLTim Foley
HLSL (and thus Slang) commonly puts interpolation modifiers like `sample` on the fields of `struct` types used as stage input/output, while GLSL only allows them on global-scope `in` and `out` variables (or ones in blocks). This change emits a really hacky filtering step to skip over certain modifiers when emitting a declaration. This lets us skip interpolation-mode modifiers when outputting a struct field to GLSL. Note: this probably gets the `in` or `out` block case wrong...
2017-07-12Use C-style line directives, even for GLSLTim Foley
- As long as we are always going to pass GLSL through glslang, there should be no harm in this - Eventually we may need to re-enable the old style
2017-07-12Properly register error on downstream compiler failureTim Foley
- The old code was just doing `exit(1)` if glslang or `D3DCompile` failed, which is obviously unacceptable - The new approach adds the output to the diagnostic buffer (or invokes the callback), and tracks the error count just like any other errors
2017-07-12Add tuple lowering logic for assignmentTim Foley
- When assigning tuples `(a0, ...) = (b0, ...)` generate a tuple of assignments `(a0 = b0, ...)` - Given an expression statement on a tuple `(a0, ...);` generate a sequence of statements `a0; ...`
2017-07-12Merge pull request #79 from tfoleyNV/sample-rate-reflectionTim Foley
Sample rate reflection
2017-07-12Add basic reflection query for checking if entry point is "sample-rate"Tim Foley
- This really just checks two basic things: 1. Was there any global variable declared with `in` and `sample`? 2. Did any code encountered during lowering referenece `gl_SampleIndex`? - This doesn't cover what HLSL could need, nor what we would need for cross-compilation. Consider it GLSL-specific for now. - In order to generate the information with even a reasonable chance of being accurate (not giving a ton of false positives) I tried to integrate the checks into the lowering process (so they only see code that is referenced, one hopes). - For this to work with my testing setup, I needed to make sure that lowering is always performed, prior to emitting reflection info - This change broke several reflection tests, because they had been using code that wouldn't actually pass the downstream compiler. I checked in fixes for those.
2017-07-12Add per-entry-point information to reflection JSON dumpsTim Foley
- This also adds reflection API for querying: - Entry point name - Entry point parameter list
2017-07-11Merge pull request #76 from tfoleyNV/gh-75Tim Foley
Make parser recovering more robust to avoid infinite loops
2017-07-11Make parser recovering more robust to avoid infinite loopsTim Foley
Fixes #75 In order to avoid cascaded errors, I went ahead and made the parser refuse to skip past a `}` in recovery mode. The problem with this is that we fail to make forward progress if we are stuck on a `}` (this happens if you have an extra `}` at the global scope.