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
13 changes: 12 additions & 1 deletion PluginSource/source/RenderAPI_D3D12.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "RenderAPI.h"
#include "PlatformBase.h"

#include <cmath>

// Direct3D 12 implementation of RenderAPI.


Expand Down Expand Up @@ -30,6 +32,7 @@ class RenderAPI_D3D12 : public RenderAPI
virtual void EndModifyVertexBuffer(void* bufferHandle);

private:
UINT64 AlignPow2(UINT64 value);
UINT64 GetAlignedSize(int width, int height, int pixelSize, int rowPitch);
ID3D12Resource* GetUploadResource(UINT64 size);
void CreateResources();
Expand Down Expand Up @@ -64,10 +67,18 @@ RenderAPI_D3D12::RenderAPI_D3D12()
{
}

UINT64 RenderAPI_D3D12::AlignPow2(UINT64 value)
{
UINT64 aligned = pow(2, (int)log2(value));
return aligned >= value ? aligned : aligned * 2;
}

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

size = AlignPow2(size);

if (size < D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT)
{
return D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT;
Expand Down Expand Up @@ -198,7 +209,7 @@ void* RenderAPI_D3D12::BeginModifyTexture(void* textureHandle, int textureWidth,

// Fill data
// Clamp to minimum rowPitch of RGBA32
*outRowPitch = max(textureWidth * 4, 256);
*outRowPitch = max(AlignPow2(textureWidth * 4), 256);
const UINT64 kDataSize = GetAlignedSize(textureWidth, textureHeight, 4, *outRowPitch);
ID3D12Resource* upload = GetUploadResource(kDataSize);
void* mapped = NULL;
Expand Down