shaderc: Added in/out hash. Fixed shader binary backward compatibility.

This commit is contained in:
Branimir Karadžić
2018-10-12 16:41:26 -07:00
parent 1ba107d156
commit 623fd3cf0b
10 changed files with 220 additions and 115 deletions

View File

@@ -3841,22 +3841,21 @@ namespace bgfx { namespace d3d11
uint32_t magic;
bx::read(&reader, magic);
switch (magic)
const bool fragment = isShaderType(magic, 'F');
uint32_t hashIn;
bx::read(&reader, hashIn);
uint32_t hashOut;
if (isShaderVerLess(magic, 6) )
{
case BGFX_CHUNK_MAGIC_CSH:
case BGFX_CHUNK_MAGIC_FSH:
case BGFX_CHUNK_MAGIC_VSH:
break;
default:
BGFX_FATAL(false, Fatal::InvalidShader, "Unknown shader format %x.", magic);
break;
hashOut = hashIn;
}
else
{
bx::read(&reader, hashOut);
}
bool fragment = BGFX_CHUNK_MAGIC_FSH == magic;
uint32_t iohash;
bx::read(&reader, iohash);
uint16_t count;
bx::read(&reader, count);
@@ -3865,11 +3864,11 @@ namespace bgfx { namespace d3d11
m_numUniforms = count;
BX_TRACE("%s Shader consts %d"
, BGFX_CHUNK_MAGIC_FSH == magic ? "Fragment" : BGFX_CHUNK_MAGIC_VSH == magic ? "Vertex" : "Compute"
, getShaderTypeName(magic)
, count
);
uint8_t fragmentBit = fragment ? BGFX_UNIFORM_FRAGMENTBIT : 0;
const uint8_t fragmentBit = fragment ? BGFX_UNIFORM_FRAGMENTBIT : 0;
if (0 < count)
{
@@ -3949,13 +3948,13 @@ namespace bgfx { namespace d3d11
const void* code = reader.getDataPtr();
bx::skip(&reader, shaderSize+1);
if (BGFX_CHUNK_MAGIC_FSH == magic)
if (isShaderType(magic, 'F') )
{
m_hasDepthOp = hasDepthOp(code, shaderSize);
DX_CHECK(s_renderD3D11->m_device->CreatePixelShader(code, shaderSize, NULL, &m_pixelShader) );
BGFX_FATAL(NULL != m_ptr, bgfx::Fatal::InvalidShader, "Failed to create fragment shader.");
}
else if (BGFX_CHUNK_MAGIC_VSH == magic)
else if (isShaderType(magic, 'V') )
{
m_hash = bx::hash<bx::HashMurmur2A>(code, shaderSize);
m_code = copy(code, shaderSize);
@@ -3963,7 +3962,7 @@ namespace bgfx { namespace d3d11
DX_CHECK(s_renderD3D11->m_device->CreateVertexShader(code, shaderSize, NULL, &m_vertexShader) );
BGFX_FATAL(NULL != m_ptr, bgfx::Fatal::InvalidShader, "Failed to create vertex shader.");
}
else
else if (isShaderType(magic, 'C') )
{
DX_CHECK(s_renderD3D11->m_device->CreateComputeShader(code, shaderSize, NULL, &m_computeShader) );
BGFX_FATAL(NULL != m_ptr, bgfx::Fatal::InvalidShader, "Failed to create compute shader.");