mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 01:50:38 +00:00
Fix bugs identified by using PVS Studio
* A few copy-paste errors, some tautological checks indicating errors, missing return value checks.
This commit is contained in:
@@ -1040,7 +1040,7 @@ void VulkanPipelineStateViewer::addResourceRow(ShaderReflection *shaderDetails,
|
||||
arrayLength = (bindMap->arraySize == ~0U ? -1 : (int)bindMap->arraySize);
|
||||
|
||||
// for arrays, add a parent element that we add the real cbuffers below
|
||||
if(arrayLength > 1)
|
||||
if(arrayLength > 1 || arrayLength < 0)
|
||||
{
|
||||
RDTreeWidgetItem *node =
|
||||
new RDTreeWidgetItem({QString(), setname, slotname,
|
||||
@@ -1438,7 +1438,7 @@ void VulkanPipelineStateViewer::addConstantBlockRow(ShaderReflection *shaderDeta
|
||||
arrayLength = (bindMap->arraySize == ~0U ? -1 : (int)bindMap->arraySize);
|
||||
|
||||
// for arrays, add a parent element that we add the real cbuffers below
|
||||
if(arrayLength > 1)
|
||||
if(arrayLength > 1 || arrayLength < 0)
|
||||
{
|
||||
RDTreeWidgetItem *node =
|
||||
new RDTreeWidgetItem({QString(), setname, slotname,
|
||||
|
||||
@@ -935,7 +935,7 @@ void TextureViewer::UI_UpdateStatusText()
|
||||
|
||||
if(m_TexDisplay.overlay == DebugOverlay::QuadOverdrawPass ||
|
||||
m_TexDisplay.overlay == DebugOverlay::QuadOverdrawDraw ||
|
||||
m_TexDisplay.overlay == DebugOverlay::TriangleSizeDraw ||
|
||||
m_TexDisplay.overlay == DebugOverlay::TriangleSizePass ||
|
||||
m_TexDisplay.overlay == DebugOverlay::TriangleSizeDraw)
|
||||
{
|
||||
dsv = false;
|
||||
|
||||
@@ -610,7 +610,7 @@ void ImageViewer::RefreshFile()
|
||||
}
|
||||
}
|
||||
|
||||
FreeEXRImage(&exrImage);
|
||||
ret = FreeEXRImage(&exrImage);
|
||||
|
||||
// shouldn't get here but let's be safe
|
||||
if(ret != 0)
|
||||
|
||||
@@ -2609,14 +2609,6 @@ rdcarray<PixelModification> D3D11Replay::PixelHistory(rdcarray<EventUsage> event
|
||||
mod.postMod.col.floatValue[c] = float(mod.postMod.col.uintValue[c]) / maxVal;
|
||||
}
|
||||
}
|
||||
else if(fmt.compType == CompType::SNorm && fmt.compByteWidth == 2)
|
||||
{
|
||||
for(uint32_t c = 0; c < fmt.compCount; c++)
|
||||
{
|
||||
mod.preMod.col.floatValue[c] = float(mod.preMod.col.uintValue[c]);
|
||||
mod.postMod.col.floatValue[c] = float(mod.postMod.col.uintValue[c]);
|
||||
}
|
||||
}
|
||||
else if(fmt.compType == CompType::SNorm && fmt.compByteWidth == 1)
|
||||
{
|
||||
for(uint32_t c = 0; c < fmt.compCount; c++)
|
||||
|
||||
@@ -1984,9 +1984,9 @@ void D3D11Replay::GetTextureData(ResourceId tex, const Subresource &sub,
|
||||
{
|
||||
if(params.remap == RemapTexture::RGBA8)
|
||||
{
|
||||
desc.Format = GetTypedFormat(DXGI_FORMAT_R8G8B8A8_TYPELESS, params.typeCast);
|
||||
if(IsSRGBFormat(desc.Format) && params.typeCast == CompType::Typeless)
|
||||
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
|
||||
desc.Format = GetTypedFormat(DXGI_FORMAT_R8G8B8A8_TYPELESS, params.typeCast);
|
||||
}
|
||||
else if(params.remap == RemapTexture::RGBA16)
|
||||
{
|
||||
@@ -2319,9 +2319,9 @@ void D3D11Replay::GetTextureData(ResourceId tex, const Subresource &sub,
|
||||
{
|
||||
if(params.remap == RemapTexture::RGBA8)
|
||||
{
|
||||
desc.Format = GetTypedFormat(DXGI_FORMAT_R8G8B8A8_TYPELESS, params.typeCast);
|
||||
if(IsSRGBFormat(desc.Format) && params.typeCast == CompType::Typeless)
|
||||
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
|
||||
desc.Format = GetTypedFormat(DXGI_FORMAT_R8G8B8A8_TYPELESS, params.typeCast);
|
||||
}
|
||||
else if(params.remap == RemapTexture::RGBA16)
|
||||
{
|
||||
|
||||
@@ -2575,6 +2575,7 @@ void ExtractInputsPS(PSInput IN, float4 debug_pixelPos : SV_Position, uint prim
|
||||
if(FAILED(hr))
|
||||
{
|
||||
RDCERR("Failed to map stage buff HRESULT: %s", ToStr(hr).c_str());
|
||||
SAFE_DELETE_ARRAY(initialData);
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
@@ -327,6 +327,12 @@ D3D12DebugManager::D3D12DebugManager(WrappedID3D12Device *wrapper)
|
||||
__uuidof(ID3D12Resource), (void **)&m_ReadbackBuffer);
|
||||
m_pDevice->InternalRef();
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
RDCERR("Failed to create readback buffer, HRESULT: %s", ToStr(hr).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
m_ReadbackBuffer->SetName(L"m_ReadbackBuffer");
|
||||
|
||||
rm->SetInternalResource(m_ReadbackBuffer);
|
||||
@@ -725,7 +731,7 @@ D3D12_CPU_DESCRIPTOR_HANDLE D3D12DebugManager::GetTempDescriptor(const D3D12Desc
|
||||
ret = GetCPUHandle(TMP_DSV);
|
||||
|
||||
const D3D12_DEPTH_STENCIL_VIEW_DESC *dsvdesc = &desc.GetDSV();
|
||||
if(dsvdesc->ViewDimension == D3D12_RTV_DIMENSION_UNKNOWN)
|
||||
if(dsvdesc->ViewDimension == D3D12_DSV_DIMENSION_UNKNOWN)
|
||||
dsvdesc = NULL;
|
||||
|
||||
m_pDevice->CreateDepthStencilView(res, dsvdesc, ret);
|
||||
|
||||
@@ -682,7 +682,7 @@ public:
|
||||
if(iid == __uuidof(ID3D12Device) || iid == __uuidof(ID3D12Device1) ||
|
||||
iid == __uuidof(ID3D12Device2) || iid == __uuidof(ID3D12Device3) ||
|
||||
iid == __uuidof(ID3D12Device4) || iid == __uuidof(ID3D12Device5) ||
|
||||
iid == __uuidof(ID3D12Device5))
|
||||
iid == __uuidof(ID3D12Device6))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -404,7 +404,7 @@ bool WrappedID3D12Device::Serialise_CreateHeap1(SerialiserType &ser, const D3D12
|
||||
// don't replay with a protected session
|
||||
HRESULT hr = E_NOINTERFACE;
|
||||
if(m_pDevice4)
|
||||
m_pDevice4->CreateHeap1(&Descriptor, NULL, guid, &realptr);
|
||||
hr = m_pDevice4->CreateHeap1(&Descriptor, NULL, guid, &realptr);
|
||||
else
|
||||
RDCERR("Replaying a without D3D12.4 available");
|
||||
|
||||
|
||||
@@ -91,6 +91,8 @@ bool D3D12ResourceManager::Prepare_InitialState(ID3D12DeviceChild *res)
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool isUploadHeap = (heapProps.Type == D3D12_HEAP_TYPE_UPLOAD);
|
||||
|
||||
heapProps.Type = D3D12_HEAP_TYPE_READBACK;
|
||||
heapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||
heapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||
@@ -111,7 +113,6 @@ bool D3D12ResourceManager::Prepare_InitialState(ID3D12DeviceChild *res)
|
||||
RDCASSERT(states.size() == 1);
|
||||
|
||||
D3D12_RESOURCE_BARRIER barrier;
|
||||
const bool isUploadHeap = (heapProps.Type == D3D12_HEAP_TYPE_UPLOAD);
|
||||
const bool needsTransition =
|
||||
!isUploadHeap && ((states[0] & D3D12_RESOURCE_STATE_COPY_SOURCE) == 0);
|
||||
|
||||
@@ -645,9 +646,9 @@ bool D3D12ResourceManager::Serialise_InitialState(SerialiserType &ser, ResourceI
|
||||
(resDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) != 0;
|
||||
|
||||
D3D12_RESOURCE_DESC msaaDesc = resDesc;
|
||||
arrayDesc.Alignment = 0;
|
||||
arrayDesc.Flags = isDepth ? D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL
|
||||
: D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
|
||||
msaaDesc.Alignment = 0;
|
||||
msaaDesc.Flags = isDepth ? D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL
|
||||
: D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
|
||||
|
||||
ID3D12Resource *arrayTex = NULL;
|
||||
HRESULT hr = m_Device->CreateCommittedResource(
|
||||
|
||||
@@ -959,10 +959,6 @@ rdcstr DoStringise(const D3D12_HEAP_FLAGS &el)
|
||||
STRINGISE_BITFIELD_BIT(D3D12_HEAP_FLAG_SHARED_CROSS_ADAPTER);
|
||||
STRINGISE_BITFIELD_BIT(D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES);
|
||||
STRINGISE_BITFIELD_BIT(D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES);
|
||||
STRINGISE_BITFIELD_BIT(D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES);
|
||||
STRINGISE_BITFIELD_BIT(D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS);
|
||||
STRINGISE_BITFIELD_BIT(D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES);
|
||||
STRINGISE_BITFIELD_BIT(D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES);
|
||||
}
|
||||
END_BITFIELD_STRINGISE();
|
||||
}
|
||||
|
||||
@@ -2825,7 +2825,7 @@ void DoSerialise(SerialiserType &ser, DXGI_ADAPTER_DESC &el)
|
||||
|
||||
// don't serialise SIZE_T, cast to uint64_t
|
||||
{
|
||||
uint64_t DedicatedVideoMemory = el.DedicatedSystemMemory;
|
||||
uint64_t DedicatedVideoMemory = el.DedicatedVideoMemory;
|
||||
uint64_t DedicatedSystemMemory = el.DedicatedSystemMemory;
|
||||
uint64_t SharedSystemMemory = el.SharedSystemMemory;
|
||||
|
||||
@@ -2835,7 +2835,7 @@ void DoSerialise(SerialiserType &ser, DXGI_ADAPTER_DESC &el)
|
||||
|
||||
if(ser.IsReading())
|
||||
{
|
||||
el.DedicatedSystemMemory = (SIZE_T)DedicatedVideoMemory;
|
||||
el.DedicatedVideoMemory = (SIZE_T)DedicatedVideoMemory;
|
||||
el.DedicatedSystemMemory = (SIZE_T)DedicatedSystemMemory;
|
||||
el.SharedSystemMemory = (SIZE_T)SharedSystemMemory;
|
||||
}
|
||||
|
||||
@@ -713,9 +713,8 @@ HRESULT STDMETHODCALLTYPE WrappedIDXGIOutput6::DuplicateOutput1(
|
||||
if(wrapDevice)
|
||||
{
|
||||
IDXGIOutputDuplication *dup = NULL;
|
||||
HRESULT ret =
|
||||
m_pReal5->DuplicateOutput1(wrapDevice->GetRealIUnknown(), Flags, SupportedFormatsCount,
|
||||
pSupportedFormats, ppOutputDuplication);
|
||||
HRESULT ret = m_pReal5->DuplicateOutput1(wrapDevice->GetRealIUnknown(), Flags,
|
||||
SupportedFormatsCount, pSupportedFormats, &dup);
|
||||
|
||||
if(SUCCEEDED(ret) && dup)
|
||||
dup = new WrappedIDXGIOutputDuplication(wrapDevice, dup);
|
||||
|
||||
@@ -1030,9 +1030,9 @@ void GLReplay::InitDebugData()
|
||||
rdcstr versionString = version;
|
||||
|
||||
versionString += " / ";
|
||||
versionString += renderer;
|
||||
versionString += renderer ? renderer : "";
|
||||
versionString += " / ";
|
||||
versionString += vendor;
|
||||
versionString += vendor ? vendor : "";
|
||||
|
||||
versionString.resize(RDCMIN(versionString.size(), ARRAY_COUNT(m_DriverInfo.version) - 1));
|
||||
memcpy(m_DriverInfo.version, versionString.c_str(), versionString.size());
|
||||
|
||||
@@ -3607,6 +3607,7 @@ ReplayStatus CreateReplayDevice(RDCDriver rdcdriver, RDCFile *rdc, const ReplayO
|
||||
|
||||
if(!replay->HasDebugContext())
|
||||
{
|
||||
delete gldriver;
|
||||
platform.DeleteReplayContext(data);
|
||||
return ReplayStatus::APIHardwareUnsupported;
|
||||
}
|
||||
|
||||
@@ -823,7 +823,7 @@ rdcstr GetTextureCompleteStatus(GLenum target, GLuint tex, GLuint sampler)
|
||||
|
||||
rdcstr faceStr;
|
||||
rdcstr face0Str;
|
||||
if(faceCount > 0)
|
||||
if(faceCount > 1)
|
||||
{
|
||||
face0Str = StringFormat::Fmt(" of %s", ToStr(targets[0]).c_str());
|
||||
faceStr = StringFormat::Fmt(" of %s", ToStr(targets[face]).c_str());
|
||||
|
||||
@@ -2052,7 +2052,7 @@ void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &ref
|
||||
case eGL_FLOAT_MAT3x4:
|
||||
case eGL_DOUBLE_MAT3x4:
|
||||
sig.compCount = 3;
|
||||
rows = 2;
|
||||
rows = 4;
|
||||
sig.regChannelMask = 0x7;
|
||||
break;
|
||||
case eGL_FLOAT_MAT3x2:
|
||||
|
||||
@@ -307,10 +307,10 @@ bool WrappedOpenGL::Serialise_glDispatchCompute(SerialiserType &ser, GLuint num_
|
||||
MessageSource::IncorrectAPIUse,
|
||||
"Dispatch call has num_groups_x=0. This will do nothing, which is unusual "
|
||||
"for a non-indirect Dispatch. Did you mean X=1?");
|
||||
if(num_groups_x == 0)
|
||||
if(num_groups_y == 0)
|
||||
AddDebugMessage(MessageCategory::Execution, MessageSeverity::Medium,
|
||||
MessageSource::IncorrectAPIUse,
|
||||
"Dispatch call has num_groups_x=0. This will do nothing, which is unusual "
|
||||
"Dispatch call has num_groups_y=0. This will do nothing, which is unusual "
|
||||
"for a non-indirect Dispatch. Did you mean Y=1?");
|
||||
if(num_groups_z == 0)
|
||||
AddDebugMessage(MessageCategory::Execution, MessageSeverity::Medium,
|
||||
|
||||
@@ -2243,8 +2243,8 @@ bool Program::ExtractOperation(uint32_t *&tokenStream, Operation &retOp, bool fr
|
||||
retOp.operands[0].funcNum = func;
|
||||
}
|
||||
|
||||
if(op == OPCODE_IF || op == OPCODE_BREAKC || op == OPCODE_CALLC || op == OPCODE_RETC ||
|
||||
op == OPCODE_SWAPC || op == OPCODE_DMOVC || op == OPCODE_DISCARD || op == OPCODE_DMOVC)
|
||||
if(op == OPCODE_IF || op == OPCODE_BREAKC || op == OPCODE_CALLC || op == OPCODE_CONTINUEC ||
|
||||
op == OPCODE_RETC || op == OPCODE_DISCARD)
|
||||
retOp.str += retOp.nonzero ? "_nz" : "_z";
|
||||
|
||||
if(op != OPCODE_SYNC)
|
||||
|
||||
@@ -128,14 +128,14 @@ struct VkPackedVersion
|
||||
bool operator<=(uint32_t v) const { return version <= v; }
|
||||
bool operator>=(uint32_t v) const { return version >= v; }
|
||||
bool operator==(uint32_t v) const { return version == v; }
|
||||
bool operator!=(uint32_t v) const { return version == v; }
|
||||
bool operator!=(uint32_t v) const { return version != v; }
|
||||
// int overloads because VK_MAKE_VERSION is type int...
|
||||
bool operator<(int v) const { return version < (uint32_t)v; }
|
||||
bool operator>(int v) const { return version > (uint32_t)v; }
|
||||
bool operator<=(int v) const { return version <= (uint32_t)v; }
|
||||
bool operator>=(int v) const { return version >= (uint32_t)v; }
|
||||
bool operator==(int v) const { return version == (uint32_t)v; }
|
||||
bool operator!=(int v) const { return version == (uint32_t)v; }
|
||||
bool operator!=(int v) const { return version != (uint32_t)v; }
|
||||
operator uint32_t() const { return version; }
|
||||
VkPackedVersion &operator=(uint32_t v)
|
||||
{
|
||||
|
||||
@@ -1559,6 +1559,7 @@ bool WrappedVulkan::Serialise_BeginCaptureFrame(SerialiserType &ser)
|
||||
VkCommandBuffer cmd = GetNextCmd();
|
||||
|
||||
VkResult vkr = ObjDisp(cmd)->BeginCommandBuffer(Unwrap(cmd), &beginInfo);
|
||||
RDCASSERTEQUAL(vkr, VK_SUCCESS);
|
||||
|
||||
ObjDisp(cmd)->CmdPipelineBarrier(Unwrap(cmd), src_stages, dest_stages, false, 0, NULL, 0,
|
||||
NULL, 1, &imgBarriers[i]);
|
||||
@@ -1572,6 +1573,7 @@ bool WrappedVulkan::Serialise_BeginCaptureFrame(SerialiserType &ser)
|
||||
VkCommandBuffer cmd = GetNextCmd();
|
||||
|
||||
VkResult vkr = ObjDisp(cmd)->BeginCommandBuffer(Unwrap(cmd), &beginInfo);
|
||||
RDCASSERTEQUAL(vkr, VK_SUCCESS);
|
||||
|
||||
ObjDisp(cmd)->CmdPipelineBarrier(Unwrap(cmd), src_stages, dest_stages, false, 0, NULL, 0,
|
||||
NULL, (uint32_t)imgBarriers.size(), &imgBarriers[0]);
|
||||
@@ -2255,19 +2257,28 @@ ReplayStatus WrappedVulkan::ReadLogInitialisation(RDCFile *rdc, bool storeStruct
|
||||
chunkIdx++;
|
||||
|
||||
if(reader->IsErrored())
|
||||
{
|
||||
SAFE_DELETE(sink);
|
||||
return ReplayStatus::APIDataCorrupted;
|
||||
}
|
||||
|
||||
bool success = ProcessChunk(ser, context);
|
||||
|
||||
ser.EndChunk();
|
||||
|
||||
if(reader->IsErrored())
|
||||
{
|
||||
SAFE_DELETE(sink);
|
||||
return ReplayStatus::APIDataCorrupted;
|
||||
}
|
||||
|
||||
// if there wasn't a serialisation error, but the chunk didn't succeed, then it's an API replay
|
||||
// failure.
|
||||
if(!success)
|
||||
{
|
||||
SAFE_DELETE(sink);
|
||||
return m_FailedReplayStatus;
|
||||
}
|
||||
|
||||
uint64_t offsetEnd = reader->GetOffset();
|
||||
|
||||
@@ -2291,7 +2302,10 @@ ReplayStatus WrappedVulkan::ReadLogInitialisation(RDCFile *rdc, bool storeStruct
|
||||
ReplayStatus status = ContextReplayLog(m_State, 0, 0, false);
|
||||
|
||||
if(status != ReplayStatus::Succeeded)
|
||||
{
|
||||
SAFE_DELETE(sink);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
chunkInfos[context].total += timer.GetMilliseconds();
|
||||
|
||||
@@ -91,6 +91,9 @@ struct DescSetLayout
|
||||
}
|
||||
const Binding &operator=(const Binding &b)
|
||||
{
|
||||
if(this == &b)
|
||||
return *this;
|
||||
|
||||
descriptorType = b.descriptorType;
|
||||
descriptorCount = b.descriptorCount;
|
||||
stageFlags = b.stageFlags;
|
||||
|
||||
@@ -2490,6 +2490,7 @@ void VulkanReplay::FetchVSOut(uint32_t eventId)
|
||||
// readback mesh data
|
||||
byte *byteData = NULL;
|
||||
vkr = m_pDriver->vkMapMemory(m_Device, readbackMem, 0, VK_WHOLE_SIZE, 0, (void **)&byteData);
|
||||
RDCASSERTEQUAL(vkr, VK_SUCCESS);
|
||||
|
||||
VkMappedMemoryRange range = {
|
||||
VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, NULL, readbackMem, 0, VK_WHOLE_SIZE,
|
||||
|
||||
@@ -3727,7 +3727,7 @@ void ResourceInfo::Update(uint32_t numBindings, const VkSparseMemoryBind *pBindi
|
||||
VkSparseMemoryBind first = curRange;
|
||||
|
||||
// set the new size of the first half
|
||||
first.size = newRange.resourceOffset - newRange.resourceOffset;
|
||||
first.size = newRange.resourceOffset - curRange.resourceOffset;
|
||||
|
||||
// add the new range where the current iterator was
|
||||
curRange = newRange;
|
||||
|
||||
@@ -422,7 +422,7 @@ struct UpgradeCommand : public Command
|
||||
|
||||
ZeroMemory(paramsAlloc, sizeof(wchar_t) * 512);
|
||||
|
||||
wcscpy_s(paramsAlloc, sizeof(wchar_t) * 511, cmdline.c_str());
|
||||
wcscpy_s(paramsAlloc, 511, cmdline.c_str());
|
||||
|
||||
PROCESS_INFORMATION pi;
|
||||
STARTUPINFOW si;
|
||||
@@ -743,7 +743,7 @@ struct GlobalHookCommand : public Command
|
||||
// wait until a write comes in over the pipe
|
||||
char buf[16] = {0};
|
||||
DWORD read = 0;
|
||||
ReadFile(pipe, buf, 16, &read, NULL);
|
||||
ReadFile(pipe, buf, sizeof(buf), &read, NULL);
|
||||
|
||||
UnmapViewOfFile(shimdata);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user