From 27c6e9b01f7386263bde90e16812be46327015c2 Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Wed, 21 May 2025 21:11:01 -0700 Subject: Initial `dyn` keyword support & `-lang 2026` compiler option (#7172) fixes: [#7143](https://github.com/shader-slang/slang/issues/7143) fixes: [#7146](https://github.com/shader-slang/slang/issues/7146) Goal of PR: * This PR is part of the larger #7115 refactor to how dynamic dispatch works. * The first step is to add the `-std ` flag. * The second step is to provide basic `dyn` keyword support in AST. This does not include `varDecl` support since most of these interactions require `some` keyword support. Future PR(s) goal: * Support `some` keyword in AST. With this we will also implement all varDecl interactions between `dyn` and `some`. * Add IR support for `some` and `dyn`. Breakdown of PR: * most of the logic is in `validateDyn.*`. This was done so that in the future when we implement more features we will have an easy time removing/adding restrictions to `dyn` interfaces. Breaking changes: * As per spec (https://github.com/shader-slang/spec/pull/14/files), any type conforming to a `dyn` interface errors if member list contains one of the following: opaque type, non copyable type, or unsized type. * Due to the breaking change, the test `tests\compute\dynamic-dispatch-bindless-texture.slang` is incorrect. This has been fixed. --- source/core/slang-type-text-util.cpp | 16 ++++++++++++++++ source/core/slang-type-text-util.h | 5 +++++ 2 files changed, 21 insertions(+) (limited to 'source/core') diff --git a/source/core/slang-type-text-util.cpp b/source/core/slang-type-text-util.cpp index 2261ed614..4797395b7 100644 --- a/source/core/slang-type-text-util.cpp +++ b/source/core/slang-type-text-util.cpp @@ -99,6 +99,12 @@ static const NamesDescriptionValue s_languageInfos[] = { {SLANG_SOURCE_LANGUAGE_CUDA, "cu,cuda", "CUDA"}, }; +static const NamesDescriptionValue s_stdRevisionInfos[] = { + {SLANG_STD_REVISION_UNKNOWN, "unknown", "Unknown"}, + {SLANG_STD_REVISION_2025, "2025,default", "Slang language rules for 2025 and older"}, + {SLANG_STD_REVISION_2026, "2026", "Slang language rules for 2026 and newer"}, +}; + static const NamesDescriptionValue s_compilerInfos[] = { {SLANG_PASS_THROUGH_NONE, "none", "Unknown"}, {SLANG_PASS_THROUGH_FXC, "fxc", "FXC HLSL compiler"}, @@ -217,6 +223,11 @@ static const NamesDescriptionValue s_fileSystemTypes[] = { return makeConstArrayView(s_languageInfos); } +/* static */ ConstArrayView TypeTextUtil::getStdRevisionInfos() +{ + return makeConstArrayView(s_stdRevisionInfos); +} + /* static */ ConstArrayView TypeTextUtil::getCompilerInfos() { return makeConstArrayView(s_compilerInfos); @@ -317,6 +328,11 @@ static const NamesDescriptionValue s_fileSystemTypes[] = { return NameValueUtil::findValue(getLanguageInfos(), text, SLANG_SOURCE_LANGUAGE_UNKNOWN); } +/* static */ SlangStdRevision TypeTextUtil::findStdRevision(const UnownedStringSlice& text) +{ + return NameValueUtil::findValue(getStdRevisionInfos(), text, SLANG_STD_REVISION_UNKNOWN); +} + /* static */ SlangPassThrough TypeTextUtil::findPassThrough(const UnownedStringSlice& slice) { return NameValueUtil::findValue(getCompilerInfos(), slice, SLANG_PASS_THROUGH_NONE); diff --git a/source/core/slang-type-text-util.h b/source/core/slang-type-text-util.h index 730888254..bc136c3ab 100644 --- a/source/core/slang-type-text-util.h +++ b/source/core/slang-type-text-util.h @@ -33,6 +33,8 @@ struct TypeTextUtil /// Get the language infos static ConstArrayView getLanguageInfos(); + /// Get the std revision infos + static ConstArrayView getStdRevisionInfos(); /// Get the compiler infos static ConstArrayView getCompilerInfos(); /// Get the archive type infos @@ -71,6 +73,9 @@ struct TypeTextUtil /// Given a source language name returns a source language. Name here is distinct from extension static SlangSourceLanguage findSourceLanguage(const UnownedStringSlice& text); + /// Given a std revision returns a std revision. + static SlangStdRevision findStdRevision(const UnownedStringSlice& text); + /// Given a name returns the pass through static SlangPassThrough findPassThrough(const UnownedStringSlice& slice); static SlangResult findPassThrough( -- cgit v1.2.3