|
1 | 1 | #include "RenderAPI.h" |
2 | 2 | #include "PlatformBase.h" |
3 | 3 |
|
| 4 | +#include <cmath> |
| 5 | + |
4 | 6 | // Direct3D 12 implementation of RenderAPI. |
5 | 7 |
|
6 | 8 |
|
@@ -30,6 +32,7 @@ class RenderAPI_D3D12 : public RenderAPI |
30 | 32 | virtual void EndModifyVertexBuffer(void* bufferHandle); |
31 | 33 |
|
32 | 34 | private: |
| 35 | + UINT64 AlignPow2(UINT64 value); |
33 | 36 | UINT64 GetAlignedSize(int width, int height, int pixelSize, int rowPitch); |
34 | 37 | ID3D12Resource* GetUploadResource(UINT64 size); |
35 | 38 | void CreateResources(); |
@@ -64,10 +67,18 @@ RenderAPI_D3D12::RenderAPI_D3D12() |
64 | 67 | { |
65 | 68 | } |
66 | 69 |
|
| 70 | +UINT64 RenderAPI_D3D12::AlignPow2(UINT64 value) |
| 71 | +{ |
| 72 | + UINT64 aligned = pow(2, (int)log2(value)); |
| 73 | + return aligned >= value ? aligned : aligned * 2; |
| 74 | +} |
| 75 | + |
67 | 76 | UINT64 RenderAPI_D3D12::GetAlignedSize( int width, int height, int pixelSize, int rowPitch) |
68 | 77 | { |
69 | 78 | UINT64 size = width * height * pixelSize; |
70 | 79 |
|
| 80 | + size = AlignPow2(size); |
| 81 | + |
71 | 82 | if (size < D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT) |
72 | 83 | { |
73 | 84 | return D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT; |
@@ -198,7 +209,7 @@ void* RenderAPI_D3D12::BeginModifyTexture(void* textureHandle, int textureWidth, |
198 | 209 |
|
199 | 210 | // Fill data |
200 | 211 | // Clamp to minimum rowPitch of RGBA32 |
201 | | - *outRowPitch = max(textureWidth * 4, 256); |
| 212 | + *outRowPitch = max(AlignPow2(textureWidth * 4), 256); |
202 | 213 | const UINT64 kDataSize = GetAlignedSize(textureWidth, textureHeight, 4, *outRowPitch); |
203 | 214 | ID3D12Resource* upload = GetUploadResource(kDataSize); |
204 | 215 | void* mapped = NULL; |
|
0 commit comments