From b9f9ec56f566a3fbfa879664b0d2887b714bdcf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=A3=8E?= Date: Mon, 29 Jan 2018 13:31:34 +0800 Subject: [PATCH 1/3] Add BX_FALLTHROUGH to avoid -Wimplicit-fallthrough false positives (#1322) --- src/bgfx.cpp | 1 + src/renderer_d3d11.cpp | 3 +++ src/renderer_d3d12.cpp | 5 +++++ src/renderer_d3d9.cpp | 3 +++ src/renderer_d3d9.h | 1 + src/renderer_vk.cpp | 8 ++++++++ 6 files changed, 21 insertions(+) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 610ddf9d1..136d341c9 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -2844,6 +2844,7 @@ error: case ErrorState::ContextAllocated: BX_ALIGNED_DELETE(g_allocator, s_ctx, 64); s_ctx = NULL; + BX_FALLTHROUGH; case ErrorState::Default: if (NULL != s_callbackStub) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index eb4e15267..066a38efe 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1870,6 +1870,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); DX_RELEASE(m_deviceCtx, 0); DX_RELEASE(m_device, 0); DX_RELEASE(m_factory, 0); + BX_FALLTHROUGH; #if USE_D3D11_DYNAMIC_LIB case ErrorState::LoadedDXGI: @@ -1887,10 +1888,12 @@ BX_PRAGMA_DIAGNOSTIC_POP(); bx::dlclose(m_dxgidll); m_dxgidll = NULL; + BX_FALLTHROUGH; case ErrorState::LoadedD3D11: bx::dlclose(m_d3d11dll); m_d3d11dll = NULL; + BX_FALLTHROUGH; #endif // USE_D3D11_DYNAMIC_LIB case ErrorState::Default: diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 4b4973992..0281236f4 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -1448,17 +1448,22 @@ namespace bgfx { namespace d3d12 { case ErrorState::CreatedCommandQueue: m_cmd.shutdown(); + BX_FALLTHROUGH; case ErrorState::CreatedDXGIFactory: DX_RELEASE(m_device, 0); DX_RELEASE(m_adapter, 0); DX_RELEASE(m_factory, 0); + BX_FALLTHROUGH; #if USE_D3D12_DYNAMIC_LIB case ErrorState::LoadedDXGI: bx::dlclose(m_dxgidll); + BX_FALLTHROUGH; case ErrorState::LoadedD3D12: bx::dlclose(m_d3d12dll); + BX_FALLTHROUGH; case ErrorState::LoadedKernel32: bx::dlclose(m_kernel32dll); + BX_FALLTHROUGH; #endif // USE_D3D12_DYNAMIC_LIB case ErrorState::Default: default: diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index f2726eca0..9fb3b4c62 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -869,6 +869,7 @@ namespace bgfx { namespace d3d9 { DX_RELEASE(m_device, 0); } + BX_FALLTHROUGH; case ErrorState::CreatedD3D9: if (NULL != m_d3d9ex) @@ -880,10 +881,12 @@ namespace bgfx { namespace d3d9 { DX_RELEASE(m_d3d9, 0); } + BX_FALLTHROUGH; case ErrorState::LoadedD3D9: m_nvapi.shutdown(); bx::dlclose(m_d3d9dll); + BX_FALLTHROUGH; case ErrorState::Default: break; diff --git a/src/renderer_d3d9.h b/src/renderer_d3d9.h index 235a6ea19..22228604d 100644 --- a/src/renderer_d3d9.h +++ b/src/renderer_d3d9.h @@ -241,6 +241,7 @@ namespace bgfx { namespace d3d9 switch (m_type) { case 0: DX_RELEASE(m_vertexShader, 0); + BX_FALLTHROUGH; default: DX_RELEASE(m_pixelShader, 0); } } diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index 5d0529798..b0de96e9b 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -1766,11 +1766,13 @@ VK_IMPORT_DEVICE vkDestroy(m_pipelineLayout); vkDestroy(m_descriptorSetLayout); vkDestroy(m_descriptorPool); + BX_FALLTHROUGH; case ErrorState::CommandBuffersCreated: vkFreeCommandBuffers(m_device, m_commandPool, BX_COUNTOF(m_commandBuffers), m_commandBuffers); vkDestroy(m_commandPool); vkDestroy(m_fence); + BX_FALLTHROUGH; case ErrorState::SwapchainCreated: for (uint32_t ii = 0; ii < BX_COUNTOF(m_backBufferColorImageView); ++ii) @@ -1791,15 +1793,19 @@ VK_IMPORT_DEVICE } } vkDestroy(m_swapchain); + BX_FALLTHROUGH; case ErrorState::SurfaceCreated: vkDestroySurfaceKHR(m_instance, m_surface, m_allocatorCb); + BX_FALLTHROUGH; case ErrorState::RenderPassCreated: vkDestroy(m_renderPass); + BX_FALLTHROUGH; case ErrorState::DeviceCreated: vkDestroyDevice(m_device, m_allocatorCb); + BX_FALLTHROUGH; case ErrorState::InstanceCreated: if (VK_NULL_HANDLE != m_debugReportCallback) @@ -1808,12 +1814,14 @@ VK_IMPORT_DEVICE } vkDestroyInstance(m_instance, m_allocatorCb); + BX_FALLTHROUGH; case ErrorState::LoadedVulkan1: bx::dlclose(m_vulkan1dll); m_vulkan1dll = NULL; m_allocatorCb = NULL; unloadRenderDoc(m_renderdocdll); + BX_FALLTHROUGH; case ErrorState::Default: break; From e5a983d25a39a60e612797bf0f89509ecfe6678a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 29 Jan 2018 21:39:17 -0800 Subject: [PATCH 2/3] Cleanup. --- src/renderer_d3d11.cpp | 1 + src/renderer_d3d12.cpp | 5 +++++ src/renderer_d3d9.h | 3 +-- src/shader_dxbc.cpp | 9 +++++---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 066a38efe..67889db96 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1894,6 +1894,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); bx::dlclose(m_d3d11dll); m_d3d11dll = NULL; BX_FALLTHROUGH; + #endif // USE_D3D11_DYNAMIC_LIB case ErrorState::Default: diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 0281236f4..47f62071e 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -1449,21 +1449,26 @@ namespace bgfx { namespace d3d12 case ErrorState::CreatedCommandQueue: m_cmd.shutdown(); BX_FALLTHROUGH; + case ErrorState::CreatedDXGIFactory: DX_RELEASE(m_device, 0); DX_RELEASE(m_adapter, 0); DX_RELEASE(m_factory, 0); BX_FALLTHROUGH; + #if USE_D3D12_DYNAMIC_LIB case ErrorState::LoadedDXGI: bx::dlclose(m_dxgidll); BX_FALLTHROUGH; + case ErrorState::LoadedD3D12: bx::dlclose(m_d3d12dll); BX_FALLTHROUGH; + case ErrorState::LoadedKernel32: bx::dlclose(m_kernel32dll); BX_FALLTHROUGH; + #endif // USE_D3D12_DYNAMIC_LIB case ErrorState::Default: default: diff --git a/src/renderer_d3d9.h b/src/renderer_d3d9.h index 22228604d..b9321403e 100644 --- a/src/renderer_d3d9.h +++ b/src/renderer_d3d9.h @@ -240,8 +240,7 @@ namespace bgfx { namespace d3d9 switch (m_type) { - case 0: DX_RELEASE(m_vertexShader, 0); - BX_FALLTHROUGH; + case 0: DX_RELEASE(m_vertexShader, 0); BX_FALLTHROUGH; default: DX_RELEASE(m_pixelShader, 0); } } diff --git a/src/shader_dxbc.cpp b/src/shader_dxbc.cpp index 1575d4cf3..d5895f319 100644 --- a/src/shader_dxbc.cpp +++ b/src/shader_dxbc.cpp @@ -1912,6 +1912,8 @@ namespace bgfx bx::MemoryBlock mb(g_allocator); bx::MemoryWriter writer(&mb); + int32_t total = 0; + for (uint32_t token = 0, numTokens = uint32_t(_src.byteCode.size() / sizeof(uint32_t) ); token < numTokens;) { DxbcInstruction instruction; @@ -1920,15 +1922,14 @@ namespace bgfx _fn(instruction, _userData); - write(&writer, instruction, _err); + total += write(&writer, instruction, _err); token += instruction.length; } uint8_t* data = (uint8_t*)mb.more(); - uint32_t size = uint32_t(bx::getSize(&writer) ); - _dst.byteCode.reserve(size); - bx::memCopy(_dst.byteCode.data(), data, size); + _dst.byteCode.resize(total); + bx::memCopy(_dst.byteCode.data(), data, total); } } // namespace bgfx From 5b37b39155dd0073754aafccce42e32c614341ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 29 Jan 2018 21:53:52 -0800 Subject: [PATCH 3/3] Fixed GCC7 warnings. --- src/shader_dxbc.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/shader_dxbc.h b/src/shader_dxbc.h index 56b16f08d..5ff5d2610 100644 --- a/src/shader_dxbc.h +++ b/src/shader_dxbc.h @@ -450,7 +450,16 @@ namespace bgfx struct DxbcSubOperand { - DxbcSubOperand() { /* not pod */ } + DxbcSubOperand() + : type(DxbcOperandType::Temp) + , mode(0) + , modeBits(0) + , num(0) + , numAddrModes(0) + , addrMode(0) + , regIndex(0) + { + } DxbcOperandType::Enum type; uint8_t mode; @@ -463,7 +472,19 @@ namespace bgfx struct DxbcOperand { - DxbcOperand() { /* not pod */ } + DxbcOperand() + : type(DxbcOperandType::Temp) + , mode(DxbcOperandMode::Mask) + , modeBits(0) + , num(0) + , extended(false) + , extBits(0) + , numAddrModes(0) + { + bx::memSet(addrMode, 0, sizeof(addrMode) ); + bx::memSet(regIndex, 0, sizeof(regIndex) ); + bx::memSet(un.imm64, 0, sizeof(un.imm64) ); + } DxbcOperandType::Enum type; DxbcOperandMode::Enum mode;