https://github.com/shader-slang/slang
Revision 76dca35b3fabbe77d4c01640423bdf5ce93d27d4 authored by Tim Foley on 19 July 2017, 15:32:44 UTC, committed by Tim Foley on 20 July 2017, 17:09:25 UTC
- The easy part here is treating `NV_` prefixed semantics as another case of "system-value" semantics

- Mapping the new semantics (`NV_X_RIGHT` and `NV_VIEWPORT_MASK`) to their GLSL equivalents is harder
  - Instead of a single "right-eye vertex" output, GLSL defines an array of per-view positions
  - Instead of a vector of masks, GLSL defines an array of per-view masks

- Another point here is that a lot of semantics that appear as `uint` in HLSL are `int` in GLSL, which can lead to conversion issues.

- The approach here is to have the lowering pass introduce a notion of assignment with "fixups," which will try to cast things as needed
  - When assigning to a simple value with the "wrong" type, introduce a cast
  - When assigning to an array from a vector, break out multiple assignments of individual vector/array elements

- In order to facilitate the above, I needed to add actual types to the magic expressions I introduce to represent GLSL builtin variables. These were taken by scanning the online documentation for GL, so they might not be perfect.

- Major issues with the approach in this change:

  - No attempt is being made here to check that the original declaration used a type appropriate to the semantic. The assumption is that this logic only ever triggers for Slang entry points, or GLSL entry points using a Slang `struct` type for input/output (and for right now Slang code is only ever written by "understanding" developers)

  - In the case of a Slang entry point, we always copy varying parameters in/out around the call to `main_`, so this approach should handle calls to functions with `out` or `in out` parameters okay, but it is *not* robust to cases where we don't want to copy in all the entry point parameters first thing (e.g., a GS), so that will have to change

  - In the GLSL case (or if we revise the approach to Slang entry points), there is going to be a problem if these converted varying parameters are ever passed as arguments to `out` or `in out` parameters. In these cases we need to do more sleight-of-hand to reify a temporary variable and do the necessary copy-in/copy-out. Being able to do that logic relies on having correct information about callees, which requires having robust semantic analysis of the function body. There is only so much we can do...

- A better long-term approach would not rely on an ad-hoc "fixup" conversion during assignment, but would instead implement the GLSL builtin variables as, effectively, global "property" declarations that have both `get` and `set` accessors, and then tunnel a reference to such a property down through lowering, where it can lower to uses of the "getter" or "setter" as appropriate in context (and the result type of the getter/setter can be what we'd want/expect).
1 parent f07c01c
History
Tip revision: 76dca35b3fabbe77d4c01640423bdf5ce93d27d4 authored by Tim Foley on 19 July 2017, 15:32:44 UTC
Translate NV single-pass stereo extension from Slang to GLSL
Tip revision: 76dca35
File Mode Size
build
examples
external
source
tests
tools
.gitignore -rw-r--r-- 385 bytes
.gitmodules -rw-r--r-- 107 bytes
LICENSE -rw-r--r-- 1.1 KB
README.md -rw-r--r-- 1.5 KB
appveyor.yml -rw-r--r-- 3.3 KB
slang.h -rw-r--r-- 30.8 KB
slang.sln -rw-r--r-- 6.4 KB
test.bat -rw-r--r-- 1.4 KB

README.md

back to top