Skip to content

Commit

Permalink
Fixed some numeric overflow bugs when working with very large textures.
Browse files Browse the repository at this point in the history
  • Loading branch information
apanteleev committed Sep 9, 2024
1 parent 52794a5 commit c11134a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/d3d12/d3d12-texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ namespace nvrhi::d3d12
{
for (uint32_t row = 0; row < numRows; row++)
{
void* destAddress = (char*)cpuVA + footprint.Footprint.RowPitch * (row + depthSlice * numRows);
void* destAddress = (char*)cpuVA + uint64_t(footprint.Footprint.RowPitch) * uint64_t(row + depthSlice * numRows);
const void* srcAddress = (const char*)data + rowPitch * row + depthPitch * depthSlice;
memcpy(destAddress, srcAddress, std::min(rowPitch, rowSizeInBytes));
}
Expand Down
8 changes: 4 additions & 4 deletions src/vulkan/vulkan-staging-texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ namespace nvrhi::vulkan
{
const FormatInfo& formatInfo = getFormatInfo(desc.format);

auto wInBlocks = std::max(((desc.width >> mipLevel) + formatInfo.blockSize - 1) / formatInfo.blockSize, 1u);
auto hInBlocks = std::max(((desc.height >> mipLevel) + formatInfo.blockSize - 1) / formatInfo.blockSize, 1u);
uint32_t wInBlocks = std::max(((desc.width >> mipLevel) + formatInfo.blockSize - 1) / formatInfo.blockSize, 1u);
uint32_t hInBlocks = std::max(((desc.height >> mipLevel) + formatInfo.blockSize - 1) / formatInfo.blockSize, 1u);

auto blockPitchBytes = wInBlocks * formatInfo.bytesPerBlock;
size_t blockPitchBytes = wInBlocks * formatInfo.bytesPerBlock;
return blockPitchBytes * hInBlocks;
}

Expand Down Expand Up @@ -118,7 +118,7 @@ namespace nvrhi::vulkan
tex->populateSliceRegions();

BufferDesc bufDesc;
bufDesc.byteSize = uint32_t(tex->getBufferSize());
bufDesc.byteSize = tex->getBufferSize();
assert(bufDesc.byteSize > 0);
bufDesc.debugName = desc.debugName;
bufDesc.cpuAccess = cpuAccess;
Expand Down
2 changes: 1 addition & 1 deletion src/vulkan/vulkan-texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ namespace nvrhi::vulkan
uint32_t deviceNumCols = (mipWidth + formatInfo.blockSize - 1) / formatInfo.blockSize;
uint32_t deviceNumRows = (mipHeight + formatInfo.blockSize - 1) / formatInfo.blockSize;
uint32_t deviceRowPitch = deviceNumCols * formatInfo.bytesPerBlock;
uint32_t deviceMemSize = deviceRowPitch * deviceNumRows * mipDepth;
uint64_t deviceMemSize = uint64_t(deviceRowPitch) * uint64_t(deviceNumRows) * mipDepth;

Buffer* uploadBuffer;
uint64_t uploadOffset;
Expand Down

0 comments on commit c11134a

Please sign in to comment.