diff options
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/compiler.cpp | 44 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang | 21 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang.h | 21 | ||||
| -rw-r--r-- | source/slang/profile-defs.h | 13 | ||||
| -rw-r--r-- | source/slang/slang.vcxproj.filters | 22 |
5 files changed, 110 insertions, 11 deletions
diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp index b7cbc2327..66df01db0 100644 --- a/source/slang/compiler.cpp +++ b/source/slang/compiler.cpp @@ -279,13 +279,43 @@ namespace Slang auto profile = getEffectiveProfile(entryPoint, targetReq); + // If we have been invoked in a pass-through mode, then we need to make sure + // that the downstream compiler sees whatever options were passed to Slang + // via the command line or API. + // + // TODO: more pieces of information should be added here as needed. + // + List<D3D_SHADER_MACRO> dxMacrosStorage; + D3D_SHADER_MACRO const* dxMacros = nullptr; + if( entryPoint->compileRequest->passThrough != PassThroughMode::None ) + { + for( auto& define : entryPoint->compileRequest->preprocessorDefinitions ) + { + D3D_SHADER_MACRO dxMacro; + dxMacro.Name = define.Key.Buffer(); + dxMacro.Definition = define.Value.Buffer(); + dxMacrosStorage.Add(dxMacro); + } + for( auto& define : entryPoint->getTranslationUnit()->preprocessorDefinitions ) + { + D3D_SHADER_MACRO dxMacro; + dxMacro.Name = define.Key.Buffer(); + dxMacro.Definition = define.Value.Buffer(); + dxMacrosStorage.Add(dxMacro); + } + D3D_SHADER_MACRO nullTerminator = { 0, 0 }; + dxMacrosStorage.Add(nullTerminator); + + dxMacros = dxMacrosStorage.Buffer(); + } + ID3DBlob* codeBlob; ID3DBlob* diagnosticsBlob; HRESULT hr = D3DCompile_( hlslCode.begin(), hlslCode.Length(), "slang", - nullptr, + dxMacros, nullptr, getText(entryPoint->name).begin(), GetHLSLProfileName(profile), @@ -300,7 +330,17 @@ namespace Slang data.AddRange((uint8_t const*)codeBlob->GetBufferPointer(), (int)codeBlob->GetBufferSize()); codeBlob->Release(); } - if (diagnosticsBlob) + + // Note: we will only output diagnostics coming from a downstream + // compiler in the event of an error (although in that case we will + // end up including any warning diagnostics that are produced as well). + // + // TODO: some day we should aspire to make Slang's output always compile + // cleanly without warnings on downstream compilers (or else suppress those + // warnings), but this is difficult to do in practice without a lot of + // tailoring for the quirks of each compiler (version). + // + if (diagnosticsBlob && FAILED(hr)) { // TODO(tfoley): need a better policy for how we translate diagnostics // back into the Slang world (although we should always try to generate diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 86f9eb946..10665915d 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -750,6 +750,27 @@ __generic<T : __BuiltinArithmeticType, let R : int, let N : int, let C : int> __ float noise(float x); __generic<let N : int> float noise(vector<float, N> x); +/// Indicate that an index may be non-uniform at execution time. +/// +/// Shader Model 5.1 and 6.x introduce support for dynamic indexing +/// of arrays of resources, but place the restriction that *by default* +/// the implementation can assume that any value used as an index into +/// such arrays will be dynamically uniform across an entire `Draw` or `Dispatch` +/// (when using instancing, the value must be uniform across all instances; +/// it does not seem that the restriction extends to draws within a multi-draw). +/// +/// In order to indicate to the implementation that it cannot make the +/// uniformity assumption, a shader programmer is required to pass the index +/// to the `NonUniformResourceIndex` function before using it as an index. +/// The function superficially acts like an identity function. +/// +/// Note: a future version of Slang may take responsibility for inserting calls +/// to this function as necessary in output code, rather than make this +/// the user's responsibility, so that the default behavior of the language +/// is more semantically "correct." +uint NonUniformResourceIndex(uint index); +int NonUniformResourceIndex(int index); + // Normalize a vector __generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> normalize(vector<T,N> x); diff --git a/source/slang/hlsl.meta.slang.h b/source/slang/hlsl.meta.slang.h index c05e81cd1..d63f38e47 100644 --- a/source/slang/hlsl.meta.slang.h +++ b/source/slang/hlsl.meta.slang.h @@ -783,6 +783,27 @@ SLANG_RAW("// noise (deprecated)\n") SLANG_RAW("float noise(float x);\n") SLANG_RAW("__generic<let N : int> float noise(vector<float, N> x);\n") SLANG_RAW("\n") +SLANG_RAW("/// Indicate that an index may be non-uniform at execution time.\n") +SLANG_RAW("///\n") +SLANG_RAW("/// Shader Model 5.1 and 6.x introduce support for dynamic indexing\n") +SLANG_RAW("/// of arrays of resources, but place the restriction that *by default*\n") +SLANG_RAW("/// the implementation can assume that any value used as an index into\n") +SLANG_RAW("/// such arrays will be dynamically uniform across an entire `Draw` or `Dispatch`\n") +SLANG_RAW("/// (when using instancing, the value must be uniform across all instances;\n") +SLANG_RAW("/// it does not seem that the restriction extends to draws within a multi-draw).\n") +SLANG_RAW("///\n") +SLANG_RAW("/// In order to indicate to the implementation that it cannot make the\n") +SLANG_RAW("/// uniformity assumption, a shader programmer is required to pass the index\n") +SLANG_RAW("/// to the `NonUniformResourceIndex` function before using it as an index.\n") +SLANG_RAW("/// The function superficially acts like an identity function.\n") +SLANG_RAW("///\n") +SLANG_RAW("/// Note: a future version of Slang may take responsibility for inserting calls\n") +SLANG_RAW("/// to this function as necessary in output code, rather than make this\n") +SLANG_RAW("/// the user's responsibility, so that the default behavior of the language\n") +SLANG_RAW("/// is more semantically \"correct.\"\n") +SLANG_RAW("uint NonUniformResourceIndex(uint index);\n") +SLANG_RAW("int NonUniformResourceIndex(int index);\n") +SLANG_RAW("\n") SLANG_RAW("// Normalize a vector\n") SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> normalize(vector<T,N> x);\n") SLANG_RAW("\n") diff --git a/source/slang/profile-defs.h b/source/slang/profile-defs.h index 2f029aff0..93703f3b9 100644 --- a/source/slang/profile-defs.h +++ b/source/slang/profile-defs.h @@ -205,6 +205,19 @@ PROFILE_ALIAS(DX_None_6_3, DX_Lib_6_3, sm_6_3) // Define all the GLSL profiles +PROFILE(GLSL_None_110, glsl_110, Unknown, GLSL_110) +PROFILE(GLSL_None_120, glsl_120, Unknown, GLSL_120) +PROFILE(GLSL_None_130, glsl_130, Unknown, GLSL_130) +PROFILE(GLSL_None_140, glsl_140, Unknown, GLSL_140) +PROFILE(GLSL_None_150, glsl_150, Unknown, GLSL_150) +PROFILE(GLSL_None_330, glsl_330, Unknown, GLSL_330) +PROFILE(GLSL_None_400, glsl_400, Unknown, GLSL_400) +PROFILE(GLSL_None_410, glsl_410, Unknown, GLSL_410) +PROFILE(GLSL_None_420, glsl_420, Unknown, GLSL_420) +PROFILE(GLSL_None_430, glsl_430, Unknown, GLSL_430) +PROFILE(GLSL_None_440, glsl_440, Unknown, GLSL_440) +PROFILE(GLSL_None_450, glsl_450, Unknown, GLSL_450) + #define P(UPPER, LOWER, VERSION) \ PROFILE(GLSL_##UPPER##_##VERSION, glsl_##LOWER##_##VERSION, UPPER, GLSL_##VERSION) diff --git a/source/slang/slang.vcxproj.filters b/source/slang/slang.vcxproj.filters index cb0235e61..f12163f27 100644 --- a/source/slang/slang.vcxproj.filters +++ b/source/slang/slang.vcxproj.filters @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Filter Include="Header Files"> @@ -54,6 +54,12 @@ <ClInclude Include="ir-insts.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="ir-restructure-scoping.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="ir-restructure.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="ir-ssa.h"> <Filter>Header Files</Filter> </ClInclude> @@ -153,10 +159,6 @@ <ClInclude Include="vm.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="ir-restructure.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="ir-restructure-scoping.h" /> </ItemGroup> <ItemGroup> <ClCompile Include="bytecode.cpp"> @@ -186,6 +188,12 @@ <ClCompile Include="ir-legalize-types.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="ir-restructure-scoping.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="ir-restructure.cpp"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="ir-ssa.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -258,10 +266,6 @@ <ClCompile Include="vm.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="ir-restructure.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="ir-restructure-scoping.cpp" /> </ItemGroup> <ItemGroup> <None Include="slang.natvis"> |
