Branimir Karadžić 10 anni fa
parent
commit
63f3bd1ea2
5 ha cambiato i file con 98 aggiunte e 86 eliminazioni
  1. 28 26
      src/renderer_d3d11.cpp
  2. 46 44
      src/renderer_d3d12.cpp
  3. 1 1
      src/renderer_d3d12.h
  4. 19 11
      src/renderer_d3d9.cpp
  5. 4 4
      src/renderer_gl.cpp

+ 28 - 26
src/renderer_d3d11.cpp

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

+ 46 - 44
src/renderer_d3d12.cpp

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

+ 1 - 1
src/renderer_d3d12.h

@@ -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();
 		void destroy();
 
 
 		uint16_t alloc(ID3D12Resource* _ptr, const D3D12_SHADER_RESOURCE_VIEW_DESC* _desc);
 		uint16_t alloc(ID3D12Resource* _ptr, const D3D12_SHADER_RESOURCE_VIEW_DESC* _desc);

+ 19 - 11
src/renderer_d3d9.cpp

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

+ 4 - 4
src/renderer_gl.cpp

@@ -2699,10 +2699,10 @@ namespace bgfx { namespace gl
 //					}
 //					}
 //					break;
 //					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:
 				case UniformType::End:
 					break;
 					break;