d3d12: Use align instead of powerOf2Align

This commit is contained in:
vlj 2015-06-25 21:46:36 +02:00 committed by Vincent Lejeune
parent 5e33d5535d
commit 1c7bff4d36
5 changed files with 17 additions and 28 deletions

View File

@ -18,17 +18,6 @@ void check(HRESULT hr)
abort(); abort();
} }
/**
* Get next value that is aligned by the corresponding power of 2
*/
inline
size_t powerOf2Align(size_t unalignedVal, size_t powerOf2)
{
// check that powerOf2 is power of 2
assert(!(powerOf2 & (powerOf2 - 1)));
return (unalignedVal + powerOf2 - 1) & ~(powerOf2 - 1);
}
/** /**
* Send data to dst pointer without polluting cache. * Send data to dst pointer without polluting cache.
* Usefull to write to mapped memory from upload heap. * Usefull to write to mapped memory from upload heap.

View File

@ -365,7 +365,7 @@ std::pair<std::vector<D3D12_VERTEX_BUFFER_VIEW>, D3D12_INDEX_BUFFER_VIEW> D3D12G
indexCount = 6 * m_indexed_array.m_data.size() / (4 * indexSize); indexCount = 6 * m_indexed_array.m_data.size() / (4 * indexSize);
else else
indexCount = m_draw_array_count * 6 / 4; indexCount = m_draw_array_count * 6 / 4;
size_t subBufferSize = powerOf2Align(indexCount * indexSize, 64); size_t subBufferSize = align(indexCount * indexSize, 64);
assert(m_vertexIndexData.canAlloc(subBufferSize)); assert(m_vertexIndexData.canAlloc(subBufferSize));
size_t heapOffset = m_vertexIndexData.alloc(subBufferSize); size_t heapOffset = m_vertexIndexData.alloc(subBufferSize);

View File

@ -1113,11 +1113,11 @@ ID3D12Resource * D3D12GSRender::writeColorBuffer(ID3D12Resource * RTT, ID3D12Gra
{ {
case CELL_GCM_SURFACE_A8R8G8B8: case CELL_GCM_SURFACE_A8R8G8B8:
dxgiFormat = DXGI_FORMAT_R8G8B8A8_UNORM; dxgiFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
rowPitch = powerOf2Align(w * 4, 256); rowPitch = align(w * 4, 256);
break; break;
case CELL_GCM_SURFACE_F_W16Z16Y16X16: case CELL_GCM_SURFACE_F_W16Z16Y16X16:
dxgiFormat = DXGI_FORMAT_R16G16B16A16_FLOAT; dxgiFormat = DXGI_FORMAT_R16G16B16A16_FLOAT;
rowPitch = powerOf2Align(w * 8, 256); rowPitch = align(w * 8, 256);
break; break;
} }
@ -1406,11 +1406,11 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
switch (m_surface_color_format) switch (m_surface_color_format)
{ {
case CELL_GCM_SURFACE_A8R8G8B8: case CELL_GCM_SURFACE_A8R8G8B8:
srcPitch = powerOf2Align(m_surface_clip_w * 4, 256); srcPitch = align(m_surface_clip_w * 4, 256);
dstPitch = m_surface_clip_w * 4; dstPitch = m_surface_clip_w * 4;
break; break;
case CELL_GCM_SURFACE_F_W16Z16Y16X16: case CELL_GCM_SURFACE_F_W16Z16Y16X16:
srcPitch = powerOf2Align(m_surface_clip_w * 8, 256); srcPitch = align(m_surface_clip_w * 8, 256);
dstPitch = m_surface_clip_w * 8; dstPitch = m_surface_clip_w * 8;
break; break;
} }

View File

@ -138,7 +138,7 @@ struct DataHeap
bool canAlloc(size_t size) bool canAlloc(size_t size)
{ {
size_t putPos = m_putPos, getPos = m_getPos; size_t putPos = m_putPos, getPos = m_getPos;
size_t allocSize = powerOf2Align(size, Alignment); size_t allocSize = align(size, Alignment);
if (putPos + allocSize < m_size) if (putPos + allocSize < m_size)
{ {
// range before get // range before get
@ -168,12 +168,12 @@ struct DataHeap
size_t putPos = m_putPos; size_t putPos = m_putPos;
if (putPos + size < m_size) if (putPos + size < m_size)
{ {
m_putPos += powerOf2Align(size, Alignment); m_putPos += align(size, Alignment);
return putPos; return putPos;
} }
else else
{ {
m_putPos = powerOf2Align(size, Alignment); m_putPos = align(size, Alignment);
return 0; return 0;
} }
} }

View File

@ -157,7 +157,7 @@ writeTexelsGeneric(const char *src, char *dst, size_t widthInBlock, size_t heigh
size_t currentHeight = heightInBlock, currentWidth = widthInBlock; size_t currentHeight = heightInBlock, currentWidth = widthInBlock;
for (unsigned mipLevel = 0; mipLevel < mipmapCount; mipLevel++) for (unsigned mipLevel = 0; mipLevel < mipmapCount; mipLevel++)
{ {
size_t rowPitch = powerOf2Align(currentWidth * blockSize, 256); size_t rowPitch = align(currentWidth * blockSize, 256);
MipmapLevelInfo currentMipmapLevelInfo = {}; MipmapLevelInfo currentMipmapLevelInfo = {};
currentMipmapLevelInfo.offset = offsetInDst; currentMipmapLevelInfo.offset = offsetInDst;
@ -188,7 +188,7 @@ writeTexelsSwizzled(const char *src, char *dst, size_t widthInBlock, size_t heig
size_t currentHeight = heightInBlock, currentWidth = widthInBlock; size_t currentHeight = heightInBlock, currentWidth = widthInBlock;
for (unsigned mipLevel = 0; mipLevel < mipmapCount; mipLevel++) for (unsigned mipLevel = 0; mipLevel < mipmapCount; mipLevel++)
{ {
size_t rowPitch = powerOf2Align(currentWidth * blockSize, 256); size_t rowPitch = align(currentWidth * blockSize, 256);
MipmapLevelInfo currentMipmapLevelInfo = {}; MipmapLevelInfo currentMipmapLevelInfo = {};
currentMipmapLevelInfo.offset = offsetInDst; currentMipmapLevelInfo.offset = offsetInDst;
@ -231,7 +231,7 @@ writeCompressedTexel(const char *src, char *dst, size_t widthInBlock, size_t blo
size_t currentHeight = heightInBlock, currentWidth = widthInBlock; size_t currentHeight = heightInBlock, currentWidth = widthInBlock;
for (unsigned mipLevel = 0; mipLevel < mipmapCount; mipLevel++) for (unsigned mipLevel = 0; mipLevel < mipmapCount; mipLevel++)
{ {
size_t rowPitch = powerOf2Align(currentWidth * blockSize, 256); size_t rowPitch = align(currentWidth * blockSize, 256);
MipmapLevelInfo currentMipmapLevelInfo = {}; MipmapLevelInfo currentMipmapLevelInfo = {};
currentMipmapLevelInfo.offset = offsetInDst; currentMipmapLevelInfo.offset = offsetInDst;
@ -244,7 +244,7 @@ writeCompressedTexel(const char *src, char *dst, size_t widthInBlock, size_t blo
memcpy((char*)dst + offsetInDst + row * rowPitch, (char*)src + offsetInSrc + row * currentWidth * blockSize, currentWidth * blockSize); memcpy((char*)dst + offsetInDst + row * rowPitch, (char*)src + offsetInSrc + row * currentWidth * blockSize, currentWidth * blockSize);
offsetInDst += currentHeight * rowPitch; offsetInDst += currentHeight * rowPitch;
offsetInDst = powerOf2Align(offsetInDst, 512); offsetInDst = align(offsetInDst, 512);
offsetInSrc += currentHeight * currentWidth * blockSize; offsetInSrc += currentHeight * currentWidth * blockSize;
currentHeight = MAX2(currentHeight / 2, 1); currentHeight = MAX2(currentHeight / 2, 1);
currentWidth = MAX2(currentWidth / 2, 1); currentWidth = MAX2(currentWidth / 2, 1);
@ -264,7 +264,7 @@ write16bTexelsGeneric(const char *src, char *dst, size_t widthInBlock, size_t he
size_t srcPitch = widthInBlock * blockSize; size_t srcPitch = widthInBlock * blockSize;
for (unsigned mipLevel = 0; mipLevel < mipmapCount; mipLevel++) for (unsigned mipLevel = 0; mipLevel < mipmapCount; mipLevel++)
{ {
size_t rowPitch = powerOf2Align(currentWidth * blockSize, 256); size_t rowPitch = align(currentWidth * blockSize, 256);
MipmapLevelInfo currentMipmapLevelInfo = {}; MipmapLevelInfo currentMipmapLevelInfo = {};
currentMipmapLevelInfo.offset = offsetInDst; currentMipmapLevelInfo.offset = offsetInDst;
@ -302,7 +302,7 @@ write16bX4TexelsGeneric(const char *src, char *dst, size_t widthInBlock, size_t
size_t srcPitch = widthInBlock * blockSize; size_t srcPitch = widthInBlock * blockSize;
for (unsigned mipLevel = 0; mipLevel < mipmapCount; mipLevel++) for (unsigned mipLevel = 0; mipLevel < mipmapCount; mipLevel++)
{ {
size_t rowPitch = powerOf2Align(currentWidth * blockSize, 256); size_t rowPitch = align(currentWidth * blockSize, 256);
MipmapLevelInfo currentMipmapLevelInfo = {}; MipmapLevelInfo currentMipmapLevelInfo = {};
currentMipmapLevelInfo.offset = offsetInDst; currentMipmapLevelInfo.offset = offsetInDst;
@ -490,7 +490,7 @@ ID3D12Resource *uploadSingleTexture(
size_t heightInBlocks = (h + blockHeightInPixel - 1) / blockHeightInPixel; size_t heightInBlocks = (h + blockHeightInPixel - 1) / blockHeightInPixel;
size_t widthInBlocks = (w + blockWidthInPixel - 1) / blockWidthInPixel; size_t widthInBlocks = (w + blockWidthInPixel - 1) / blockWidthInPixel;
// Multiple of 256 // Multiple of 256
size_t rowPitch = powerOf2Align(blockSizeInByte * widthInBlocks, 256); size_t rowPitch = align(blockSizeInByte * widthInBlocks, 256);
ID3D12Resource *Texture; ID3D12Resource *Texture;
size_t textureSize = rowPitch * heightInBlocks * 2; // * 4 for mipmap levels size_t textureSize = rowPitch * heightInBlocks * 2; // * 4 for mipmap levels
@ -610,7 +610,7 @@ size_t getTextureSize(const RSXTexture &texture)
case ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN) & CELL_GCM_TEXTURE_COMPRESSED_R8B8_R8G8: case ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN) & CELL_GCM_TEXTURE_COMPRESSED_R8B8_R8G8:
default: default:
LOG_ERROR(RSX, "Unimplemented Texture format : %x", format); LOG_ERROR(RSX, "Unimplemented Texture format : %x", format);
break; return 0;
case CELL_GCM_TEXTURE_B8: case CELL_GCM_TEXTURE_B8:
return w * h; return w * h;
case CELL_GCM_TEXTURE_A1R5G5B5: case CELL_GCM_TEXTURE_A1R5G5B5:
@ -707,7 +707,7 @@ size_t D3D12GSRender::UploadTextures()
getCurrentResourceStorage().m_inflightCommandList.push_back(commandList); getCurrentResourceStorage().m_inflightCommandList.push_back(commandList);
m_texturesCache[texaddr] = vramTexture; m_texturesCache[texaddr] = vramTexture;
u32 s = align(getTextureSize(m_textures[i]), 4096); u32 s = (u32)align(getTextureSize(m_textures[i]), 4096);
LOG_WARNING(RSX, "PROTECTING %x of size %d", align(texaddr, 4096), s); LOG_WARNING(RSX, "PROTECTING %x of size %d", align(texaddr, 4096), s);
m_protectedTextures.push_back(std::make_tuple(texaddr, align(texaddr, 4096), s)); m_protectedTextures.push_back(std::make_tuple(texaddr, align(texaddr, 4096), s));
vm::page_protect(align(texaddr, 4096), s, 0, 0, vm::page_writable); vm::page_protect(align(texaddr, 4096), s, 0, 0, vm::page_writable);