2016-01-07 20:40:35 -07:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
struct ID3D12Resource;
|
|
|
|
|
|
|
|
namespace DX12
|
|
|
|
{
|
|
|
|
class D3DStreamBuffer
|
|
|
|
{
|
|
|
|
public:
|
2016-06-24 02:43:46 -06:00
|
|
|
D3DStreamBuffer(size_t initial_size, size_t max_size, bool* buffer_reallocation_notification);
|
|
|
|
~D3DStreamBuffer();
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
bool AllocateSpaceInBuffer(size_t allocation_size, size_t alignment, bool allow_execute = true);
|
|
|
|
void OverrideSizeOfPreviousAllocation(size_t override_allocation_size);
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void* GetBaseCPUAddress() const;
|
|
|
|
D3D12_GPU_VIRTUAL_ADDRESS GetBaseGPUAddress() const;
|
|
|
|
ID3D12Resource* GetBuffer() const;
|
|
|
|
void* GetCPUAddressOfCurrentAllocation() const;
|
|
|
|
D3D12_GPU_VIRTUAL_ADDRESS GetGPUAddressOfCurrentAllocation() const;
|
|
|
|
size_t GetOffsetOfCurrentAllocation() const;
|
|
|
|
size_t GetSize() const;
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
static void QueueFenceCallback(void* owning_object, UINT64 fence_value);
|
2016-01-07 20:40:35 -07:00
|
|
|
|
|
|
|
private:
|
2016-06-24 02:43:46 -06:00
|
|
|
void AllocateBuffer(size_t size);
|
|
|
|
bool AttemptBufferResizeOrElseStall(size_t allocation_size, bool allow_execute);
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
bool AttemptToAllocateOutOfExistingUnusedSpaceInBuffer(size_t allocation_size);
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
bool AttemptToFindExistingFenceToStallOn(size_t allocation_size);
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void UpdateGPUProgress();
|
2016-02-16 09:44:17 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void ClearFences();
|
|
|
|
bool HasBufferOffsetChangedSinceLastFence() const;
|
|
|
|
void QueueFence(UINT64 fence_value);
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
struct FenceTrackingInformation
|
|
|
|
{
|
|
|
|
UINT64 fence_value;
|
|
|
|
size_t buffer_offset;
|
|
|
|
};
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
std::queue<FenceTrackingInformation> m_queued_fences;
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
ID3D12Fence* m_buffer_tracking_fence = nullptr;
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
ID3D12Resource* m_buffer = nullptr;
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void* m_buffer_cpu_address = nullptr;
|
|
|
|
D3D12_GPU_VIRTUAL_ADDRESS m_buffer_gpu_address = {};
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
size_t m_buffer_current_allocation_offset = 0;
|
|
|
|
size_t m_buffer_offset = 0;
|
|
|
|
size_t m_buffer_size = 0;
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
const size_t m_buffer_max_size = 0;
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
size_t m_buffer_gpu_completion_offset = 0;
|
2016-01-07 20:40:35 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
bool* m_buffer_reallocation_notification = nullptr;
|
2016-01-07 20:40:35 -07:00
|
|
|
};
|
|
|
|
}
|