This commit is contained in:
Branimir Karadžić 2015-08-20 12:30:59 -07:00
parent fb15c69b31
commit 63f3bd1ea2
5 changed files with 98 additions and 86 deletions

View File

@ -497,7 +497,18 @@ namespace bgfx { namespace d3d11
bool init()
{
uint32_t errorState = 0;
struct ErrorState
{
enum Enum
{
Default,
LoadedD3D11,
LoadedDXGI,
CreatedDXGIFactory,
};
};
ErrorState::Enum errorState = ErrorState::Default;
// Must be before device creation, and before RenderDoc.
m_ovr.init();
@ -520,7 +531,7 @@ namespace bgfx { namespace d3d11
goto error;
}
errorState = 1;
errorState = ErrorState::LoadedD3D11;
m_d3d9dll = NULL;
@ -556,7 +567,7 @@ namespace bgfx { namespace d3d11
goto error;
}
errorState = 2;
errorState = ErrorState::LoadedDXGI;
CreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY)bx::dlsym(m_dxgidll, "CreateDXGIFactory");
BX_WARN(NULL != CreateDXGIFactory, "Function CreateDXGIFactory not found.");
@ -597,7 +608,7 @@ namespace bgfx { namespace d3d11
goto error;
}
errorState = 3;
errorState = ErrorState::CreatedDXGIFactory;
m_device = (ID3D11Device*)g_platformData.context;
@ -664,7 +675,7 @@ namespace bgfx { namespace d3d11
}
DX_RELEASE(factory, NULL != m_adapter ? 1 : 0);
D3D_FEATURE_LEVEL features[] =
D3D_FEATURE_LEVEL featureLevel[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
@ -691,13 +702,17 @@ namespace bgfx { namespace d3d11
, m_driverType
, NULL
, flags
, &features[ii]
, BX_COUNTOF(features)-ii
, &featureLevel[ii]
, BX_COUNTOF(featureLevel)-ii
, D3D11_SDK_VERSION
, &m_device
, &m_featureLevel
, &m_deviceCtx
);
BX_WARN(FAILED(hr), "Direct3D11 device feature level %d.%d."
, (m_featureLevel >> 12) & 0xf
, (m_featureLevel >> 8) & 0xf
);
if (FAILED(hr)
&& 0 != (flags & D3D11_CREATE_DEVICE_DEBUG) )
{
@ -729,8 +744,6 @@ namespace bgfx { namespace d3d11
goto error;
}
errorState = 4;
if (NULL != m_adapter)
{
DX_RELEASE(m_adapter, 2);
@ -745,8 +758,6 @@ namespace bgfx { namespace d3d11
{
goto error;
}
errorState = 4;
}
{
@ -886,8 +897,6 @@ BX_PRAGMA_DIAGNOSTIC_POP();
{
goto error;
}
errorState = 5;
}
else
{
@ -1172,18 +1181,13 @@ BX_PRAGMA_DIAGNOSTIC_POP();
error:
switch (errorState)
{
default:
case 5:
case ErrorState::CreatedDXGIFactory:
DX_RELEASE(m_swapChain, 0);
case 4:
DX_RELEASE(m_deviceCtx, 0);
DX_RELEASE(m_device, 0);
case 3:
DX_RELEASE(m_factory, 0);
case 2:
case ErrorState::LoadedDXGI:
#if USE_D3D11_DYNAMIC_LIB
if (NULL != m_dxgidebugdll)
{
@ -1201,13 +1205,13 @@ BX_PRAGMA_DIAGNOSTIC_POP();
m_dxgidll = NULL;
#endif // USE_D3D11_DYNAMIC_LIB
case 1:
case ErrorState::LoadedD3D11:
#if USE_D3D11_DYNAMIC_LIB
bx::dlclose(m_d3d11dll);
m_d3d11dll = NULL;
#endif // USE_D3D11_DYNAMIC_LIB
case 0:
case ErrorState::Default:
unloadRenderDoc(m_renderdocdll);
m_ovr.shutdown();
break;
@ -2724,8 +2728,8 @@ BX_PRAGMA_DIAGNOSTIC_POP();
}
break;
CASE_IMPLEMENT_UNIFORM(Int1, I, int);
CASE_IMPLEMENT_UNIFORM(Vec4, F, float);
CASE_IMPLEMENT_UNIFORM(Int1, I, int);
CASE_IMPLEMENT_UNIFORM(Vec4, F, float);
CASE_IMPLEMENT_UNIFORM(Mat4, F, float);
case UniformType::End:
@ -2735,9 +2739,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _constantBuffer.getPos(), opcode, type, loc, num, copy);
break;
}
#undef CASE_IMPLEMENT_UNIFORM
}
}

View File

@ -461,7 +461,20 @@ namespace bgfx { namespace d3d12
bool init()
{
uint32_t errorState = 0;
struct ErrorState
{
enum Enum
{
Default,
LoadedKernel32,
LoadedD3D12,
LoadedDXGI,
CreatedDXGIFactory,
CreatedCommandQueue,
};
};
ErrorState::Enum errorState = ErrorState::Default;
LUID luid;
m_fbh.idx = invalidHandle;
@ -483,7 +496,7 @@ namespace bgfx { namespace d3d12
goto error;
}
errorState = 1;
errorState = ErrorState::LoadedKernel32;
m_d3d12dll = bx::dlopen("d3d12.dll");
BX_WARN(NULL != m_d3d12dll, "Failed to load d3d12.dll.");
@ -492,7 +505,7 @@ namespace bgfx { namespace d3d12
goto error;
}
errorState = 2;
errorState = ErrorState::LoadedD3D12;
D3D12CreateDevice = (PFN_D3D12_CREATE_DEVICE)bx::dlsym(m_d3d12dll, "D3D12CreateDevice");
BX_WARN(NULL != D3D12CreateDevice, "Function D3D12CreateDevice not found.");
@ -518,8 +531,6 @@ namespace bgfx { namespace d3d12
goto error;
}
errorState = 3;
CreateDXGIFactory1 = (PFN_CREATE_DXGI_FACTORY)bx::dlsym(m_dxgidll, "CreateDXGIFactory1");
BX_WARN(NULL != CreateDXGIFactory1, "Function CreateDXGIFactory1 not found.");
@ -527,10 +538,10 @@ namespace bgfx { namespace d3d12
{
goto error;
}
#else
errorState = 4;
#endif // USE_D3D12_DYNAMIC_LIB
errorState = ErrorState::LoadedDXGI;
HRESULT hr;
hr = CreateDXGIFactory1(IID_IDXGIFactory4, (void**)&m_factory);
@ -541,7 +552,7 @@ namespace bgfx { namespace d3d12
goto error;
}
errorState = 4;
errorState = ErrorState::CreatedDXGIFactory;
m_adapter = NULL;
m_driverType = D3D_DRIVER_TYPE_HARDWARE;
@ -608,7 +619,7 @@ namespace bgfx { namespace d3d12
}
{
static D3D_FEATURE_LEVEL featureLevel[] =
D3D_FEATURE_LEVEL featureLevel[] =
{
D3D_FEATURE_LEVEL_12_1,
D3D_FEATURE_LEVEL_12_0,
@ -616,16 +627,6 @@ namespace bgfx { namespace d3d12
D3D_FEATURE_LEVEL_11_0,
};
const char* featureLevelName[] =
{
"12.1",
"12.0",
"11.1",
"11.0",
};
BX_STATIC_ASSERT(BX_COUNTOF(featureLevel) == BX_COUNTOF(featureLevelName) );
BX_UNUSED(featureLevelName);
hr = E_FAIL;
for (uint32_t ii = 0; ii < BX_COUNTOF(featureLevel) && FAILED(hr); ++ii)
{
@ -634,7 +635,10 @@ namespace bgfx { namespace d3d12
, IID_ID3D12Device
, (void**)&m_device
);
BX_WARN(FAILED(hr), "Direct3D12 device feature level %s.", featureLevelName[ii]);
BX_WARN(FAILED(hr), "Direct3D12 device feature level %d.%d."
, (featureLevel[ii] >> 12) & 0xf
, (featureLevel[ii] >> 8) & 0xf
);
}
BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D12 device.");
}
@ -644,8 +648,6 @@ namespace bgfx { namespace d3d12
goto error;
}
errorState = 5;
{
memset(&m_adapterDesc, 0, sizeof(m_adapterDesc) );
luid = m_device->GetAdapterLuid();
@ -703,6 +705,7 @@ namespace bgfx { namespace d3d12
BX_TRACE("\tResourceHeapTier %d", m_options.ResourceHeapTier);
m_cmd.init(m_device);
errorState = ErrorState::CreatedCommandQueue;
m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH;
m_scd.BufferDesc.Height = BGFX_DEFAULT_HEIGHT;
@ -916,7 +919,7 @@ namespace bgfx { namespace d3d12
// | BGFX_CAPS_SWAP_CHAIN
);
g_caps.maxTextureSize = 16384;
g_caps.maxFBAttachments = bx::uint32_min(16, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS);
g_caps.maxFBAttachments = uint8_t(bx::uint32_min(16, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) );
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
{
@ -1031,22 +1034,21 @@ namespace bgfx { namespace d3d12
error:
switch (errorState)
{
default:
case 5:
case ErrorState::CreatedCommandQueue:
m_cmd.shutdown();
DX_RELEASE(m_device, 0);
case 4:
case ErrorState::CreatedDXGIFactory:
DX_RELEASE(m_device, 0);
DX_RELEASE(m_adapter, 0);
DX_RELEASE(m_factory, 0);
#if USE_D3D12_DYNAMIC_LIB
case 3:
case ErrorState::LoadedDXGI:
bx::dlclose(m_dxgidll);
case 2:
case ErrorState::LoadedD3D12:
bx::dlclose(m_d3d12dll);
case 1:
case ErrorState::LoadedKernel32:
bx::dlclose(m_kernel32dll);
#endif // USE_D3D12_DYNAMIC_LIB
case 0:
case ErrorState::Default:
break;
}
@ -1688,7 +1690,7 @@ data.NumQualityLevels = 0;
}
}
void setShaderUniform(uint8_t _flags, uint16_t _regIndex, const void* _val, uint16_t _numRegs)
void setShaderUniform(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
{
if (_flags&BGFX_UNIFORM_FRAGMENTBIT)
{
@ -1702,12 +1704,12 @@ data.NumQualityLevels = 0;
}
}
void setShaderUniform4f(uint8_t _flags, uint16_t _regIndex, const void* _val, uint16_t _numRegs)
void setShaderUniform4f(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
{
setShaderUniform(_flags, _regIndex, _val, _numRegs);
}
void setShaderUniform4x4f(uint8_t _flags, uint16_t _regIndex, const void* _val, uint16_t _numRegs)
void setShaderUniform4x4f(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
{
setShaderUniform(_flags, _regIndex, _val, _numRegs);
}
@ -1852,7 +1854,7 @@ data.NumQualityLevels = 0;
drt->BlendOpAlpha = s_blendEquation[equA];
}
uint32_t writeMask = (_state & BGFX_STATE_ALPHA_WRITE)
uint8_t writeMask = (_state & BGFX_STATE_ALPHA_WRITE)
? D3D12_COLOR_WRITE_ENABLE_ALPHA
: 0
;
@ -2329,11 +2331,11 @@ data.NumQualityLevels = 0;
case UniformType::_uniform: \
case UniformType::_uniform|BGFX_UNIFORM_FRAGMENTBIT: \
{ \
setShaderUniform(type, loc, data, num); \
setShaderUniform(uint8_t(type), loc, data, num); \
} \
break;
switch ( (int32_t)type)
switch ( (uint32_t)type)
{
case UniformType::Mat3:
case UniformType::Mat3|BGFX_UNIFORM_FRAGMENTBIT:
@ -2354,7 +2356,7 @@ data.NumQualityLevels = 0;
mtx.un.val[ 9] = value[7];
mtx.un.val[10] = value[8];
mtx.un.val[11] = 0.0f;
setShaderUniform(type, loc, &mtx.un.val[0], 3);
setShaderUniform(uint8_t(type), loc, &mtx.un.val[0], 3);
}
}
break;
@ -2742,7 +2744,7 @@ data.NumQualityLevels = 0;
m_gpuHandle.ptr += m_incrementSize;
}
void DescriptorAllocator::create(D3D12_DESCRIPTOR_HEAP_TYPE _type, uint32_t _maxDescriptors, uint16_t _numDescriptorsPerBlock)
void DescriptorAllocator::create(D3D12_DESCRIPTOR_HEAP_TYPE _type, uint16_t _maxDescriptors, uint16_t _numDescriptorsPerBlock)
{
m_handleAlloc = bx::createHandleAlloc(g_allocator, _maxDescriptors);
m_numDescriptorsPerBlock = _numDescriptorsPerBlock;
@ -3202,7 +3204,7 @@ data.NumQualityLevels = 0;
kind = "predefined";
m_predefined[m_numPredefined].m_loc = regIndex;
m_predefined[m_numPredefined].m_count = regCount;
m_predefined[m_numPredefined].m_type = predefined|fragmentBit;
m_predefined[m_numPredefined].m_type = uint8_t(predefined|fragmentBit);
m_numPredefined++;
}
else
@ -3282,7 +3284,7 @@ data.NumQualityLevels = 0;
if (imageParse(imageContainer, _mem->data, _mem->size) )
{
uint8_t numMips = imageContainer.m_numMips;
const uint32_t startLod = bx::uint32_min(_skip, numMips-1);
const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) );
numMips -= startLod;
const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) );
const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod);
@ -3316,7 +3318,7 @@ data.NumQualityLevels = 0;
}
m_numMips = numMips;
const uint32_t numSides = imageContainer.m_cubeMap ? 6 : 1;
const uint16_t numSides = imageContainer.m_cubeMap ? 6 : 1;
uint32_t numSrd = numMips*numSides;
D3D12_SUBRESOURCE_DATA* srd = (D3D12_SUBRESOURCE_DATA*)alloca(numSrd*sizeof(D3D12_SUBRESOURCE_DATA) );
@ -3359,7 +3361,7 @@ data.NumQualityLevels = 0;
uint32_t height = textureHeight;
uint32_t depth = imageContainer.m_depth;
for (uint32_t lod = 0; lod < numMips; ++lod)
for (uint8_t lod = 0; lod < numMips; ++lod)
{
width = bx::uint32_max(blockWidth, width);
height = bx::uint32_max(blockHeight, height);
@ -4306,7 +4308,7 @@ data.NumQualityLevels = 0;
, draw.m_stencil
, declIdx
, programIdx
, draw.m_instanceDataStride/16
, uint8_t(draw.m_instanceDataStride/16)
);
if (pso != currentPso)
{

View File

@ -103,7 +103,7 @@ namespace bgfx { namespace d3d12
{
}
void create(D3D12_DESCRIPTOR_HEAP_TYPE _type, uint32_t _maxDescriptors, uint16_t _numDescriptorsPerBlock = 1);
void create(D3D12_DESCRIPTOR_HEAP_TYPE _type, uint16_t _maxDescriptors, uint16_t _numDescriptorsPerBlock = 1);
void destroy();
uint16_t alloc(ID3D12Resource* _ptr, const D3D12_SHADER_RESOURCE_VIEW_DESC* _desc);

View File

@ -293,7 +293,18 @@ namespace bgfx { namespace d3d9
bool init()
{
uint32_t errorState = 0;
struct ErrorState
{
enum Enum
{
Default,
LoadedD3D9,
CreatedD3D9,
CreatedDevice,
};
};
ErrorState::Enum errorState = ErrorState::Default;
m_fbh.idx = invalidHandle;
memset(m_uniforms, 0, sizeof(m_uniforms) );
@ -332,7 +343,7 @@ namespace bgfx { namespace d3d9
goto error;
}
errorState = 1;
errorState = ErrorState::LoadedD3D9;
if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
{
@ -378,7 +389,7 @@ namespace bgfx { namespace d3d9
goto error;
}
errorState = 2;
errorState = ErrorState::CreatedD3D9;
{
m_adapter = D3DADAPTER_DEFAULT;
@ -473,7 +484,7 @@ namespace bgfx { namespace d3d9
goto error;
}
errorState = 3;
errorState = ErrorState::CreatedDevice;
m_numWindows = 1;
@ -680,9 +691,7 @@ namespace bgfx { namespace d3d9
error:
switch (errorState)
{
default:
case 3:
case ErrorState::CreatedDevice:
#if BGFX_CONFIG_RENDERER_DIRECT3D9EX
if (NULL != m_d3d9ex)
{
@ -695,7 +704,7 @@ namespace bgfx { namespace d3d9
DX_RELEASE(m_device, 0);
}
case 2:
case ErrorState::CreatedD3D9:
#if BGFX_CONFIG_RENDERER_DIRECT3D9EX
if (NULL != m_d3d9ex)
{
@ -709,11 +718,11 @@ namespace bgfx { namespace d3d9
}
#if BX_PLATFORM_WINDOWS
case 1:
case ErrorState::LoadedD3D9:
bx::dlclose(m_d3d9dll);
#endif // BX_PLATFORM_WINDOWS
case 0:
case ErrorState::Default:
break;
}
@ -1621,7 +1630,6 @@ namespace bgfx { namespace d3d9
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _constantBuffer.getPos(), opcode, type, loc, num, copy);
break;
}
#undef CASE_IMPLEMENT_UNIFORM
}
}

View File

@ -2699,10 +2699,10 @@ namespace bgfx { namespace gl
// }
// break;
CASE_IMPLEMENT_UNIFORM(Int1, 1iv, I, int);
CASE_IMPLEMENT_UNIFORM(Vec4, 4fv, F, float);
CASE_IMPLEMENT_UNIFORM_T(Mat3, Matrix3fv, F, float);
CASE_IMPLEMENT_UNIFORM_T(Mat4, Matrix4fv, F, float);
CASE_IMPLEMENT_UNIFORM(Int1, 1iv, I, int);
CASE_IMPLEMENT_UNIFORM(Vec4, 4fv, F, float);
CASE_IMPLEMENT_UNIFORM_T(Mat3, Matrix3fv, F, float);
CASE_IMPLEMENT_UNIFORM_T(Mat4, Matrix4fv, F, float);
case UniformType::End:
break;