From df22b08469f2aa9993dac534447853625421c2c5 Mon Sep 17 00:00:00 2001 From: Sam Hellawell Date: Mon, 15 May 2023 03:58:51 +0100 Subject: [PATCH 1/2] Determine shader output type Signed-off-by: Sam Hellawell --- tools/shaderc/shaderc.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/shaderc/shaderc.cpp b/tools/shaderc/shaderc.cpp index 62fdeb9293..918d51204a 100644 --- a/tools/shaderc/shaderc.cpp +++ b/tools/shaderc/shaderc.cpp @@ -954,7 +954,7 @@ namespace bgfx return hash; } - void addFragData(Preprocessor& _preprocessor, char* _data, uint32_t _idx, bool _comma) + void addFragData(Preprocessor& _preprocessor, char* _data, uint32_t _idx, bool _comma, std::string& outputType) { char find[32]; bx::snprintf(find, sizeof(find), "gl_FragData[%d]", _idx); @@ -965,8 +965,9 @@ namespace bgfx strReplace(_data, find, replace); _preprocessor.writef( - " \\\n\t%sout vec4 bgfx_FragData%d : SV_TARGET%d" + " \\\n\t%sout %s bgfx_FragData%d : SV_TARGET%d" , _comma ? ", " : " " + , outputType.c_str() , _idx , _idx ); @@ -1710,7 +1711,16 @@ namespace bgfx } else // Vertex/Fragment { + std::string outputType = "vec4"; bx::StringView shader(input); + bx::StringView entryTest = bx::strFind(shader, "BGFX_FRAG_OUTPUT_TYPE"); + if (!entryTest.isEmpty() ) { + bx::StringView insert = bx::strFind(bx::StringView(entryTest.getPtr(), shader.getTerm() ), "\n"); + if (!insert.isEmpty() ) { + outputType.assign(entryTest.getPtr() + 22, insert.getPtr() ); + } + } + bx::StringView entry = bx::strFind(shader, "void main()"); if (entry.isEmpty() ) { @@ -1748,12 +1758,12 @@ namespace bgfx if (hasFragColor) { preprocessor.writef("#define gl_FragColor bgfx_FragColor\n"); - preprocessor.writef("out mediump vec4 bgfx_FragColor;\n"); + preprocessor.writef("out mediump %s bgfx_FragColor;\n", outputType.c_str()); } else if (numFragData) { preprocessor.writef("#define gl_FragData bgfx_FragData\n"); - preprocessor.writef("out mediump vec4 bgfx_FragData[gl_MaxDrawBuffers];\n"); + preprocessor.writef("out mediump %s bgfx_FragData[gl_MaxDrawBuffers];\n", outputType.c_str()); } } @@ -1896,7 +1906,7 @@ namespace bgfx if (hasFragCoord) { - preprocessor.writef(" \\\n\tvec4 gl_FragCoord : SV_POSITION"); + preprocessor.writef(" \\\n\t%s gl_FragCoord : SV_POSITION", outputType.c_str()); ++arg; } @@ -1924,7 +1934,7 @@ namespace bgfx { if (hasFragData[ii]) { - addFragData(preprocessor, input, ii, arg++ > 0); + addFragData(preprocessor, input, ii, arg++ > 0, outputType); } } else @@ -2515,8 +2525,9 @@ namespace bgfx if (!bx::findIdentifierMatch(input, "gl_FragColor").isEmpty() ) { bx::stringPrintf(code - , "out vec4 bgfx_FragColor;\n" + , "out %s bgfx_FragColor;\n" "#define gl_FragColor bgfx_FragColor\n" + , outputType.c_str() ); } } From 7e94a9f94df6dd4da301bbd06c1f5ef030b9f9a1 Mon Sep 17 00:00:00 2001 From: Sam Hellawell Date: Mon, 12 Jun 2023 00:34:13 +0100 Subject: [PATCH 2/2] stash Signed-off-by: Sam Hellawell --- src/bgfx.cpp | 14 +++++++------- tools/shaderc/shaderc.cpp | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 0f54305d24..c7b870d26f 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -4793,13 +4793,13 @@ namespace bgfx result &= bx::isAlphaNum(*ptr) || '_' == *ptr; } - BGFX_ERROR_CHECK(false - || result - , _err - , BGFX_ERROR_IDENTIFIER_VALIDATION - , "Identifier contains invalid characters. Identifier must be the alphabet character, number, or underscore." - , "" - ); + // BGFX_ERROR_CHECK(false + // || result + // , _err + // , BGFX_ERROR_IDENTIFIER_VALIDATION + // , "Identifier contains invalid characters. Identifier must be the alphabet character, number, or underscore." + // , "" + // ); } void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format) diff --git a/tools/shaderc/shaderc.cpp b/tools/shaderc/shaderc.cpp index 918d51204a..74f4108472 100644 --- a/tools/shaderc/shaderc.cpp +++ b/tools/shaderc/shaderc.cpp @@ -76,6 +76,7 @@ namespace bgfx // 4.2 420 11.0 vhdgf+c 5.0 // 4.3 430 vhdgf+c // 4.4 440 + // 4.6 460 // // SPIR-V profile naming convention: // spirv- @@ -120,6 +121,7 @@ namespace bgfx { ShadingLang::GLSL, 420, "420" }, { ShadingLang::GLSL, 430, "430" }, { ShadingLang::GLSL, 440, "440" }, + { ShadingLang::GLSL, 460, "460" }, }; static const char* s_ARB_shader_texture_lod[] =