mirror of https://github.com/bkaradzic/bgfx
shaderc: Added support for gl_VertexID/InstanceID. Issue #1062.
This commit is contained in:
parent
aba8438683
commit
3d73d0904b
Binary file not shown.
Binary file not shown.
|
@ -940,6 +940,13 @@ namespace bgfx { namespace gl
|
|||
NULL
|
||||
};
|
||||
|
||||
static const char* s_EXT_gpu_shader4[] =
|
||||
{
|
||||
"gl_VertexID",
|
||||
"gl_InstanceID",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char* s_ARB_gpu_shader5[] =
|
||||
{
|
||||
"bitfieldReverse",
|
||||
|
@ -5602,6 +5609,7 @@ namespace bgfx { namespace gl
|
|||
&& s_extension[Extension::ARB_shader_texture_lod].m_supported
|
||||
&& bx::findIdentifierMatch(code, s_ARB_shader_texture_lod)
|
||||
;
|
||||
const bool usesGpuShader4 = !!bx::findIdentifierMatch(code, s_EXT_gpu_shader4);
|
||||
const bool usesGpuShader5 = !!bx::findIdentifierMatch(code, s_ARB_gpu_shader5);
|
||||
const bool usesIUsamplers = !!bx::findIdentifierMatch(code, s_uisamplers);
|
||||
const bool usesTexelFetch = !!bx::findIdentifierMatch(code, s_texelFetch);
|
||||
|
@ -5610,7 +5618,7 @@ namespace bgfx { namespace gl
|
|||
const bool usesPacking = !!bx::findIdentifierMatch(code, s_ARB_shading_language_packing);
|
||||
|
||||
uint32_t version =
|
||||
usesIUsamplers || usesTexelFetch || usesGpuShader5 ? 130
|
||||
usesIUsamplers|| usesTexelFetch || usesGpuShader5 ? 130
|
||||
: usesTextureLod ? 120
|
||||
: 120
|
||||
;
|
||||
|
@ -5633,6 +5641,11 @@ namespace bgfx { namespace gl
|
|||
}
|
||||
}
|
||||
|
||||
if (usesGpuShader4)
|
||||
{
|
||||
writeString(&writer, "#extension GL_EXT_gpu_shader4 : enable\n");
|
||||
}
|
||||
|
||||
if (usesGpuShader5)
|
||||
{
|
||||
writeString(&writer, "#extension GL_ARB_gpu_shader5 : enable\n");
|
||||
|
|
|
@ -78,6 +78,13 @@ namespace bgfx
|
|||
NULL
|
||||
};
|
||||
|
||||
static const char* s_EXT_gpu_shader4[] =
|
||||
{
|
||||
"gl_VertexID",
|
||||
"gl_InstanceID",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char* s_ARB_gpu_shader5[] =
|
||||
{
|
||||
"bitfieldReverse",
|
||||
|
@ -1671,7 +1678,7 @@ namespace bgfx
|
|||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "PrimitiveID builtin is not supported by this D3D9 HLSL.\n");
|
||||
fprintf(stderr, "gl_PrimitiveID builtin is not supported by this D3D9 HLSL.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -1698,6 +1705,9 @@ namespace bgfx
|
|||
}
|
||||
else if ('v' == shaderType)
|
||||
{
|
||||
const bool hasVertexId = NULL != bx::strFind(input, "gl_VertexID");
|
||||
const bool hasInstanceId = NULL != bx::strFind(input, "gl_InstanceID");
|
||||
|
||||
const char* brace = bx::strFind(entry, "{");
|
||||
if (NULL != brace)
|
||||
{
|
||||
|
@ -1730,17 +1740,55 @@ namespace bgfx
|
|||
|
||||
preprocessor.writef("#define void_main() \\\n");
|
||||
preprocessor.writef("Output main(");
|
||||
bool first = true;
|
||||
uint32_t arg = 0;
|
||||
for (InOut::const_iterator it = shaderInputs.begin(), itEnd = shaderInputs.end(); it != itEnd; ++it)
|
||||
{
|
||||
VaryingMap::const_iterator varyingIt = varyingMap.find(*it);
|
||||
if (varyingIt != varyingMap.end() )
|
||||
{
|
||||
const Varying& var = varyingIt->second;
|
||||
preprocessor.writef("%s%s %s : %s\\\n", first ? "" : "\t, ", var.m_type.c_str(), var.m_name.c_str(), var.m_semantics.c_str() );
|
||||
first = false;
|
||||
preprocessor.writef(
|
||||
" \\\n\t%s%s %s : %s"
|
||||
, arg++ > 0 ? ", " : ""
|
||||
, var.m_type.c_str()
|
||||
, var.m_name.c_str()
|
||||
, var.m_semantics.c_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasVertexId)
|
||||
{
|
||||
if (d3d > 9)
|
||||
{
|
||||
preprocessor.writef(
|
||||
" \\\n\t%suint gl_VertexID : SV_VertexID"
|
||||
, arg++ > 0 ? ", " : " "
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "gl_VertexID builtin is not supported by this D3D9 HLSL.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasInstanceId)
|
||||
{
|
||||
if (d3d > 9)
|
||||
{
|
||||
preprocessor.writef(
|
||||
" \\\n\t%suint gl_InstanceID : SV_InstanceID"
|
||||
, arg++ > 0 ? ", " : " "
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "gl_InstanceID builtin is not supported by this D3D9 HLSL.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
preprocessor.writef(
|
||||
") \\\n"
|
||||
"{ \\\n"
|
||||
|
@ -1857,6 +1905,8 @@ namespace bgfx
|
|||
|| !!bx::findIdentifierMatch(input, s_ARB_shader_texture_lod)
|
||||
|| !!bx::findIdentifierMatch(input, s_EXT_shader_texture_lod)
|
||||
;
|
||||
const bool usesInstanceID = !!bx::strFind(input, "gl_InstanceID");
|
||||
const bool usesGpuShader4 = !!bx::findIdentifierMatch(input, s_EXT_gpu_shader4);
|
||||
const bool usesGpuShader5 = !!bx::findIdentifierMatch(input, s_ARB_gpu_shader5);
|
||||
const bool usesTexelFetch = !!bx::findIdentifierMatch(input, s_texelFetch);
|
||||
const bool usesTextureMS = !!bx::findIdentifierMatch(input, s_ARB_texture_multisample);
|
||||
|
@ -1880,6 +1930,20 @@ namespace bgfx
|
|||
glsl = 130;
|
||||
}
|
||||
|
||||
if (usesInstanceID)
|
||||
{
|
||||
bx::stringPrintf(code
|
||||
, "#extension GL_ARB_draw_instanced : enable\n"
|
||||
);
|
||||
}
|
||||
|
||||
if (usesGpuShader4)
|
||||
{
|
||||
bx::stringPrintf(code
|
||||
, "#extension GL_EXT_gpu_shader4 : enable\n"
|
||||
);
|
||||
}
|
||||
|
||||
if (usesGpuShader5)
|
||||
{
|
||||
bx::stringPrintf(code
|
||||
|
|
|
@ -475,6 +475,8 @@ namespace bgfx { namespace spirv
|
|||
return true;
|
||||
}
|
||||
|
||||
#define DBG(...)
|
||||
|
||||
void disassemble(bx::WriterI* _writer, bx::ReaderSeekerI* _reader, bx::Error* _err)
|
||||
{
|
||||
BX_UNUSED(_writer);
|
||||
|
@ -497,24 +499,25 @@ namespace bgfx { namespace spirv
|
|||
if (0 < num
|
||||
&& 0 != bx::strCmp(id.var.name.c_str(), "gl_PerVertex") )
|
||||
{
|
||||
printf("%3d: %s %d %s\n"
|
||||
DBG("%3d: %s %d %s\n"
|
||||
, it->first
|
||||
, id.var.name.c_str()
|
||||
, id.var.location
|
||||
, getName(id.var.storageClass)
|
||||
);
|
||||
printf("{\n");
|
||||
DBG("{\n");
|
||||
for (uint32_t ii = 0; ii < num; ++ii)
|
||||
{
|
||||
const SpvReflection::Id::Variable& var = id.members[ii];
|
||||
printf("\t\t%s %s %d %s\n"
|
||||
DBG("\t\t%s %s %d %s\n"
|
||||
, spvx.getTypeName(var.type).c_str()
|
||||
, var.name.c_str()
|
||||
, var.offset
|
||||
, getName(var.storageClass)
|
||||
);
|
||||
BX_UNUSED(var);
|
||||
}
|
||||
printf("}\n");
|
||||
DBG("}\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue