Spirv compiler fixes

This commit is contained in:
Brian Harris 2017-03-24 15:20:38 -05:00
parent 38226cf2c5
commit c2d62c44ee
1 changed files with 21 additions and 17 deletions

View File

@ -539,10 +539,9 @@ namespace bgfx { namespace spirv
{
case 'c': return EShLangCompute;
case 'f': return EShLangFragment;
default: break;
case 'v': return EShLangVertex;
default: return EShLangCount;
}
return EShLangVertex;
}
// static void printError(spv_message_level_t, const char*, const spv_position_t&, const char* _message)
@ -554,10 +553,10 @@ namespace bgfx { namespace spirv
{
BX_UNUSED(_cmdLine, _version, _code, _writer);
const char* profile = _cmdLine.findOption('p', "profile");
if (NULL == profile)
const char* type = _cmdLine.findOption('\0', "type");
if (NULL == type)
{
fprintf(stderr, "Error: Shader profile must be specified.\n");
fprintf(stderr, "Error: Shader type must be specified.\n");
return false;
}
@ -565,7 +564,12 @@ namespace bgfx { namespace spirv
glslang::TProgram* program = new glslang::TProgram;
EShLanguage stage = getLang(profile[0]);
EShLanguage stage = getLang(type[0]);
if (EShLangCount == stage)
{
fprintf(stderr, "Error: Unknown shader type %s.\n", type);
return false;
}
glslang::TShader* shader = new glslang::TShader(stage);
EShMessages messages = EShMessages(0
@ -575,14 +579,12 @@ namespace bgfx { namespace spirv
| EShMsgSpvRules
);
const char* shaderStrings[] = { _code.c_str() };
const char* shaderNames[] = { "" };
shader->setEntryPoint("main");
shader->setStringsWithLengthsAndNames(
const char* shaderStrings[] = { _code.c_str() };
shader->setStrings(
shaderStrings
, NULL
, shaderNames
, BX_COUNTOF(shaderNames)
, BX_COUNTOF(shaderStrings)
);
bool compiled = shader->parse(&resourceLimits
, 110
@ -651,7 +653,7 @@ namespace bgfx { namespace spirv
uint16_t count = (uint16_t)program->getNumLiveUniformVariables();
bx::write(_writer, count);
uint32_t fragmentBit = profile[0] == 'p' ? BGFX_UNIFORM_FRAGMENTBIT : 0;
uint32_t fragmentBit = type[0] == 'f' ? BGFX_UNIFORM_FRAGMENTBIT : 0;
for (uint16_t ii = 0; ii < count; ++ii)
{
Uniform un;
@ -681,8 +683,7 @@ namespace bgfx { namespace spirv
uint8_t nameSize = (uint8_t)un.name.size();
bx::write(_writer, nameSize);
bx::write(_writer, un.name.c_str(), nameSize);
uint8_t type = uint8_t(un.type | fragmentBit);
bx::write(_writer, type);
bx::write(_writer, uint8_t(un.type | fragmentBit));
bx::write(_writer, un.num);
bx::write(_writer, un.regIndex);
bx::write(_writer, un.regCount);
@ -696,7 +697,10 @@ namespace bgfx { namespace spirv
);
}
}
program->dumpReflection();
if (g_verbose)
{
program->dumpReflection();
}
BX_UNUSED(spv::MemorySemanticsAllMemory);