diff --git a/Test/nonVulkan.frag b/Test/nonVulkan.frag index c8cf46747..425e8402d 100644 --- a/Test/nonVulkan.frag +++ b/Test/nonVulkan.frag @@ -2,4 +2,8 @@ layout(constant_id = 17) const int arraySize = 12; // ERROR layout(input_attachment_index = 1) int foo; // ERROR -layout(push_constant) uniform ubn { int a; } ubi; // ERROR \ No newline at end of file +layout(push_constant) uniform ubn { int a; } ubi; // ERROR + +#ifdef VULKAN +#error VULKAN should not be defined +#endif diff --git a/Test/vulkan.vert b/Test/vulkan.vert index ad33a53b4..b234c75bb 100644 --- a/Test/vulkan.vert +++ b/Test/vulkan.vert @@ -37,3 +37,11 @@ void foo() } layout(set = 1, push_constant) uniform badpc { int a; } badpcI; // ERROR, no descriptor set with push_constant + +#ifndef VULKAN +#error VULKAN should be defined +#endif + +#if VULKAN != 100 +#error VULKAN should be 100 +#endif diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index 6034f1ab0..5fd6f4218 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -629,7 +629,9 @@ bool ProcessDeferred( parseContext->initializeExtensionBehavior(); // Fill in the strings as outlined above. - strings[0] = parseContext->getPreamble(); + std::string preamble; + parseContext->getPreamble(preamble); + strings[0] = preamble.c_str(); lengths[0] = strlen(strings[0]); names[0] = nullptr; strings[1] = customPreamble; diff --git a/glslang/MachineIndependent/Versions.cpp b/glslang/MachineIndependent/Versions.cpp index 019caf9b1..911535af0 100644 --- a/glslang/MachineIndependent/Versions.cpp +++ b/glslang/MachineIndependent/Versions.cpp @@ -215,10 +215,10 @@ void TParseVersions::initializeExtensionBehavior() // Get code that is not part of a shared symbol table, is specific to this shader, // or needed by the preprocessor (which does not use a shared symbol table). -const char* TParseVersions::getPreamble() +void TParseVersions::getPreamble(std::string& preamble) { if (profile == EEsProfile) { - return + preamble = "#define GL_ES 1\n" "#define GL_FRAGMENT_PRECISION_HIGH 1\n" "#define GL_OES_texture_3D 1\n" @@ -227,10 +227,6 @@ const char* TParseVersions::getPreamble() "#define GL_OES_EGL_image_external 1\n" "#define GL_EXT_shader_texture_lod 1\n" - // #line and #include - "#define GL_GOOGLE_cpp_style_line_directive 1\n" - "#define GL_GOOGLE_include_directive 1\n" - // AEP "#define GL_ANDROID_extension_pack_es31a 1\n" "#define GL_KHR_blend_equation_advanced 1\n" @@ -260,7 +256,7 @@ const char* TParseVersions::getPreamble() "#define GL_OES_texture_cube_map_array 1\n" ; } else { - return + preamble = "#define GL_FRAGMENT_PRECISION_HIGH 1\n" "#define GL_ARB_texture_rectangle 1\n" "#define GL_ARB_shading_language_420pack 1\n" @@ -283,12 +279,18 @@ const char* TParseVersions::getPreamble() "#define GL_ARB_gl_spirv 1\n" "#define GL_ARB_sparse_texture2 1\n" "#define GL_ARB_sparse_texture_clamp 1\n" - - "#define GL_GOOGLE_cpp_style_line_directive 1\n" - "#define GL_GOOGLE_include_directive 1\n" // "#define GL_ARB_cull_distance 1\n" // present for 4.5, but need extension control over block members ; } + + // #line and #include + preamble += + "#define GL_GOOGLE_cpp_style_line_directive 1\n" + "#define GL_GOOGLE_include_directive 1\n" + ; + + if (vulkan > 0) + preamble += "#define VULKAN 100\n"; } // diff --git a/glslang/MachineIndependent/parseVersions.h b/glslang/MachineIndependent/parseVersions.h index 13d768059..0eebb10ae 100755 --- a/glslang/MachineIndependent/parseVersions.h +++ b/glslang/MachineIndependent/parseVersions.h @@ -104,7 +104,7 @@ public: void setCurrentSourceName(const char* name) { currentScanner->setFile(name); } void setCurrentString(int string) { currentScanner->setString(string); } - const char* getPreamble(); + void getPreamble(std::string&); bool relaxedErrors() const { return (messages & EShMsgRelaxedErrors) != 0; } bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; } diff --git a/hlsl/hlslParseHelper.h b/hlsl/hlslParseHelper.h index 88a3fe2fe..661fd97bb 100755 --- a/hlsl/hlslParseHelper.h +++ b/hlsl/hlslParseHelper.h @@ -48,7 +48,7 @@ public: virtual ~HlslParseContext(); void setLimits(const TBuiltInResource&); bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false); - const char* getPreamble(); + void getPreamble(std::string&); void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken, const char* szExtraInfoFormat, ...);