Commit 4be4aebd by John Kessenich

Infrastructure: Non-functional: Move to rich description of environment.

This is for input languages, client APIs, code to generate, etc.
parent 4fbb8cb4
...@@ -715,9 +715,27 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits) ...@@ -715,9 +715,27 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
if (Options & EOptionAutoMapLocations) if (Options & EOptionAutoMapLocations)
shader->setAutoMapLocations(true); shader->setAutoMapLocations(true);
// Set up the environment, some subsettings take precedence over earlier
// ways of setting things.
if (Options & EOptionSpv) {
if (Options & EOptionVulkanRules) {
shader->setEnvInput((Options & EOptionReadHlsl) ? glslang::EShSourceHlsl
: glslang::EShSourceGlsl,
compUnit.stage, glslang::EShClientVulkan, 100);
shader->setEnvClient(glslang::EShClientVulkan, 100);
shader->setEnvTarget(glslang::EshTargetSpv, 0x00001000);
} else {
shader->setEnvInput((Options & EOptionReadHlsl) ? glslang::EShSourceHlsl
: glslang::EShSourceGlsl,
compUnit.stage, glslang::EShClientOpenGL, 100);
shader->setEnvClient(glslang::EShClientOpenGL, 450);
shader->setEnvTarget(glslang::EshTargetSpv, 0x00001000);
}
}
shaders.push_back(shader); shaders.push_back(shader);
const int defaultVersion = Options & EOptionDefaultDesktop? 110: 100; const int defaultVersion = Options & EOptionDefaultDesktop ? 110 : 100;
DirStackFileIncluder includer; DirStackFileIncluder includer;
std::for_each(IncludeDirectoryList.rbegin(), IncludeDirectoryList.rend(), [&includer](const std::string& dir) { std::for_each(IncludeDirectoryList.rbegin(), IncludeDirectoryList.rend(), [&includer](const std::string& dir) {
......
...@@ -50,7 +50,8 @@ namespace glslang { ...@@ -50,7 +50,8 @@ namespace glslang {
TParseContext::TParseContext(TSymbolTable& symbolTable, TIntermediate& interm, bool parsingBuiltins, TParseContext::TParseContext(TSymbolTable& symbolTable, TIntermediate& interm, bool parsingBuiltins,
int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language,
TInfoSink& infoSink, bool forwardCompatible, EShMessages messages) : TInfoSink& infoSink, bool forwardCompatible, EShMessages messages) :
TParseContextBase(symbolTable, interm, parsingBuiltins, version, profile, spvVersion, language, infoSink, forwardCompatible, messages), TParseContextBase(symbolTable, interm, parsingBuiltins, version, profile, spvVersion, language,
infoSink, forwardCompatible, messages),
inMain(false), inMain(false),
blockName(nullptr), blockName(nullptr),
limits(resources.limits), limits(resources.limits),
......
...@@ -355,9 +355,9 @@ void TParseVersions::getPreamble(std::string& preamble) ...@@ -355,9 +355,9 @@ void TParseVersions::getPreamble(std::string& preamble)
// #define VULKAN XXXX // #define VULKAN XXXX
const int numberBufSize = 12; const int numberBufSize = 12;
char numberBuf[numberBufSize]; char numberBuf[numberBufSize];
if (spvVersion.vulkan > 0) { if (spvVersion.vulkanGlsl > 0) {
preamble += "#define VULKAN "; preamble += "#define VULKAN ";
snprintf(numberBuf, numberBufSize, "%d", spvVersion.vulkan); snprintf(numberBuf, numberBufSize, "%d", spvVersion.vulkanGlsl);
preamble += numberBuf; preamble += numberBuf;
preamble += "\n"; preamble += "\n";
} }
......
...@@ -72,14 +72,19 @@ inline const char* ProfileName(EProfile profile) ...@@ -72,14 +72,19 @@ inline const char* ProfileName(EProfile profile)
} }
// //
// SPIR-V has versions for multiple things; tie them together. // What source rules, validation rules, target language, etc. are needed
// 0 means a target or rule set is not enabled. // desired for SPIR-V?
//
// 0 means a target or rule set is not enabled (ignore rules from that entity).
// Non-0 means to apply semantic rules arising from that version of its rule set.
// The union of all requested rule sets will be applied.
// //
struct SpvVersion { struct SpvVersion {
SpvVersion() : spv(0), vulkan(0), openGl(0) {} SpvVersion() : spv(0), vulkanGlsl(0), vulkan(0), openGl(0) {}
unsigned int spv; // the version of the targeted SPIR-V, as defined by SPIR-V in word 1 of the SPIR-V binary header unsigned int spv; // the version of SPIR-V to target, as defined by "word 1" of the SPIR-V binary header
int vulkan; // the version of semantics for Vulkan; e.g., for GLSL from KHR_vulkan_glsl "#define VULKAN" int vulkanGlsl; // the version of GLSL semantics for Vulkan, from GL_KHR_vulkan_glsl, for "#define VULKAN XXX"
int openGl; // the version of semantics for OpenGL; e.g., for GLSL from KHR_vulkan_glsl "#define GL_SPIRV" int vulkan; // the version of Vulkan, for which SPIR-V execution environment rules to use (100 means 1.0)
int openGl; // the version of GLSL semantics for OpenGL, from GL_ARB_gl_spirv, for "#define GL_SPIRV XXX"
}; };
// //
......
...@@ -110,7 +110,44 @@ typedef enum { ...@@ -110,7 +110,44 @@ typedef enum {
EShSourceNone, EShSourceNone,
EShSourceGlsl, EShSourceGlsl,
EShSourceHlsl, EShSourceHlsl,
} EShSource; // if EShLanguage were EShStage, this could be EShLanguage instead } EShSource; // if EShLanguage were EShStage, this could be EShLanguage instead
typedef enum {
EShClientNone,
EShClientVulkan,
EShClientOpenGL,
} EShClient;
typedef enum {
EShTargetNone,
EshTargetSpv,
} EShTargetLanguage;
struct TInputLanguage {
EShSource languageFamily; // redundant information with other input, this one overrides when not EShSourceNone
EShLanguage stage; // redundant information with other input, this one overrides when not EShSourceNone
EShClient dialect;
int dialectVersion; // version of client's language definition, not the client (when not EShClientNone)
};
struct TClient {
EShClient client;
int version; // version of client itself (not the client's input dialect)
};
struct TTarget {
EShTargetLanguage language;
unsigned int version; // the version to target, if SPIR-V, defined by "word 1" of the SPIR-V binary header
};
// All source/client/target versions and settings.
// Can override previous methods of setting, when items are set here.
// Expected to grow, as more are added, rather than growing parameter lists.
struct TEnvironment {
TInputLanguage input; // definition of the input language
TClient client; // what client is the overall compilation being done for?
TTarget target; // what to generate
};
const char* StageName(EShLanguage); const char* StageName(EShLanguage);
...@@ -324,6 +361,25 @@ public: ...@@ -324,6 +361,25 @@ public:
void setNoStorageFormat(bool useUnknownFormat); void setNoStorageFormat(bool useUnknownFormat);
void setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode); void setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode);
// For setting up the environment (initialized in the constructor):
void setEnvInput(EShSource lang, EShLanguage stage, EShClient client, int version)
{
environment.input.languageFamily = lang;
environment.input.stage = stage;
environment.input.dialect = client;
environment.input.dialectVersion = version;
}
void setEnvClient(EShClient client, int version)
{
environment.client.client = client;
environment.client.version = version;
}
void setEnvTarget(EShTargetLanguage lang, unsigned int version)
{
environment.target.language = lang;
environment.target.version = version;
}
// Interface to #include handlers. // Interface to #include handlers.
// //
// To support #include, a client of Glslang does the following: // To support #include, a client of Glslang does the following:
...@@ -463,6 +519,8 @@ protected: ...@@ -463,6 +519,8 @@ protected:
// a function in the source string can be renamed FROM this TO the name given in setEntryPoint. // a function in the source string can be renamed FROM this TO the name given in setEntryPoint.
std::string sourceEntryPointName; std::string sourceEntryPointName;
TEnvironment environment;
friend class TProgram; friend class TProgram;
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment