D3DStreamBuffer: Use size_t within the class interface

A few StreamBuffer instances take arguments that are actually size_t,
and this will cause truncation warnings during argument forwarding
with make_unique.
This commit is contained in:
Lioncash 2016-02-16 00:39:04 -05:00
parent 2c5fcad5f5
commit 626fcf4c15
4 changed files with 54 additions and 55 deletions

View File

@ -12,7 +12,7 @@
namespace DX12
{
D3DStreamBuffer::D3DStreamBuffer(unsigned int initial_size, unsigned int max_size, bool* buffer_reallocation_notification) :
D3DStreamBuffer::D3DStreamBuffer(size_t initial_size, size_t max_size, bool* buffer_reallocation_notification) :
m_buffer_size(initial_size),
m_buffer_max_size(max_size),
m_buffer_reallocation_notification(buffer_reallocation_notification)
@ -39,13 +39,13 @@ D3DStreamBuffer::~D3DStreamBuffer()
// Obviously this is non-performant, so the buffer max_size should be large enough to
// ensure this never happens.
bool D3DStreamBuffer::AllocateSpaceInBuffer(unsigned int allocation_size, unsigned int alignment)
bool D3DStreamBuffer::AllocateSpaceInBuffer(size_t allocation_size, size_t alignment)
{
CHECK(allocation_size <= m_buffer_max_size, "Error: Requested allocation size in D3DStreamBuffer is greater than max allowed size of backing buffer.");
if (alignment)
{
unsigned int padding = m_buffer_offset % alignment;
size_t padding = m_buffer_offset % alignment;
// Check for case when adding alignment causes CPU offset to equal GPU offset,
// which would imply entire buffer is available (if not corrected).
@ -84,12 +84,12 @@ bool D3DStreamBuffer::AllocateSpaceInBuffer(unsigned int allocation_size, unsign
// we call AllocateSpaceInBuffer. We have to conservatively allocate 16MB (!).
// After the vertex data is written, we can choose to specify the 'real' allocation
// size to avoid wasting space.
void D3DStreamBuffer::OverrideSizeOfPreviousAllocation(unsigned int override_allocation_size)
void D3DStreamBuffer::OverrideSizeOfPreviousAllocation(size_t override_allocation_size)
{
m_buffer_offset = m_buffer_current_allocation_offset + override_allocation_size;
}
void D3DStreamBuffer::AllocateBuffer(unsigned int size)
void D3DStreamBuffer::AllocateBuffer(size_t size)
{
// First, put existing buffer (if it exists) in deferred destruction list.
if (m_buffer)
@ -120,7 +120,7 @@ void D3DStreamBuffer::AllocateBuffer(unsigned int size)
// Function returns true if current command list executed as a result of current command list
// referencing all of buffer's contents, AND we are already at max_size. No alternative but to
// flush. See comments above AllocateSpaceInBuffer for more details.
bool D3DStreamBuffer::AttemptBufferResizeOrElseStall(unsigned int allocation_size)
bool D3DStreamBuffer::AttemptBufferResizeOrElseStall(size_t allocation_size)
{
// This function will attempt to increase the size of the buffer, in response
// to running out of room. If the buffer is already at its maximum size specified
@ -148,7 +148,7 @@ bool D3DStreamBuffer::AttemptBufferResizeOrElseStall(unsigned int allocation_siz
}
// 2) Next, prefer increasing buffer size instead of stalling.
unsigned int new_size = std::min(static_cast<unsigned int>(m_buffer_size * 1.5f), m_buffer_max_size);
size_t new_size = std::min(static_cast<size_t>(m_buffer_size * 1.5f), m_buffer_max_size);
new_size = std::max(new_size, allocation_size);
// Can we grow buffer further?
@ -193,7 +193,7 @@ bool D3DStreamBuffer::AttemptBufferResizeOrElseStall(unsigned int allocation_siz
}
// Return true if space is found.
bool D3DStreamBuffer::AttemptToAllocateOutOfExistingUnusedSpaceInBuffer(unsigned int allocation_size)
bool D3DStreamBuffer::AttemptToAllocateOutOfExistingUnusedSpaceInBuffer(size_t allocation_size)
{
// First, check if there is room at end of buffer. Fast path.
if (m_buffer_offset >= m_buffer_gpu_completion_offset)
@ -225,12 +225,11 @@ bool D3DStreamBuffer::AttemptToAllocateOutOfExistingUnusedSpaceInBuffer(unsigned
}
// Returns true if fence was found and waited on.
bool D3DStreamBuffer::AttemptToFindExistingFenceToStallOn(unsigned int allocation_size)
bool D3DStreamBuffer::AttemptToFindExistingFenceToStallOn(size_t allocation_size)
{
// Let's find the first fence that will free up enough space in our buffer.
UINT64 fence_value_required = 0;
unsigned int new_buffer_offset = 0;
while (m_queued_fences.size() > 0)
{
@ -335,12 +334,12 @@ void* D3DStreamBuffer::GetCPUAddressOfCurrentAllocation() const
return static_cast<u8*>(m_buffer_cpu_address) + m_buffer_current_allocation_offset;
}
unsigned int D3DStreamBuffer::GetOffsetOfCurrentAllocation() const
size_t D3DStreamBuffer::GetOffsetOfCurrentAllocation() const
{
return m_buffer_current_allocation_offset;
}
unsigned int D3DStreamBuffer::GetSize() const
size_t D3DStreamBuffer::GetSize() const
{
return m_buffer_size;
}

View File

@ -14,29 +14,29 @@ namespace DX12
class D3DStreamBuffer
{
public:
D3DStreamBuffer(unsigned int initial_size, unsigned int max_size, bool* buffer_reallocation_notification);
D3DStreamBuffer(size_t initial_size, size_t max_size, bool* buffer_reallocation_notification);
~D3DStreamBuffer();
bool AllocateSpaceInBuffer(unsigned int allocation_size, unsigned int alignment);
void OverrideSizeOfPreviousAllocation(unsigned int override_allocation_size);
bool AllocateSpaceInBuffer(size_t allocation_size, size_t alignment);
void OverrideSizeOfPreviousAllocation(size_t override_allocation_size);
void* GetBaseCPUAddress() const;
D3D12_GPU_VIRTUAL_ADDRESS GetBaseGPUAddress() const;
ID3D12Resource* GetBuffer() const;
void* GetCPUAddressOfCurrentAllocation() const;
D3D12_GPU_VIRTUAL_ADDRESS GetGPUAddressOfCurrentAllocation() const;
unsigned int GetOffsetOfCurrentAllocation() const;
unsigned int GetSize() const;
size_t GetOffsetOfCurrentAllocation() const;
size_t GetSize() const;
static void QueueFenceCallback(void* owning_object, UINT64 fence_value);
private:
void AllocateBuffer(unsigned int size);
bool AttemptBufferResizeOrElseStall(unsigned int new_size);
void AllocateBuffer(size_t size);
bool AttemptBufferResizeOrElseStall(size_t new_size);
bool AttemptToAllocateOutOfExistingUnusedSpaceInBuffer(unsigned int allocation_size);
bool AttemptToAllocateOutOfExistingUnusedSpaceInBuffer(size_t allocation_size);
bool AttemptToFindExistingFenceToStallOn(unsigned int allocation_size);
bool AttemptToFindExistingFenceToStallOn(size_t allocation_size);
void UpdateGPUProgress();
void QueueFence(UINT64 fence_value);
@ -44,7 +44,7 @@ private:
struct FenceTrackingInformation
{
UINT64 fence_value;
unsigned int buffer_offset;
size_t buffer_offset;
};
std::queue<FenceTrackingInformation> m_queued_fences;
@ -56,13 +56,13 @@ private:
void* m_buffer_cpu_address = nullptr;
D3D12_GPU_VIRTUAL_ADDRESS m_buffer_gpu_address = {};
unsigned int m_buffer_current_allocation_offset = 0;
unsigned int m_buffer_offset = 0;
unsigned int m_buffer_size = 0;
size_t m_buffer_current_allocation_offset = 0;
size_t m_buffer_offset = 0;
size_t m_buffer_size = 0;
const unsigned int m_buffer_max_size = 0;
const size_t m_buffer_max_size = 0;
unsigned int m_buffer_gpu_completion_offset = 0;
size_t m_buffer_gpu_completion_offset = 0;
bool* m_buffer_reallocation_notification = nullptr;
};

View File

@ -56,7 +56,7 @@ void ResourceBarrier(ID3D12GraphicsCommandList* command_list, ID3D12Resource* re
class UtilVertexBuffer
{
public:
explicit UtilVertexBuffer(int size)
explicit UtilVertexBuffer(size_t size)
{
m_stream_buffer = new D3DStreamBuffer(size, size * 4, nullptr);
}
@ -65,10 +65,10 @@ public:
SAFE_DELETE(m_stream_buffer);
}
unsigned int GetSize() const { return m_stream_buffer->GetSize(); }
size_t GetSize() const { return m_stream_buffer->GetSize(); }
// returns vertex offset to the new data
int AppendData(void* data, int size, int vertex_size)
size_t AppendData(const void* data, size_t size, size_t vertex_size)
{
m_stream_buffer->AllocateSpaceInBuffer(size, vertex_size);
@ -77,7 +77,7 @@ public:
return m_stream_buffer->GetOffsetOfCurrentAllocation() / vertex_size;
}
int BeginAppendData(void** write_ptr, int size, int vertex_size)
size_t BeginAppendData(void** write_ptr, size_t size, size_t vertex_size)
{
m_stream_buffer->AllocateSpaceInBuffer(size, vertex_size);
@ -535,9 +535,9 @@ struct
} clear_quad_data;
// ring buffer offsets
int stq_offset;
int cq_offset;
int clearq_offset;
static size_t stq_offset;
static size_t cq_offset;
static size_t clearq_offset;
void InitUtils()
{
@ -660,7 +660,7 @@ void DrawShadedTexQuad(D3DTexture2D* texture,
D3D12_VERTEX_BUFFER_VIEW vb_view = {
util_vbuf_stq->GetBuffer12()->GetGPUVirtualAddress(), // D3D12_GPU_VIRTUAL_ADDRESS BufferLocation;
util_vbuf_stq->GetSize(), // UINT SizeInBytes; This is the size of the entire buffer, not just the size of the vertex data for one draw call, since the offsetting is done in the draw call itself.
static_cast<UINT>(util_vbuf_stq->GetSize()), // UINT SizeInBytes; This is the size of the entire buffer, not just the size of the vertex data for one draw call, since the offsetting is done in the draw call itself.
sizeof(STQVertex) // UINT StrideInBytes;
};
@ -714,7 +714,7 @@ void DrawShadedTexQuad(D3DTexture2D* texture,
// 2 ^ D3D12_MAX_TEXTURE_DIMENSION_2_TO_EXP = 131072
D3D::current_command_list->RSSetScissorRects(1, &CD3DX12_RECT(0, 0, 131072, 131072));
D3D::current_command_list->DrawInstanced(4, 1, stq_offset, 0);
D3D::current_command_list->DrawInstanced(4, 1, static_cast<UINT>(stq_offset), 0);
g_renderer->RestoreAPIState();
}
@ -749,7 +749,7 @@ void DrawColorQuad(u32 Color, float z, float x1, float y1, float x2, float y2, D
D3D12_VERTEX_BUFFER_VIEW vb_view = {
util_vbuf_cq->GetBuffer12()->GetGPUVirtualAddress(), // D3D12_GPU_VIRTUAL_ADDRESS BufferLocation;
util_vbuf_cq->GetSize(), // UINT SizeInBytes; This is the size of the entire buffer, not just the size of the vertex data for one draw call, since the offsetting is done in the draw call itself.
static_cast<UINT>(util_vbuf_cq->GetSize()), // UINT SizeInBytes; This is the size of the entire buffer, not just the size of the vertex data for one draw call, since the offsetting is done in the draw call itself.
sizeof(ColVertex) // UINT StrideInBytes;
};
@ -795,7 +795,7 @@ void DrawColorQuad(u32 Color, float z, float x1, float y1, float x2, float y2, D
// 2 ^ D3D12_MAX_TEXTURE_DIMENSION_2_TO_EXP = 131072
D3D::current_command_list->RSSetScissorRects(1, &CD3DX12_RECT(0, 0, 131072, 131072));
D3D::current_command_list->DrawInstanced(4, 1, cq_offset, 0);
D3D::current_command_list->DrawInstanced(4, 1, static_cast<UINT>(cq_offset), 0);
g_renderer->RestoreAPIState();
}
@ -822,7 +822,7 @@ void DrawClearQuad(u32 Color, float z, D3D12_BLEND_DESC* blend_desc, D3D12_DEPTH
D3D12_VERTEX_BUFFER_VIEW vb_view = {
util_vbuf_clearq->GetBuffer12()->GetGPUVirtualAddress(), // D3D12_GPU_VIRTUAL_ADDRESS BufferLocation;
util_vbuf_clearq->GetSize(), // UINT SizeInBytes; This is the size of the entire buffer, not just the size of the vertex data for one draw call, since the offsetting is done in the draw call itself.
static_cast<UINT>(util_vbuf_clearq->GetSize()), // UINT SizeInBytes; This is the size of the entire buffer, not just the size of the vertex data for one draw call, since the offsetting is done in the draw call itself.
sizeof(ClearVertex) // UINT StrideInBytes;
};
@ -870,7 +870,7 @@ void DrawClearQuad(u32 Color, float z, D3D12_BLEND_DESC* blend_desc, D3D12_DEPTH
// 2 ^ D3D12_MAX_TEXTURE_DIMENSION_2_TO_EXP = 131072
D3D::current_command_list->RSSetScissorRects(1, &CD3DX12_RECT(0, 0, 131072, 131072));
D3D::current_command_list->DrawInstanced(4, 1, clearq_offset, 0);
D3D::current_command_list->DrawInstanced(4, 1, static_cast<UINT>(clearq_offset), 0);
g_renderer->RestoreAPIState();
}
@ -942,7 +942,7 @@ void DrawEFBPokeQuads(EFBAccessType type,
size_t required_bytes = COL_QUAD_SIZE * points_to_draw;
void* buffer_ptr = nullptr;
int base_vertex_index = util_vbuf_efbpokequads->BeginAppendData(&buffer_ptr, static_cast<int>(required_bytes), sizeof(ColVertex));
size_t base_vertex_index = util_vbuf_efbpokequads->BeginAppendData(&buffer_ptr, required_bytes, sizeof(ColVertex));
CHECK(base_vertex_index * 16 + required_bytes <= util_vbuf_efbpokequads->GetSize(), "Uh oh");
@ -953,7 +953,7 @@ void DrawEFBPokeQuads(EFBAccessType type,
D3D12_VERTEX_BUFFER_VIEW vb_view = {
util_vbuf_efbpokequads->GetBuffer12()->GetGPUVirtualAddress(), // D3D12_GPU_VIRTUAL_ADDRESS BufferLocation;
util_vbuf_efbpokequads->GetSize(), // UINT SizeInBytes; This is the size of the entire buffer, not just the size of the vertex data for one draw call, since the offsetting is done in the draw call itself.
static_cast<UINT>(util_vbuf_efbpokequads->GetSize()), // UINT SizeInBytes; This is the size of the entire buffer, not just the size of the vertex data for one draw call, since the offsetting is done in the draw call itself.
sizeof(ColVertex) // UINT StrideInBytes;
};
@ -991,7 +991,7 @@ void DrawEFBPokeQuads(EFBAccessType type,
}
// Issue the draw
D3D::current_command_list->DrawInstanced(6 * static_cast<unsigned int>(points_to_draw), 1, base_vertex_index, 0);
D3D::current_command_list->DrawInstanced(6 * static_cast<UINT>(points_to_draw), 1, static_cast<UINT>(base_vertex_index), 0);
}
}

View File

@ -31,9 +31,9 @@ static constexpr unsigned int MAX_VBUFFER_SIZE = VertexManager::MAXVBUFFERSIZE *
void VertexManager::SetIndexBuffer()
{
D3D12_INDEX_BUFFER_VIEW ib_view = {
m_index_stream_buffer->GetBaseGPUAddress(), // D3D12_GPU_VIRTUAL_ADDRESS BufferLocation;
m_index_stream_buffer->GetSize(), // UINT SizeInBytes;
DXGI_FORMAT_R16_UINT // DXGI_FORMAT Format;
m_index_stream_buffer->GetBaseGPUAddress(), // D3D12_GPU_VIRTUAL_ADDRESS BufferLocation;
static_cast<UINT>(m_index_stream_buffer->GetSize()), // UINT SizeInBytes;
DXGI_FORMAT_R16_UINT // DXGI_FORMAT Format;
};
D3D::current_command_list->IASetIndexBuffer(&ib_view);
@ -95,9 +95,9 @@ void VertexManager::Draw(u32 stride)
if (D3D::command_list_mgr->GetCommandListDirtyState(COMMAND_LIST_STATE_VERTEX_BUFFER) || s_previous_stride != stride)
{
D3D12_VERTEX_BUFFER_VIEW vb_view = {
m_vertex_stream_buffer->GetBaseGPUAddress(), // D3D12_GPU_VIRTUAL_ADDRESS BufferLocation;
m_vertex_stream_buffer->GetSize(), // UINT SizeInBytes;
stride // UINT StrideInBytes;
m_vertex_stream_buffer->GetBaseGPUAddress(), // D3D12_GPU_VIRTUAL_ADDRESS BufferLocation;
static_cast<UINT>(m_vertex_stream_buffer->GetSize()), // UINT SizeInBytes;
stride // UINT StrideInBytes;
};
D3D::current_command_list->IASetVertexBuffers(0, 1, &vb_view);
@ -194,11 +194,11 @@ void VertexManager::ResetBuffer(u32 stride)
}
s_pBaseBufferPointer = static_cast<u8*>(m_vertex_stream_buffer->GetBaseCPUAddress());
s_pEndBufferPointer = s_pBaseBufferPointer + m_vertex_stream_buffer->GetSize();
s_pCurBufferPointer = static_cast<u8*>(m_vertex_stream_buffer->GetCPUAddressOfCurrentAllocation());
m_vertex_draw_offset = m_vertex_stream_buffer->GetOffsetOfCurrentAllocation();
s_pEndBufferPointer = s_pBaseBufferPointer + m_vertex_stream_buffer->GetSize();
s_pCurBufferPointer = static_cast<u8*>(m_vertex_stream_buffer->GetCPUAddressOfCurrentAllocation());
m_vertex_draw_offset = static_cast<u32>(m_vertex_stream_buffer->GetOffsetOfCurrentAllocation());
command_list_executed |= m_index_stream_buffer->AllocateSpaceInBuffer(MAXIBUFFERSIZE * sizeof(u16), sizeof(u16));
command_list_executed |= m_index_stream_buffer->AllocateSpaceInBuffer(MAXIBUFFERSIZE * sizeof(u16), sizeof(u16));
if (command_list_executed)
{
g_renderer->SetViewport();
@ -211,8 +211,8 @@ void VertexManager::ResetBuffer(u32 stride)
m_index_stream_buffer_reallocated = false;
}
m_index_draw_offset = m_index_stream_buffer->GetOffsetOfCurrentAllocation();
IndexGenerator::Start(reinterpret_cast<u16*>(m_index_stream_buffer->GetCPUAddressOfCurrentAllocation()));
m_index_draw_offset = static_cast<u32>(m_index_stream_buffer->GetOffsetOfCurrentAllocation());
IndexGenerator::Start(static_cast<u16*>(m_index_stream_buffer->GetCPUAddressOfCurrentAllocation()));
}
} // namespace