Common: Add alignment header

Gets rid of duplicated alignment code.
This commit is contained in:
Léo Lam
2016-11-27 11:56:22 +01:00
parent 7192789c11
commit 31ccfffd38
32 changed files with 146 additions and 119 deletions

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include "VideoBackends/D3D12/XFBEncoder.h"
#include "Common/Align.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
@ -23,7 +24,7 @@ constexpr size_t XFB_TEXTURE_HEIGHT = MAX_XFB_HEIGHT;
// Buffer enough space for 2 XFB buffers (our frame latency)
constexpr size_t XFB_UPLOAD_BUFFER_SIZE =
D3D::AlignValue(XFB_TEXTURE_WIDTH * sizeof(u32), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT) *
Common::AlignUp(XFB_TEXTURE_WIDTH * sizeof(u32), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT) *
XFB_TEXTURE_HEIGHT * 2;
constexpr size_t XFB_ENCODER_PARAMS_BUFFER_SIZE = 64 * 1024;
@ -48,7 +49,7 @@ XFBEncoder::XFBEncoder()
CheckHR(D3D::device12->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_READBACK), D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(
D3D::AlignValue(XFB_TEXTURE_WIDTH * sizeof(u32), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT) *
Common::AlignUp(XFB_TEXTURE_WIDTH * sizeof(u32), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT) *
MAX_XFB_HEIGHT),
D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&m_readback_buffer)));
@ -117,7 +118,8 @@ void XFBEncoder::EncodeTextureToRam(u8* dst, u32 dst_pitch, u32 dst_height,
// Copy from YUYV intermediate texture to readback buffer. It's likely the pitch here is going to
// be different to dst_pitch.
u32 readback_pitch = D3D::AlignValue(dst_width * sizeof(u16), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
u32 readback_pitch = static_cast<u32>(
Common::AlignUp(dst_width * sizeof(u16), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT));
D3D12_PLACED_SUBRESOURCE_FOOTPRINT dst_footprint = {
0, {DXGI_FORMAT_R8G8B8A8_UNORM, dst_texture_width, dst_height, 1, readback_pitch}};
CD3DX12_TEXTURE_COPY_LOCATION dst_location(m_readback_buffer, dst_footprint);
@ -154,8 +156,8 @@ void XFBEncoder::DecodeToTexture(D3DTexture2D* dst_texture, const u8* src, u32 s
"XFB source does not exceed maximum size");
// Copy to XFB upload buffer. Each row has to be done separately due to pitch differences.
u32 buffer_pitch =
D3D::AlignValue(src_width / 2 * sizeof(u32), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
u32 buffer_pitch = static_cast<u32>(
Common::AlignUp(src_width / 2 * sizeof(u32), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT));
m_upload_buffer->AllocateSpaceInBuffer(buffer_pitch * src_height,
D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT);
for (u32 row = 0; row < src_height; row++)