D3D12: Skip patching DXBC with Aon9 chunk.

This commit is contained in:
Branimir Karadžić 2016-03-09 21:33:20 -08:00
parent f3e4d83540
commit 3afc13e521
7 changed files with 79 additions and 28 deletions

View File

@ -747,10 +747,10 @@ namespace bgfx { namespace d3d11
#if USE_D3D11_DYNAMIC_LIB #if USE_D3D11_DYNAMIC_LIB
m_d3d11dll = bx::dlopen("d3d11.dll"); m_d3d11dll = bx::dlopen("d3d11.dll");
BX_WARN(NULL != m_d3d11dll, "Failed to load d3d11.dll.");
if (NULL == m_d3d11dll) if (NULL == m_d3d11dll)
{ {
BX_TRACE("Failed to load d3d11.dll.");
goto error; goto error;
} }
@ -777,25 +777,25 @@ namespace bgfx { namespace d3d11
} }
D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)bx::dlsym(m_d3d11dll, "D3D11CreateDevice"); D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)bx::dlsym(m_d3d11dll, "D3D11CreateDevice");
BX_WARN(NULL != D3D11CreateDevice, "Function D3D11CreateDevice not found.");
if (NULL == D3D11CreateDevice) if (NULL == D3D11CreateDevice)
{ {
BX_TRACE("Function D3D11CreateDevice not found.");
goto error; goto error;
} }
m_dxgidll = bx::dlopen("dxgi.dll"); m_dxgidll = bx::dlopen("dxgi.dll");
BX_WARN(NULL != m_dxgidll, "Failed to load dxgi.dll.");
if (NULL == m_dxgidll) if (NULL == m_dxgidll)
{ {
BX_TRACE("Failed to load dxgi.dll.");
goto error; goto error;
} }
errorState = ErrorState::LoadedDXGI; errorState = ErrorState::LoadedDXGI;
CreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY)bx::dlsym(m_dxgidll, "CreateDXGIFactory"); CreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY)bx::dlsym(m_dxgidll, "CreateDXGIFactory");
BX_WARN(NULL != CreateDXGIFactory, "Function CreateDXGIFactory not found.");
if (NULL == CreateDXGIFactory) if (NULL == CreateDXGIFactory)
{ {
BX_TRACE("Function CreateDXGIFactory not found.");
goto error; goto error;
} }
@ -828,9 +828,9 @@ namespace bgfx { namespace d3d11
hr = S_OK; hr = S_OK;
factory = NULL; factory = NULL;
#endif // BX_PLATFORM_* #endif // BX_PLATFORM_*
BX_WARN(SUCCEEDED(hr), "Unable to create DXGI factory.");
if (FAILED(hr) ) if (FAILED(hr) )
{ {
BX_TRACE("Unable to create DXGI factory.");
goto error; goto error;
} }
@ -910,8 +910,10 @@ namespace bgfx { namespace d3d11
D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_10_0,
#if BX_PLATFORM_WINRT
D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_2,
#endif // BX_PLATFORM_WINRT
}; };
for (;;) for (;;)
@ -965,10 +967,10 @@ namespace bgfx { namespace d3d11
break; break;
} }
BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device.");
if (FAILED(hr) ) if (FAILED(hr) )
{ {
BX_TRACE("Unable to create Direct3D11 device.");
goto error; goto error;
} }
@ -980,10 +982,10 @@ namespace bgfx { namespace d3d11
else else
{ {
m_device->GetImmediateContext(&m_deviceCtx); m_device->GetImmediateContext(&m_deviceCtx);
BX_WARN(NULL != m_deviceCtx, "Unable to create Direct3D11 device.");
if (NULL == m_deviceCtx) if (NULL == m_deviceCtx)
{ {
BX_TRACE("Unable to create Direct3D11 device.");
goto error; goto error;
} }
} }
@ -1020,9 +1022,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
} }
} }
BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device.");
if (FAILED(hr) ) if (FAILED(hr) )
{ {
BX_TRACE("Unable to create Direct3D11 device.");
goto error; goto error;
} }
@ -1045,9 +1047,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
} }
hr = adapter->GetDesc(&m_adapterDesc); hr = adapter->GetDesc(&m_adapterDesc);
BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device.");
if (FAILED(hr) ) if (FAILED(hr) )
{ {
BX_TRACE("Unable to create Direct3D11 device.");
DX_RELEASE(adapter, 2); DX_RELEASE(adapter, 2);
goto error; goto error;
} }
@ -1062,10 +1064,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
{ {
#if !BX_PLATFORM_WINDOWS #if !BX_PLATFORM_WINDOWS
hr = adapter->GetParent(__uuidof(IDXGIFactory2), (void**)&m_factory); hr = adapter->GetParent(__uuidof(IDXGIFactory2), (void**)&m_factory);
BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device.");
DX_RELEASE(adapter, 2); DX_RELEASE(adapter, 2);
if (FAILED(hr) ) if (FAILED(hr) )
{ {
BX_TRACE("Unable to create Direct3D11 device.");
goto error; goto error;
} }
@ -1122,10 +1124,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
} }
#else #else
hr = adapter->GetParent(IID_IDXGIFactory, (void**)&m_factory); hr = adapter->GetParent(IID_IDXGIFactory, (void**)&m_factory);
BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device.");
DX_RELEASE(adapter, 2); DX_RELEASE(adapter, 2);
if (FAILED(hr) ) if (FAILED(hr) )
{ {
BX_TRACE("Unable to create Direct3D11 device.");
goto error; goto error;
} }
@ -1152,9 +1154,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
| DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_ALT_ENTER
) ); ) );
#endif // BX_PLATFORM_* #endif // BX_PLATFORM_*
BX_WARN(SUCCEEDED(hr), "Failed to create swap chain.");
if (FAILED(hr) ) if (FAILED(hr) )
{ {
BX_TRACE("Failed to create swap chain.");
goto error; goto error;
} }
} }
@ -1867,9 +1869,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
void saveScreenShot(const char* _filePath) BX_OVERRIDE void saveScreenShot(const char* _filePath) BX_OVERRIDE
{ {
BX_WARN(NULL != m_swapChain, "Unable to capture screenshot %s.", _filePath);
if (NULL == m_swapChain) if (NULL == m_swapChain)
{ {
BX_TRACE("Unable to capture screenshot %s.", _filePath);
return; return;
} }
@ -5722,8 +5724,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
tvm.clear(); tvm.clear();
uint16_t pos = 0; uint16_t pos = 0;
tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f
, " %s / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " " , " %s (FL %d.%d) / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " "
, getRendererName() , getRendererName()
, (m_featureLevel >> 12) & 0xf
, (m_featureLevel >> 8) & 0xf
); );
const DXGI_ADAPTER_DESC& desc = m_adapterDesc; const DXGI_ADAPTER_DESC& desc = m_adapterDesc;

View File

@ -457,7 +457,11 @@ namespace bgfx { namespace d3d12
struct RendererContextD3D12 : public RendererContextI struct RendererContextD3D12 : public RendererContextI
{ {
RendererContextD3D12() RendererContextD3D12()
: m_wireframe(false) : m_d3d12dll(NULL)
, m_dxgidll(NULL)
, m_renderdocdll(NULL)
, m_featureLevel(D3D_FEATURE_LEVEL(0) )
, m_wireframe(false)
, m_maxAnisotropy(1) , m_maxAnisotropy(1)
, m_depthClamp(false) , m_depthClamp(false)
, m_fsChanges(0) , m_fsChanges(0)
@ -660,12 +664,13 @@ namespace bgfx { namespace d3d12
, (featureLevel[ii] >> 12) & 0xf , (featureLevel[ii] >> 12) & 0xf
, (featureLevel[ii] >> 8) & 0xf , (featureLevel[ii] >> 8) & 0xf
); );
m_featureLevel = featureLevel[ii];
} }
BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D12 device.");
} }
if (FAILED(hr) ) if (FAILED(hr) )
{ {
BX_TRACE("Unable to create Direct3D12 device.");
goto error; goto error;
} }
@ -2261,8 +2266,9 @@ data.NumQualityLevels = 0;
bx::Error err; bx::Error err;
read(&rd, dxbc, &err); read(&rd, dxbc, &err);
bool patchShader = true; bool patchShader = !dxbc.shader.aon9;
if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) if (BX_ENABLED(BGFX_CONFIG_DEBUG)
&& patchShader)
{ {
union { uint32_t offset; void* ptr; } cast = { 0 }; union { uint32_t offset; void* ptr; } cast = { 0 };
filter(dxbc.shader, dxbc.shader, patchCb0, cast.ptr); filter(dxbc.shader, dxbc.shader, patchCb0, cast.ptr);
@ -2307,6 +2313,11 @@ data.NumQualityLevels = 0;
desc.PS.pShaderBytecode = temp->data; desc.PS.pShaderBytecode = temp->data;
desc.PS.BytecodeLength = temp->size; desc.PS.BytecodeLength = temp->size;
} }
else
{
desc.PS.pShaderBytecode = program.m_fsh->m_code->data;
desc.PS.BytecodeLength = program.m_fsh->m_code->size;
}
desc.DS.pShaderBytecode = NULL; desc.DS.pShaderBytecode = NULL;
desc.DS.BytecodeLength = 0; desc.DS.BytecodeLength = 0;
@ -2643,6 +2654,9 @@ data.NumQualityLevels = 0;
void* m_kernel32dll; void* m_kernel32dll;
void* m_d3d12dll; void* m_d3d12dll;
void* m_dxgidll; void* m_dxgidll;
void* m_renderdocdll;
D3D_FEATURE_LEVEL m_featureLevel;
D3D_DRIVER_TYPE m_driverType; D3D_DRIVER_TYPE m_driverType;
DXGI_ADAPTER_DESC m_adapterDesc; DXGI_ADAPTER_DESC m_adapterDesc;
@ -5273,8 +5287,10 @@ data.NumQualityLevels = 0;
tvm.clear(); tvm.clear();
uint16_t pos = 0; uint16_t pos = 0;
tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f
, " %s / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " " , " %s (FL %d.%d) / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " "
, getRendererName() , getRendererName()
, (m_featureLevel >> 12) & 0xf
, (m_featureLevel >> 8) & 0xf
); );
const DXGI_ADAPTER_DESC& desc = m_adapterDesc; const DXGI_ADAPTER_DESC& desc = m_adapterDesc;

View File

@ -741,7 +741,7 @@ namespace bgfx
_fn(instruction, _userData); _fn(instruction, _userData);
write(&writer, instruction); write(&writer, instruction, _err);
token += instruction.length; token += instruction.length;
} }

View File

@ -187,6 +187,8 @@ namespace bgfx
struct Dx9bcSubOperand struct Dx9bcSubOperand
{ {
Dx9bcSubOperand() { /* not pod */ }
Dx9bcOperandType::Enum type; Dx9bcOperandType::Enum type;
uint32_t regIndex; uint32_t regIndex;
uint8_t swizzleBits; uint8_t swizzleBits;
@ -194,6 +196,8 @@ namespace bgfx
struct Dx9bcOperand struct Dx9bcOperand
{ {
Dx9bcOperand() { /* not pod */ }
Dx9bcOperandType::Enum type; Dx9bcOperandType::Enum type;
uint32_t regIndex; uint32_t regIndex;
@ -214,6 +218,8 @@ namespace bgfx
struct Dx9bcInstruction struct Dx9bcInstruction
{ {
Dx9bcInstruction() { /* not pod */ }
Dx9bcOpcode::Enum opcode; Dx9bcOpcode::Enum opcode;
uint16_t length; uint16_t length;
uint8_t numOperands; uint8_t numOperands;
@ -232,6 +238,8 @@ namespace bgfx
struct Dx9bcShader struct Dx9bcShader
{ {
Dx9bcShader() { /* not pod */ }
stl::vector<uint8_t> byteCode; stl::vector<uint8_t> byteCode;
}; };
@ -240,6 +248,8 @@ namespace bgfx
struct Dx9bc struct Dx9bc
{ {
Dx9bc() { /* not pod */ }
uint32_t version; uint32_t version;
Dx9bcShader shader; Dx9bcShader shader;
}; };

View File

@ -790,7 +790,7 @@ namespace bgfx
case DxbcOperandAddrMode::Reg: case DxbcOperandAddrMode::Reg:
{ {
DxbcSubOperand subOperand; DxbcSubOperand subOperand;
size += read(_reader, subOperand); size += read(_reader, subOperand, _err);
} }
break; break;
@ -799,7 +799,7 @@ namespace bgfx
size += bx::read(_reader, _subOperand.regIndex, _err); size += bx::read(_reader, _subOperand.regIndex, _err);
DxbcSubOperand subOperand; DxbcSubOperand subOperand;
size += read(_reader, subOperand); size += read(_reader, subOperand, _err);
} }
break; break;
@ -809,7 +809,7 @@ namespace bgfx
size += bx::read(_reader, _subOperand.regIndex, _err); size += bx::read(_reader, _subOperand.regIndex, _err);
DxbcSubOperand subOperand; DxbcSubOperand subOperand;
size += read(_reader, subOperand); size += read(_reader, subOperand, _err);
} }
break; break;
@ -843,7 +843,7 @@ namespace bgfx
case DxbcOperandAddrMode::Reg: case DxbcOperandAddrMode::Reg:
{ {
DxbcSubOperand subOperand; DxbcSubOperand subOperand;
size += write(_writer, subOperand); size += write(_writer, subOperand, _err);
} }
break; break;
@ -852,7 +852,7 @@ namespace bgfx
size += bx::write(_writer, _subOperand.regIndex, _err); size += bx::write(_writer, _subOperand.regIndex, _err);
DxbcSubOperand subOperand; DxbcSubOperand subOperand;
size += write(_writer, subOperand); size += write(_writer, subOperand, _err);
} }
break; break;
@ -862,7 +862,7 @@ namespace bgfx
size += bx::write(_writer, _subOperand.regIndex, _err); size += bx::write(_writer, _subOperand.regIndex, _err);
DxbcSubOperand subOperand; DxbcSubOperand subOperand;
size += write(_writer, subOperand); size += write(_writer, subOperand, _err);
} }
break; break;
@ -1747,6 +1747,7 @@ namespace bgfx
int32_t size = 0; int32_t size = 0;
size += bx::read(_reader, _dxbc.header, _err); size += bx::read(_reader, _dxbc.header, _err);
_dxbc.shader.shex = false; _dxbc.shader.shex = false;
_dxbc.shader.aon9 = false;
for (uint32_t ii = 0; ii < _dxbc.header.numChunks; ++ii) for (uint32_t ii = 0; ii < _dxbc.header.numChunks; ++ii)
{ {
@ -1785,6 +1786,9 @@ namespace bgfx
break; break;
case BX_MAKEFOURCC('A', 'o', 'n', '9'): // Contains DX9BC for feature level 9.x (*s_4_0_level_9_*) shaders. case BX_MAKEFOURCC('A', 'o', 'n', '9'): // Contains DX9BC for feature level 9.x (*s_4_0_level_9_*) shaders.
_dxbc.shader.aon9 = true;
break;
case BX_MAKEFOURCC('I', 'F', 'C', 'E'): // Interface. case BX_MAKEFOURCC('I', 'F', 'C', 'E'): // Interface.
case BX_MAKEFOURCC('R', 'D', 'E', 'F'): // Resource definition. case BX_MAKEFOURCC('R', 'D', 'E', 'F'): // Resource definition.
case BX_MAKEFOURCC('S', 'D', 'G', 'B'): // Shader debugging info (old). case BX_MAKEFOURCC('S', 'D', 'G', 'B'): // Shader debugging info (old).

View File

@ -448,6 +448,8 @@ namespace bgfx
struct DxbcSubOperand struct DxbcSubOperand
{ {
DxbcSubOperand() { /* not pod */ }
DxbcOperandType::Enum type; DxbcOperandType::Enum type;
uint8_t mode; uint8_t mode;
uint8_t modeBits; uint8_t modeBits;
@ -459,6 +461,8 @@ namespace bgfx
struct DxbcOperand struct DxbcOperand
{ {
DxbcOperand() { /* not pod */ }
DxbcOperandType::Enum type; DxbcOperandType::Enum type;
DxbcOperandMode::Enum mode; DxbcOperandMode::Enum mode;
uint8_t modeBits; uint8_t modeBits;
@ -480,6 +484,8 @@ namespace bgfx
struct DxbcInstruction struct DxbcInstruction
{ {
DxbcInstruction() { /* not pod */ }
struct ExtendedType struct ExtendedType
{ {
enum Enum enum Enum
@ -546,6 +552,8 @@ namespace bgfx
struct DxbcSignature struct DxbcSignature
{ {
DxbcSignature() { /* not pod */ }
struct Element struct Element
{ {
stl::string name; stl::string name;
@ -570,6 +578,7 @@ namespace bgfx
uint32_t version; uint32_t version;
stl::vector<uint8_t> byteCode; stl::vector<uint8_t> byteCode;
bool shex; bool shex;
bool aon9;
}; };
int32_t read(bx::ReaderSeekerI* _reader, DxbcShader& _shader, bx::Error* _err); int32_t read(bx::ReaderSeekerI* _reader, DxbcShader& _shader, bx::Error* _err);

View File

@ -524,6 +524,8 @@ namespace bgfx
struct SpvOperand struct SpvOperand
{ {
SpvOperand() { /* not pod */ }
enum Enum enum Enum
{ {
AccessQualifier, AccessQualifier,
@ -575,6 +577,8 @@ namespace bgfx
struct SpvInstruction struct SpvInstruction
{ {
SpvInstruction() { /* not pod */ }
SpvOpcode::Enum opcode; SpvOpcode::Enum opcode;
uint16_t length; uint16_t length;
uint16_t numOperands; uint16_t numOperands;
@ -593,6 +597,8 @@ namespace bgfx
struct SpvShader struct SpvShader
{ {
SpvShader() { /* not pod */ }
stl::vector<uint8_t> byteCode; stl::vector<uint8_t> byteCode;
}; };
@ -607,6 +613,8 @@ namespace bgfx
struct SpirV struct SpirV
{ {
SpirV() { /* not pod */ }
struct Header struct Header
{ {
uint32_t magic; uint32_t magic;