Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine shader output type #3098

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/bgfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 20 additions & 7 deletions tools/shaderc/shaderc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SPIR-V version>-<Vulkan version>
Expand Down Expand Up @@ -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[] =
Expand Down Expand Up @@ -954,7 +956,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);
Expand All @@ -965,8 +967,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
);
Expand Down Expand Up @@ -1710,7 +1713,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() )
{
Expand Down Expand Up @@ -1748,12 +1760,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());
}
}

Expand Down Expand Up @@ -1896,7 +1908,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;
}

Expand Down Expand Up @@ -1924,7 +1936,7 @@ namespace bgfx
{
if (hasFragData[ii])
{
addFragData(preprocessor, input, ii, arg++ > 0);
addFragData(preprocessor, input, ii, arg++ > 0, outputType);
}
}
else
Expand Down Expand Up @@ -2515,8 +2527,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()
);
}
}
Expand Down