From cb61eec948b80a5e3f4e305513a3656374ef3191 Mon Sep 17 00:00:00 2001 From: Rex Xu Date: Wed, 7 Mar 2018 13:10:01 +0800 Subject: [PATCH] HLSL: Map min types to GLSL 16-bit types --- StandAlone/StandAlone.cpp | 8 +++++++- glslang/MachineIndependent/parseVersions.h | 1 + glslang/Public/ShaderLang.h | 1 + hlsl/hlslGrammar.cpp | 11 +++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index 8452a68d..fc5913e9 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -156,6 +156,7 @@ const char* entryPointName = nullptr; const char* sourceEntryPointName = nullptr; const char* shaderStageName = nullptr; const char* variableName = nullptr; +bool HlslEnable16BitTypes = false; std::vector IncludeDirectoryList; int ClientInputSemanticsVersion = 100; // maps to, say, #define VULKAN 100 int VulkanClientVersion = 100; // would map to, say, Vulkan 1.0 @@ -450,6 +451,8 @@ void ProcessArguments(std::vector>& workItem lowerword == "hlsl-iomapper" || lowerword == "hlsl-iomapping") { Options |= EOptionHlslIoMapping; + } else if (lowerword == "hlsl-enable-16bit-types") { + HlslEnable16BitTypes = true; } else if (lowerword == "invert-y" || // synonyms lowerword == "iy") { Options |= EOptionInvertY; @@ -513,7 +516,7 @@ void ProcessArguments(std::vector>& workItem setOpenGlSpv(); OpenGLClientVersion = 450; } else - Error("--target-env expected vulkan1.0 or opengl"); + Error("--target-env expected vulkan1.0, opengl, or hlsl-16bit-types"); } bumpArg(); } else if (lowerword == "variable-name" || // synonyms @@ -701,6 +704,8 @@ void SetMessageOptions(EShMessages& messages) messages = (EShMessages)(messages | EShMsgHlslOffsets); if (Options & EOptionDebug) messages = (EShMessages)(messages | EShMsgDebugInfo); + if (HlslEnable16BitTypes) + messages = (EShMessages)(messages | EShMsgHlslEnable16BitTypes); } // @@ -1334,6 +1339,7 @@ void usage() " --hlsl-offsets Allow block offsets to follow HLSL rules\n" " Works independently of source language\n" " --hlsl-iomap Perform IO mapping in HLSL register space\n" + " --hlsl-enable-16bit-types Allow use of 16-bit types in SPIR-V for HLSL\n" " --invert-y | --iy invert position.Y output in vertex shader\n" " --keep-uncalled don't eliminate uncalled functions\n" " --ku synonym for --keep-uncalled\n" diff --git a/glslang/MachineIndependent/parseVersions.h b/glslang/MachineIndependent/parseVersions.h index 23f4cd87..7c9f5c25 100755 --- a/glslang/MachineIndependent/parseVersions.h +++ b/glslang/MachineIndependent/parseVersions.h @@ -114,6 +114,7 @@ public: bool relaxedErrors() const { return (messages & EShMsgRelaxedErrors) != 0; } bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; } bool isReadingHLSL() const { return (messages & EShMsgReadHlsl) == EShMsgReadHlsl; } + bool hlslEnable16BitTypes() const { return (messages & EShMsgHlslEnable16BitTypes) != 0; } TInfoSink& infoSink; diff --git a/glslang/Public/ShaderLang.h b/glslang/Public/ShaderLang.h index fe8a3f28..8f4b32e9 100644 --- a/glslang/Public/ShaderLang.h +++ b/glslang/Public/ShaderLang.h @@ -200,6 +200,7 @@ enum EShMessages { EShMsgKeepUncalled = (1 << 8), // for testing, don't eliminate uncalled functions EShMsgHlslOffsets = (1 << 9), // allow block offsets to follow HLSL rules instead of GLSL rules EShMsgDebugInfo = (1 << 10), // save debug information + EShMsgHlslEnable16BitTypes = (1 << 11), // enable use of 16-bit types in SPIR-V for HLSL }; // diff --git a/hlsl/hlslGrammar.cpp b/hlsl/hlslGrammar.cpp index 57e34d1d..c09bee96 100755 --- a/hlsl/hlslGrammar.cpp +++ b/hlsl/hlslGrammar.cpp @@ -1379,12 +1379,23 @@ bool HlslGrammar::acceptType(TType& type, TIntermNode*& nodeList) { // Basic types for min* types, broken out here in case of future // changes, e.g, to use native halfs. +#ifdef AMD_EXTENSIONS + bool enable16BitTypes = parseContext.hlslEnable16BitTypes(); + + const TBasicType min16float_bt = enable16BitTypes ? EbtFloat16 : EbtFloat; + const TBasicType min10float_bt = enable16BitTypes ? EbtFloat16 : EbtFloat; + const TBasicType half_bt = enable16BitTypes ? EbtFloat16 : EbtFloat; + const TBasicType min16int_bt = enable16BitTypes ? EbtInt16 : EbtInt; + const TBasicType min12int_bt = enable16BitTypes ? EbtInt16 : EbtInt; + const TBasicType min16uint_bt = enable16BitTypes ? EbtUint16 : EbtUint; +#else static const TBasicType min16float_bt = EbtFloat; static const TBasicType min10float_bt = EbtFloat; static const TBasicType half_bt = EbtFloat; static const TBasicType min16int_bt = EbtInt; static const TBasicType min12int_bt = EbtInt; static const TBasicType min16uint_bt = EbtUint; +#endif // Some types might have turned into identifiers. Take the hit for checking // when this has happened.