From c900424d660f9917f820bb2b84ec4689bdff70d7 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Fri, 7 Mar 2025 14:51:25 +0200 Subject: [PATCH] [d3d9] More or less minor static analysis nits --- src/d3d9/d3d9_bridge.cpp | 19 +++++------- src/d3d9/d3d9_common_texture.cpp | 3 +- src/d3d9/d3d9_device.cpp | 6 ++-- src/d3d9/d3d9_fixed_function.cpp | 46 +++++++++++++++--------------- src/d3d9/d3d9_format.cpp | 2 +- src/d3d9/d3d9_shader.h | 3 +- src/d3d9/d3d9_shader_validator.cpp | 2 +- src/d3d9/d3d9_shader_validator.h | 2 +- src/d3d9/d3d9_state.h | 38 +++++++++++------------- src/d3d9/d3d9_stateblock.h | 8 +++--- src/d3d9/d3d9_swapchain.cpp | 9 +----- src/d3d9/d3d9_window.h | 2 +- src/dxvk/dxvk_shader_key.h | 2 +- 13 files changed, 61 insertions(+), 81 deletions(-) diff --git a/src/d3d9/d3d9_bridge.cpp b/src/d3d9/d3d9_bridge.cpp index 6464fecdd..d801c56ab 100644 --- a/src/d3d9/d3d9_bridge.cpp +++ b/src/d3d9/d3d9_bridge.cpp @@ -64,20 +64,15 @@ namespace dxvk { D3D9CommonTexture* srcTextureInfo = src->GetCommonTexture(); D3D9CommonTexture* dstTextureInfo = dst->GetCommonTexture(); - VkOffset3D srcOffset = { 0u, 0u, 0u }; - VkOffset3D dstOffset = { 0u, 0u, 0u }; - VkExtent3D texLevelExtent = srcTextureInfo->GetExtentMip(src->GetSubresource()); - VkExtent3D extent = texLevelExtent; + VkOffset3D srcOffset = { pSrcRect->left, + pSrcRect->top, + 0u }; - srcOffset = { pSrcRect->left, - pSrcRect->top, - 0u }; + VkExtent3D extent = { uint32_t(pSrcRect->right - pSrcRect->left), uint32_t(pSrcRect->bottom - pSrcRect->top), 1 }; - extent = { uint32_t(pSrcRect->right - pSrcRect->left), uint32_t(pSrcRect->bottom - pSrcRect->top), 1 }; - - dstOffset = { pDestPoint->x, - pDestPoint->y, - 0u }; + VkOffset3D dstOffset = { pDestPoint->x, + pDestPoint->y, + 0u }; m_device->UpdateTextureFromBuffer( srcTextureInfo, dstTextureInfo, diff --git a/src/d3d9/d3d9_common_texture.cpp b/src/d3d9/d3d9_common_texture.cpp index ec410a5a1..f9fecd437 100644 --- a/src/d3d9/d3d9_common_texture.cpp +++ b/src/d3d9/d3d9_common_texture.cpp @@ -357,7 +357,6 @@ namespace dxvk { imageInfo.sharing.mode = (*pSharedHandle == INVALID_HANDLE_VALUE || *pSharedHandle == nullptr) ? DxvkSharedHandleMode::Export : DxvkSharedHandleMode::Import; - imageInfo.sharing.type = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT; imageInfo.sharing.handle = *pSharedHandle; imageInfo.shared = true; // TODO: validate metadata? @@ -556,7 +555,7 @@ namespace dxvk { return VK_IMAGE_LAYOUT_GENERAL; // Otherwise, pick a layout that can be used for reading. - return Usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT + return (Usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; } diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index b181f0c60..dd5f4f399 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -4831,7 +4831,7 @@ namespace dxvk { // which need to be block aligned, must be validated for mip level 0. if (MipLevel == 0 && isBlockAlignedFormat && (type == D3DRTYPE_VOLUMETEXTURE || - (type != D3DRTYPE_VOLUMETEXTURE && desc.Pool == D3DPOOL_DEFAULT)) + desc.Pool == D3DPOOL_DEFAULT) && (isNotLeftAligned || isNotTopAligned || isNotRightAligned || isNotBottomAligned)) return D3DERR_INVALIDCALL; @@ -6021,7 +6021,7 @@ namespace dxvk { void D3D9DeviceEx::UpdatePushConstant(const void* pData) { struct ConstantData { uint8_t Data[Length]; }; - auto* constData = reinterpret_cast(pData); + const ConstantData* constData = reinterpret_cast(pData); EmitCs([ cData = *constData @@ -7230,7 +7230,7 @@ namespace dxvk { UINT InstanceCount) { D3D9DrawInfo drawInfo; drawInfo.vertexCount = GetVertexCount(PrimitiveType, PrimitiveCount); - drawInfo.instanceCount = m_iaState.streamsInstanced & m_iaState.streamsUsed + drawInfo.instanceCount = (m_iaState.streamsInstanced & m_iaState.streamsUsed) ? InstanceCount : 1u; return drawInfo; diff --git a/src/d3d9/d3d9_fixed_function.cpp b/src/d3d9/d3d9_fixed_function.cpp index 78c5a454c..436843a3e 100644 --- a/src/d3d9/d3d9_fixed_function.cpp +++ b/src/d3d9/d3d9_fixed_function.cpp @@ -776,8 +776,8 @@ namespace dxvk { std::vector m_bindings; - uint32_t m_inputMask = 0u; - uint32_t m_outputMask = 0u; + uint32_t m_inputMask = 0u; + uint32_t m_outputMask = 0u; uint32_t m_flatShadingMask = 0u; DxsoProgramType m_programType; @@ -790,19 +790,19 @@ namespace dxvk { DxsoIsgn m_isgn; DxsoIsgn m_osgn; - uint32_t m_floatType; - uint32_t m_uint32Type; - uint32_t m_vec4Type; - uint32_t m_vec3Type; - uint32_t m_vec2Type; - uint32_t m_mat3Type; - uint32_t m_mat4Type; + uint32_t m_floatType = 0u; + uint32_t m_uint32Type = 0u; + uint32_t m_vec4Type = 0u; + uint32_t m_vec3Type = 0u; + uint32_t m_vec2Type = 0u; + uint32_t m_mat3Type = 0u; + uint32_t m_mat4Type = 0u; - uint32_t m_entryPointId; + uint32_t m_entryPointId = 0u; - uint32_t m_rsBlock; - uint32_t m_specUbo; - uint32_t m_mainFuncLabel; + uint32_t m_rsBlock = 0u; + uint32_t m_specUbo = 0u; + uint32_t m_mainFuncLabel = 0u; D3D9FixedFunctionOptions m_options; @@ -814,11 +814,11 @@ namespace dxvk { const D3D9FFShaderKeyVS& Key, const std::string& Name, D3D9FixedFunctionOptions Options) - : m_module(spvVersion(1, 3)), m_options(Options) { - m_programType = DxsoProgramTypes::VertexShader; - m_vsKey = Key; - m_filename = Name; - } + : m_filename ( Name ) + , m_module ( spvVersion(1, 3) ) + , m_programType ( DxsoProgramTypes::VertexShader ) + , m_vsKey ( Key ) + , m_options ( Options ) { } D3D9FFShaderCompiler::D3D9FFShaderCompiler( @@ -826,11 +826,11 @@ namespace dxvk { const D3D9FFShaderKeyFS& Key, const std::string& Name, D3D9FixedFunctionOptions Options) - : m_module(spvVersion(1, 3)), m_options(Options) { - m_programType = DxsoProgramTypes::PixelShader; - m_fsKey = Key; - m_filename = Name; - } + : m_filename ( Name ) + , m_module ( spvVersion(1, 3) ) + , m_programType ( DxsoProgramTypes::PixelShader ) + , m_fsKey ( Key ) + , m_options ( Options ) { } Rc D3D9FFShaderCompiler::compile() { diff --git a/src/d3d9/d3d9_format.cpp b/src/d3d9/d3d9_format.cpp index 14923e316..a3af18669 100644 --- a/src/d3d9/d3d9_format.cpp +++ b/src/d3d9/d3d9_format.cpp @@ -514,7 +514,7 @@ namespace dxvk { return D3D9_VK_FORMAT_MAPPING(); if (!m_d24s8Support && mapping.FormatColor == VK_FORMAT_D24_UNORM_S8_UINT) - mapping.FormatColor = mapping.Aspect & VK_IMAGE_ASPECT_STENCIL_BIT ? VK_FORMAT_D32_SFLOAT_S8_UINT : VK_FORMAT_D32_SFLOAT; + mapping.FormatColor = (mapping.Aspect & VK_IMAGE_ASPECT_STENCIL_BIT) ? VK_FORMAT_D32_SFLOAT_S8_UINT : VK_FORMAT_D32_SFLOAT; if (!m_d16s8Support && mapping.FormatColor == VK_FORMAT_D16_UNORM_S8_UINT) mapping.FormatColor = m_d24s8Support ? VK_FORMAT_D24_UNORM_S8_UINT : VK_FORMAT_D32_SFLOAT_S8_UINT; diff --git a/src/d3d9/d3d9_shader.h b/src/d3d9/d3d9_shader.h index a6c6af94a..e4375178c 100644 --- a/src/d3d9/d3d9_shader.h +++ b/src/d3d9/d3d9_shader.h @@ -96,9 +96,8 @@ namespace dxvk { uint32_t BytecodeLength) : D3D9DeviceChild( pDevice ) , m_shader ( CommonShader ) + , m_bytecode ( pAllocator->Alloc(BytecodeLength) ) , m_bytecodeLength ( BytecodeLength ) { - - m_bytecode = pAllocator->Alloc(BytecodeLength); m_bytecode.Map(); std::memcpy(m_bytecode.Ptr(), pShaderBytecode, BytecodeLength); m_bytecode.Unmap(); diff --git a/src/d3d9/d3d9_shader_validator.cpp b/src/d3d9/d3d9_shader_validator.cpp index 22ef78e9e..4c2cb255a 100644 --- a/src/d3d9/d3d9_shader_validator.cpp +++ b/src/d3d9/d3d9_shader_validator.cpp @@ -190,7 +190,7 @@ namespace dxvk { const DWORD* pInstr, DWORD InstrLength, D3D9ShaderValidatorMessage MessageID, - std::string Message) { + const std::string& Message) { if (m_callback) m_callback(pFile, Line, Unknown, MessageID, Message.c_str(), m_userData); diff --git a/src/d3d9/d3d9_shader_validator.h b/src/d3d9/d3d9_shader_validator.h index 47773a96b..d3d6f2487 100644 --- a/src/d3d9/d3d9_shader_validator.h +++ b/src/d3d9/d3d9_shader_validator.h @@ -89,7 +89,7 @@ namespace dxvk { const DWORD* pInstr, DWORD InstrLength, D3D9ShaderValidatorMessage MessageID, - std::string Message); + const std::string& Message); bool m_isPixelShader = false; uint32_t m_majorVersion = 0; diff --git a/src/d3d9/d3d9_state.h b/src/d3d9/d3d9_state.h index 79aa0d9d7..21cc59336 100644 --- a/src/d3d9/d3d9_state.h +++ b/src/d3d9/d3d9_state.h @@ -81,24 +81,20 @@ namespace dxvk { }; struct D3D9Light { - D3D9Light(const D3DLIGHT9& light, Matrix4 viewMtx) { - Diffuse = Vector4(light.Diffuse.r, light.Diffuse.g, light.Diffuse.b, light.Diffuse.a); - Specular = Vector4(light.Specular.r, light.Specular.g, light.Specular.b, light.Specular.a); - Ambient = Vector4(light.Ambient.r, light.Ambient.g, light.Ambient.b, light.Ambient.a); - - Position = viewMtx * Vector4(light.Position.x, light.Position.y, light.Position.z, 1.0f); - Direction = Vector4(light.Direction.x, light.Direction.y, light.Direction.z, 0.0f); - Direction = normalize(viewMtx * Direction); - - Type = light.Type; - Range = light.Range; - Falloff = light.Falloff; - Attenuation0 = light.Attenuation0; - Attenuation1 = light.Attenuation1; - Attenuation2 = light.Attenuation2; - Theta = cosf(light.Theta / 2.0f); - Phi = cosf(light.Phi / 2.0f); - } + D3D9Light(const D3DLIGHT9& light, Matrix4 viewMtx) + : Diffuse ( Vector4(light.Diffuse.r, light.Diffuse.g, light.Diffuse.b, light.Diffuse.a) ) + , Specular ( Vector4(light.Specular.r, light.Specular.g, light.Specular.b, light.Specular.a) ) + , Ambient ( Vector4(light.Ambient.r, light.Ambient.g, light.Ambient.b, light.Ambient.a) ) + , Position ( viewMtx * Vector4(light.Position.x, light.Position.y, light.Position.z, 1.0f) ) + , Direction ( normalize(viewMtx * Vector4(light.Direction.x, light.Direction.y, light.Direction.z, 0.0f)) ) + , Type ( light.Type ) + , Range ( light.Range ) + , Falloff ( light.Falloff ) + , Attenuation0 ( light.Attenuation0 ) + , Attenuation1 ( light.Attenuation1 ) + , Attenuation2 ( light.Attenuation2 ) + , Theta ( cosf(light.Theta / 2.0f) ) + , Phi ( cosf(light.Phi / 2.0f) ) { } Vector4 Diffuse; Vector4 Specular; @@ -236,8 +232,6 @@ namespace dxvk { }; struct D3D9SamplerInfo { - D3D9SamplerInfo() = default; - D3D9SamplerInfo(const std::array& state) : addressU(D3DTEXTUREADDRESS(state[D3DSAMP_ADDRESSU])) , addressV(D3DTEXTUREADDRESS(state[D3DSAMP_ADDRESSV])) @@ -309,8 +303,8 @@ namespace dxvk { std::array enabledLightIndices; bool IsLightEnabled(DWORD Index) const { - const auto& indices = enabledLightIndices; - return std::find(indices.begin(), indices.end(), Index) != indices.end(); + const auto& enabledIndices = enabledLightIndices; + return std::find(enabledIndices.begin(), enabledIndices.end(), Index) != enabledIndices.end(); } }; diff --git a/src/d3d9/d3d9_stateblock.h b/src/d3d9/d3d9_stateblock.h index 74284d4f7..05f751107 100644 --- a/src/d3d9/d3d9_stateblock.h +++ b/src/d3d9/d3d9_stateblock.h @@ -277,7 +277,7 @@ namespace dxvk { for (uint32_t consts : bit::BitMask(m_captures.vsConsts.fConsts.dword(i))) { uint32_t idx = i * 32 + consts; - dst->SetVertexShaderConstantF(idx, (float*)&src->vsConsts->fConsts[idx], 1); + dst->SetVertexShaderConstantF(idx, reinterpret_cast(&src->vsConsts->fConsts[idx]), 1); } } @@ -285,7 +285,7 @@ namespace dxvk { for (uint32_t consts : bit::BitMask(m_captures.vsConsts.iConsts.dword(i))) { uint32_t idx = i * 32 + consts; - dst->SetVertexShaderConstantI(idx, (int*)&src->vsConsts->iConsts[idx], 1); + dst->SetVertexShaderConstantI(idx, reinterpret_cast(&src->vsConsts->iConsts[idx]), 1); } } @@ -300,7 +300,7 @@ namespace dxvk { for (uint32_t consts : bit::BitMask(m_captures.psConsts.fConsts.dword(i))) { uint32_t idx = i * 32 + consts; - dst->SetPixelShaderConstantF(idx, (float*)&src->psConsts->fConsts[idx], 1); + dst->SetPixelShaderConstantF(idx, reinterpret_cast(&src->psConsts->fConsts[idx]), 1); } } @@ -308,7 +308,7 @@ namespace dxvk { for (uint32_t consts : bit::BitMask(m_captures.psConsts.iConsts.dword(i))) { uint32_t idx = i * 32 + consts; - dst->SetPixelShaderConstantI(idx, (int*)&src->psConsts->iConsts[idx], 1); + dst->SetPixelShaderConstantI(idx, reinterpret_cast(&src->psConsts->iConsts[idx]), 1); } } diff --git a/src/d3d9/d3d9_swapchain.cpp b/src/d3d9/d3d9_swapchain.cpp index e22665400..10e28fcac 100644 --- a/src/d3d9/d3d9_swapchain.cpp +++ b/src/d3d9/d3d9_swapchain.cpp @@ -13,13 +13,6 @@ namespace dxvk { return uint16_t(65535.0f * x); } - - struct D3D9PresentInfo { - float scale[2]; - float offset[2]; - }; - - D3D9SwapChainEx::D3D9SwapChainEx( D3D9DeviceEx* pDevice, D3DPRESENT_PARAMETERS* pPresentParams, @@ -745,7 +738,7 @@ namespace dxvk { m_blitter->setCursorTexture( cursorSize, VK_FORMAT_B8G8R8A8_SRGB, - (void *) pCursorBitmap); + reinterpret_cast(pCursorBitmap)); } diff --git a/src/d3d9/d3d9_window.h b/src/d3d9/d3d9_window.h index 84fcc0048..7205cace8 100644 --- a/src/d3d9/d3d9_window.h +++ b/src/d3d9/d3d9_window.h @@ -19,7 +19,7 @@ namespace dxvk { private: HWND m_window; - bool m_filter; + bool m_filter = false; }; diff --git a/src/dxvk/dxvk_shader_key.h b/src/dxvk/dxvk_shader_key.h index 4a66e5285..78d79a9d4 100644 --- a/src/dxvk/dxvk_shader_key.h +++ b/src/dxvk/dxvk_shader_key.h @@ -31,7 +31,7 @@ namespace dxvk { */ DxvkShaderKey( VkShaderStageFlagBits stage, - Sha1Hash hash) + const Sha1Hash& hash) : m_type(stage), m_sha1(hash) { } /**