Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions PluginSource/source/RenderAPI_D3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class RenderAPI_D3D12 : public RenderAPI
virtual void EndModifyVertexBuffer(void* bufferHandle);

private:
UINT64 GetAlignedSize(int width, int height, int pixelSize, int rowPitch);
ID3D12Resource* GetUploadResource(UINT64 size);
void CreateResources();
void ReleaseResources();
Expand Down Expand Up @@ -63,6 +64,23 @@ RenderAPI_D3D12::RenderAPI_D3D12()
{
}

UINT64 RenderAPI_D3D12::GetAlignedSize( int width, int height, int pixelSize, int rowPitch)
{
UINT64 size = width * height * pixelSize;

if (size < D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT)
{
return D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT;
}
else if (width * pixelSize < rowPitch)
{
return rowPitch * height;
}
else
{
return size;
}
}

ID3D12Resource* RenderAPI_D3D12::GetUploadResource(UINT64 size)
{
Expand Down Expand Up @@ -179,11 +197,12 @@ void* RenderAPI_D3D12::BeginModifyTexture(void* textureHandle, int textureWidth,
s_D3D12CmdList->Reset(s_D3D12CmdAlloc, nullptr);

// Fill data
const UINT64 kDataSize = textureWidth * textureHeight * 4;
// Clamp to minimum rowPitch of RGBA32
*outRowPitch = max(textureWidth * 4, 256);
const UINT64 kDataSize = GetAlignedSize(textureWidth, textureHeight, 4, *outRowPitch);
ID3D12Resource* upload = GetUploadResource(kDataSize);
void* mapped = NULL;
upload->Map(0, NULL, &mapped);
*outRowPitch = textureWidth * 4;
return mapped;
}

Expand All @@ -192,7 +211,7 @@ void RenderAPI_D3D12::EndModifyTexture(void* textureHandle, int textureWidth, in
{
ID3D12Device* device = s_D3D12->GetDevice();

const UINT64 kDataSize = textureWidth * textureHeight * 4;
const UINT64 kDataSize = GetAlignedSize(textureWidth, textureHeight, 4, rowPitch);
ID3D12Resource* upload = GetUploadResource(kDataSize);
upload->Unmap(0, NULL);

Expand Down