From 9653dcc2c9d5d20d3d0e8918aaf1d5b09e963060 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 3 Dec 2019 09:58:59 -0500 Subject: getStringHash on string literals (#1140) * WIP getStringHash * Have a use. * Add slang-string-hash.h/.cpp * Use StringSlicePool for holding strings for StringHash. Add outputBuffer to string-literal-hash.slang so value can be tested. Ignore the GlobalHashedStringLiterals instruction on emit. * Add all the hashed string literals to ProgramLayout. * Add reflection support for hashed string literals to reflection test. * Fix string literal hash test. * Small fixes to pass test suite. * Fix issue in serialization where IRUse is not correctly initialized. * Fix problem initializing IRUse for string hash pass. Remove hack from slang-ir-specialize - specially handling if user is not null. * * Use shared builder when replacing getStringHash * Comments for functions in slang-ir-string-hash * Do not allow zero length string literals. Could be allowed, but doing so would require StringSlicePool to have a special case (or some other mechanism) --- tests/ir/string-literal-hash-reflection.slang | 15 ++++++++ .../string-literal-hash-reflection.slang.expected | 44 ++++++++++++++++++++++ tests/ir/string-literal-hash.slang | 17 +++++++++ tests/ir/string-literal-hash.slang.expected.txt | 4 ++ tests/ir/string-literal-module.slang | 6 +++ 5 files changed, 86 insertions(+) create mode 100644 tests/ir/string-literal-hash-reflection.slang create mode 100644 tests/ir/string-literal-hash-reflection.slang.expected create mode 100644 tests/ir/string-literal-hash.slang create mode 100644 tests/ir/string-literal-hash.slang.expected.txt create mode 100644 tests/ir/string-literal-module.slang (limited to 'tests') diff --git a/tests/ir/string-literal-hash-reflection.slang b/tests/ir/string-literal-hash-reflection.slang new file mode 100644 index 000000000..85d6ac3e4 --- /dev/null +++ b/tests/ir/string-literal-hash-reflection.slang @@ -0,0 +1,15 @@ +//TEST:REFLECTION:-stage compute -entry computeMain -target hlsl + +import string_literal_module; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain( + uint tid : SV_DispatchThreadIndex) +{ + int value = doSomethingElse() + getStringHash("Hello \t\n\0x083 World"); + outputBuffer[tid] = value; +} + diff --git a/tests/ir/string-literal-hash-reflection.slang.expected b/tests/ir/string-literal-hash-reflection.slang.expected new file mode 100644 index 000000000..4b3726efe --- /dev/null +++ b/tests/ir/string-literal-hash-reflection.slang.expected @@ -0,0 +1,44 @@ +result code = 0 +standard error = { +} +standard output = { +{ + "parameters": [ + { + "name": "outputBuffer", + "binding": {"kind": "unorderedAccess", "index": 0}, + "type": { + "kind": "resource", + "baseShape": "structuredBuffer", + "access": "readWrite", + "resultType": { + "kind": "scalar", + "scalarType": "int32" + } + } + } + ], + "entryPoints": [ + { + "name": "computeMain", + "stage:": "compute", + "parameters": [ + { + "name": "tid", + "semanticName": "SV_DISPATCHTHREADINDEX", + "type": { + "kind": "scalar", + "scalarType": "uint32" + } + } + ], + "threadGroupSize": [4, 1, 1] + } + ], + "hashedStrings": { + "Hello \t\n\0x083 World": -215446506, + "Try another": 900483678 + } + +} +} diff --git a/tests/ir/string-literal-hash.slang b/tests/ir/string-literal-hash.slang new file mode 100644 index 000000000..b6ab8bf4e --- /dev/null +++ b/tests/ir/string-literal-hash.slang @@ -0,0 +1,17 @@ +//TEST(compute):COMPARE_COMPUTE: -cpu +//TEST(compute):COMPARE_COMPUTE: +//TEST(compute):COMPARE_COMPUTE: -vk + +import string_literal_module; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain( + uint3 tid : SV_DispatchThreadID) +{ + int value = doSomethingElse() + getStringHash("Hello \t\n\0x083 World"); + outputBuffer[tid.x] = value; +} + diff --git a/tests/ir/string-literal-hash.slang.expected.txt b/tests/ir/string-literal-hash.slang.expected.txt new file mode 100644 index 000000000..8398d4098 --- /dev/null +++ b/tests/ir/string-literal-hash.slang.expected.txt @@ -0,0 +1,4 @@ +28D4D674 +28D4D674 +28D4D674 +28D4D674 diff --git a/tests/ir/string-literal-module.slang b/tests/ir/string-literal-module.slang new file mode 100644 index 000000000..96fb62088 --- /dev/null +++ b/tests/ir/string-literal-module.slang @@ -0,0 +1,6 @@ +//TEST_IGNORE_FILE: + +int doSomethingElse() +{ + return getStringHash("Try another"); +} -- cgit v1.2.3