https://github.com/shader-slang/slang
Revision af84d85799758234110fc42f0ba5c771dacb5fe3 authored by Tim Foley on 07 February 2020, 16:45:32 UTC, committed by GitHub on 07 February 2020, 16:45:32 UTC
* Change handling of strings for HLSL/GLSL targets

This change switches our handling of string literals and `getStringHash` to something that is more streamlined at the cost of potentially being less general/flexible.

* `String` is now allowed as a parameter type in user-defined functions

* `getStringHash` is now allowed to apply to `String`-type values that aren't literals

* The list of strings in an IR module is now generated during IR lowering as part of lowering a string literal expression, rather than being defined by recursively walking the IR of the module looking for `getStringHash` calls. The public API still refers to these as "hashed" strings, but they are realistically now "static strings."

* When emitting code for HLSL/GLSL, the `String` type emits as `int`, and `getStringHash(x)` emits as `x`.

In terms of implementation, the choice was whether to translate `String` over to `int` in an explicit IR pass, or to lump it into the emit pass. While adding the logic to emit clutters up an already complicated step, it is ultimately much easier to make the change there than to write a clean IR pass to eliminate all `String` use.

Note that other targets that can handle a more full-featured `String` type are *not* addressed by this change and thus do not support `String` at all. It may be woth emitting `String` as `const char*` on those targets, and emitting string literals directly, but the `getStringHash` function would need to be implemented in the "prelude" then, and we probably want to pick a well-known/-documented hash algorithm before we go that far.

This change also brings along some some clean-ups to the `gpu-printing` example, since it can now take advantage of the new functionality of `String`.

* Fix up tests for new string handling

* Add global string literal list to string-literal test (since we now list *all* static string literals and not just those passed to `getStringHash`)

* Disable `getStringHash` test on CPU, since we don't have a working `String` on that platform right now (only HLSL/GLSL)

Co-authored-by: Tim Foley <tim.foley.is@gmail.com>
1 parent 7981da5
History
Tip revision: af84d85799758234110fc42f0ba5c771dacb5fe3 authored by Tim Foley on 07 February 2020, 16:45:32 UTC
Change handling of strings for HLSL/GLSL targets (#1204)
Tip revision: af84d85
File Mode Size
docs
examples
external
prelude
source
tests
tools
.editorconfig -rw-r--r-- 937 bytes
.gitattributes -rw-r--r-- 95 bytes
.gitignore -rw-r--r-- 480 bytes
.gitmodules -rw-r--r-- 774 bytes
.travis.yml -rw-r--r-- 1.7 KB
CODE_OF_CONDUCT.md -rw-r--r-- 3.1 KB
LICENSE -rw-r--r-- 1.1 KB
README.md -rw-r--r-- 7.1 KB
appveyor.yml -rw-r--r-- 4.0 KB
premake5.lua -rw-r--r-- 29.4 KB
slang-com-helper.h -rw-r--r-- 4.8 KB
slang-com-ptr.h -rw-r--r-- 4.8 KB
slang-tag-version.h -rw-r--r-- 36 bytes
slang.h -rw-r--r-- 126.9 KB
slang.sln -rw-r--r-- 10.8 KB
test.bat -rw-r--r-- 1.4 KB
travis_build.sh -rw-r--r-- 460 bytes
travis_test.sh -rw-r--r-- 435 bytes

README.md

back to top