[UI] UploadBufferPool common code

This commit is contained in:
Triang3l
2020-09-17 21:37:44 +03:00
parent 2cebd3cabe
commit 189a38826f
18 changed files with 631 additions and 429 deletions

View File

@@ -438,9 +438,10 @@ uint64_t D3D12CommandProcessor::RequestViewBindfulDescriptors(
uint64_t current_heap_index = view_bindful_heap_pool_->Request(
frame_current_, previous_heap_index, count_for_partial_update,
count_for_full_update, descriptor_index);
if (current_heap_index == ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid) {
if (current_heap_index ==
ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid) {
// There was an error.
return ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid;
return ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid;
}
ID3D12DescriptorHeap* heap = view_bindful_heap_pool_->GetLastRequestHeap();
if (view_bindful_heap_current_ != heap) {
@@ -511,9 +512,9 @@ bool D3D12CommandProcessor::RequestOneUseSingleViewDescriptors(
D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle_start;
D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_start;
if (RequestViewBindfulDescriptors(
ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid, count, count,
ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid, count, count,
cpu_handle_start, gpu_handle_start) ==
ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid) {
ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid) {
return false;
}
for (uint32_t i = 0; i < count; ++i) {
@@ -609,9 +610,10 @@ uint64_t D3D12CommandProcessor::RequestSamplerBindfulDescriptors(
uint64_t current_heap_index = sampler_bindful_heap_pool_->Request(
frame_current_, previous_heap_index, count_for_partial_update,
count_for_full_update, descriptor_index);
if (current_heap_index == ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid) {
if (current_heap_index ==
ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid) {
// There was an error.
return ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid;
return ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid;
}
ID3D12DescriptorHeap* heap = sampler_bindful_heap_pool_->GetLastRequestHeap();
if (sampler_bindful_heap_current_ != heap) {
@@ -890,10 +892,10 @@ bool D3D12CommandProcessor::SetupContext() {
cvars::d3d12_edram_rov && provider.AreRasterizerOrderedViewsSupported();
// Initialize resource binding.
constant_buffer_pool_ = std::make_unique<ui::d3d12::UploadBufferPool>(
provider, std::max(ui::d3d12::UploadBufferPool::kDefaultPageSize,
uint32_t(D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * 4 *
sizeof(float))));
constant_buffer_pool_ = std::make_unique<ui::d3d12::D3D12UploadBufferPool>(
provider,
std::max(ui::d3d12::D3D12UploadBufferPool::kDefaultPageSize,
sizeof(float) * 4 * D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT));
if (bindless_resources_used_) {
D3D12_DESCRIPTOR_HEAP_DESC view_bindless_heap_desc;
view_bindless_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
@@ -929,10 +931,12 @@ bool D3D12CommandProcessor::SetupContext() {
sampler_bindless_heap_current_->GetGPUDescriptorHandleForHeapStart();
sampler_bindless_heap_allocated_ = 0;
} else {
view_bindful_heap_pool_ = std::make_unique<ui::d3d12::DescriptorHeapPool>(
device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, kViewBindfulHeapSize);
view_bindful_heap_pool_ =
std::make_unique<ui::d3d12::D3D12DescriptorHeapPool>(
device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
kViewBindfulHeapSize);
sampler_bindful_heap_pool_ =
std::make_unique<ui::d3d12::DescriptorHeapPool>(
std::make_unique<ui::d3d12::D3D12DescriptorHeapPool>(
device, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, kSamplerHeapSize);
}
@@ -2508,9 +2512,9 @@ void D3D12CommandProcessor::BeginSubmission(bool is_guest_command) {
cbuffer_binding_descriptor_indices_pixel_.up_to_date = false;
} else {
draw_view_bindful_heap_index_ =
ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid;
ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid;
draw_sampler_bindful_heap_index_ =
ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid;
ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid;
bindful_textures_written_vertex_ = false;
bindful_textures_written_pixel_ = false;
bindful_samplers_written_vertex_ = false;
@@ -3575,8 +3579,7 @@ bool D3D12CommandProcessor::UpdateBindings(
// empty buffer.
uint8_t* float_constants = constant_buffer_pool_->Request(
frame_current_,
uint32_t(std::max(float_constant_count_vertex, uint32_t(1)) * 4 *
sizeof(float)),
sizeof(float) * 4 * std::max(float_constant_count_vertex, uint32_t(1)),
D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT, nullptr, nullptr,
&cbuffer_binding_float_vertex_.address);
if (float_constants == nullptr) {
@@ -3604,8 +3607,7 @@ bool D3D12CommandProcessor::UpdateBindings(
if (!cbuffer_binding_float_pixel_.up_to_date) {
uint8_t* float_constants = constant_buffer_pool_->Request(
frame_current_,
uint32_t(std::max(float_constant_count_pixel, uint32_t(1)) * 4 *
sizeof(float)),
sizeof(float) * 4 * std::max(float_constant_count_pixel, uint32_t(1)),
D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT, nullptr, nullptr,
&cbuffer_binding_float_pixel_.address);
if (float_constants == nullptr) {
@@ -3893,9 +3895,9 @@ bool D3D12CommandProcessor::UpdateBindings(
uint32_t* descriptor_indices =
reinterpret_cast<uint32_t*>(constant_buffer_pool_->Request(
frame_current_,
uint32_t(std::max(texture_count_vertex + sampler_count_vertex,
uint32_t(1)) *
sizeof(uint32_t)),
std::max(texture_count_vertex + sampler_count_vertex,
uint32_t(1)) *
sizeof(uint32_t),
D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT, nullptr, nullptr,
&cbuffer_binding_descriptor_indices_vertex_.address));
if (!descriptor_indices) {
@@ -3929,9 +3931,8 @@ bool D3D12CommandProcessor::UpdateBindings(
uint32_t* descriptor_indices =
reinterpret_cast<uint32_t*>(constant_buffer_pool_->Request(
frame_current_,
uint32_t(std::max(texture_count_pixel + sampler_count_pixel,
uint32_t(1)) *
sizeof(uint32_t)),
std::max(texture_count_pixel + sampler_count_pixel, uint32_t(1)) *
sizeof(uint32_t),
D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT, nullptr, nullptr,
&cbuffer_binding_descriptor_indices_pixel_.address));
if (!descriptor_indices) {
@@ -4007,7 +4008,8 @@ bool D3D12CommandProcessor::UpdateBindings(
uint64_t view_heap_index = RequestViewBindfulDescriptors(
draw_view_bindful_heap_index_, view_count_partial_update,
view_count_full_update, view_cpu_handle, view_gpu_handle);
if (view_heap_index == ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid) {
if (view_heap_index ==
ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid) {
XELOGE("Failed to allocate view descriptors");
return false;
}
@@ -4022,14 +4024,14 @@ bool D3D12CommandProcessor::UpdateBindings(
D3D12_GPU_DESCRIPTOR_HANDLE sampler_gpu_handle = {};
uint32_t descriptor_size_sampler = provider.GetSamplerDescriptorSize();
uint64_t sampler_heap_index =
ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid;
ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid;
if (sampler_count_vertex != 0 || sampler_count_pixel != 0) {
sampler_heap_index = RequestSamplerBindfulDescriptors(
draw_sampler_bindful_heap_index_, sampler_count_partial_update,
sampler_count_vertex + sampler_count_pixel, sampler_cpu_handle,
sampler_gpu_handle);
if (sampler_heap_index ==
ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid) {
ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid) {
XELOGE("Failed to allocate sampler descriptors");
return false;
}
@@ -4059,7 +4061,7 @@ bool D3D12CommandProcessor::UpdateBindings(
~(1u << kRootParameter_Bindful_SharedMemoryAndEdram);
}
if (sampler_heap_index !=
ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid &&
ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid &&
draw_sampler_bindful_heap_index_ != sampler_heap_index) {
write_samplers_vertex = sampler_count_vertex != 0;
write_samplers_pixel = sampler_count_pixel != 0;
@@ -4143,7 +4145,7 @@ bool D3D12CommandProcessor::UpdateBindings(
// Wrote new descriptors on the current page.
draw_view_bindful_heap_index_ = view_heap_index;
if (sampler_heap_index !=
ui::d3d12::DescriptorHeapPool::kHeapIndexInvalid) {
ui::d3d12::D3D12DescriptorHeapPool::kHeapIndexInvalid) {
draw_sampler_bindful_heap_index_ = sampler_heap_index;
}
}

View File

@@ -29,8 +29,9 @@
#include "xenia/gpu/xenos.h"
#include "xenia/kernel/kernel_state.h"
#include "xenia/ui/d3d12/d3d12_context.h"
#include "xenia/ui/d3d12/d3d12_descriptor_heap_pool.h"
#include "xenia/ui/d3d12/d3d12_upload_buffer_pool.h"
#include "xenia/ui/d3d12/d3d12_util.h"
#include "xenia/ui/d3d12/pools.h"
namespace xe {
namespace gpu {
@@ -93,7 +94,7 @@ class D3D12CommandProcessor : public CommandProcessor {
ID3D12RootSignature* GetRootSignature(const D3D12Shader* vertex_shader,
const D3D12Shader* pixel_shader);
ui::d3d12::UploadBufferPool& GetConstantBufferPool() const {
ui::d3d12::D3D12UploadBufferPool& GetConstantBufferPool() const {
return *constant_buffer_pool_;
}
@@ -311,8 +312,8 @@ class D3D12CommandProcessor : public CommandProcessor {
void ClearCommandAllocatorCache();
// Request descriptors and automatically rebind the descriptor heap on the
// draw command list. Refer to DescriptorHeapPool::Request for partial/full
// update explanation. Doesn't work when bindless descriptors are used.
// draw command list. Refer to D3D12DescriptorHeapPool::Request for partial /
// full update explanation. Doesn't work when bindless descriptors are used.
uint64_t RequestViewBindfulDescriptors(
uint64_t previous_heap_index, uint32_t count_for_partial_update,
uint32_t count_for_full_update,
@@ -387,12 +388,13 @@ class D3D12CommandProcessor : public CommandProcessor {
// targets.
bool edram_rov_used_ = false;
std::unique_ptr<ui::d3d12::UploadBufferPool> constant_buffer_pool_ = nullptr;
std::unique_ptr<ui::d3d12::D3D12UploadBufferPool> constant_buffer_pool_ =
nullptr;
static constexpr uint32_t kViewBindfulHeapSize = 32768;
static_assert(kViewBindfulHeapSize <=
D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_1);
std::unique_ptr<ui::d3d12::DescriptorHeapPool> view_bindful_heap_pool_ =
std::unique_ptr<ui::d3d12::D3D12DescriptorHeapPool> view_bindful_heap_pool_ =
nullptr;
// Currently bound descriptor heap - updated by RequestViewBindfulDescriptors.
ID3D12DescriptorHeap* view_bindful_heap_current_;
@@ -423,8 +425,8 @@ class D3D12CommandProcessor : public CommandProcessor {
// FIXME(Triang3l): Investigate the issue with the sampler 2047 on Nvidia.
static constexpr uint32_t kSamplerHeapSize = 2000;
static_assert(kSamplerHeapSize <= D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE);
std::unique_ptr<ui::d3d12::DescriptorHeapPool> sampler_bindful_heap_pool_ =
nullptr;
std::unique_ptr<ui::d3d12::D3D12DescriptorHeapPool>
sampler_bindful_heap_pool_ = nullptr;
ID3D12DescriptorHeap* sampler_bindful_heap_current_;
ID3D12DescriptorHeap* sampler_bindless_heap_current_ = nullptr;
D3D12_CPU_DESCRIPTOR_HANDLE sampler_bindless_heap_cpu_start_;

View File

@@ -56,9 +56,9 @@ bool PrimitiveConverter::Initialize() {
// count), but they can be up to 4 bytes large, and conversion can add more
// indices (almost triple the count for triangle strips or fans, for
// instance).
buffer_pool_ = std::make_unique<ui::d3d12::UploadBufferPool>(
provider, std::max(uint32_t(65535 * 3 * sizeof(uint32_t)),
ui::d3d12::UploadBufferPool::kDefaultPageSize));
buffer_pool_ = std::make_unique<ui::d3d12::D3D12UploadBufferPool>(
provider, std::max(sizeof(uint32_t) * 3 * 65535,
ui::d3d12::D3D12UploadBufferPool::kDefaultPageSize));
// Create the static index buffer for non-indexed drawing.
D3D12_RESOURCE_DESC static_ib_desc;

View File

@@ -19,7 +19,7 @@
#include "xenia/gpu/xenos.h"
#include "xenia/memory.h"
#include "xenia/ui/d3d12/d3d12_context.h"
#include "xenia/ui/d3d12/pools.h"
#include "xenia/ui/d3d12/d3d12_upload_buffer_pool.h"
namespace xe {
namespace gpu {
@@ -107,7 +107,7 @@ class PrimitiveConverter {
Memory& memory_;
TraceWriter& trace_writer_;
std::unique_ptr<ui::d3d12::UploadBufferPool> buffer_pool_ = nullptr;
std::unique_ptr<ui::d3d12::D3D12UploadBufferPool> buffer_pool_ = nullptr;
// Static index buffers for emulating unsupported primitive types when drawing
// without an index buffer.

View File

@@ -26,7 +26,6 @@
#include "xenia/gpu/texture_info.h"
#include "xenia/gpu/texture_util.h"
#include "xenia/ui/d3d12/d3d12_util.h"
#include "xenia/ui/d3d12/pools.h"
DEFINE_bool(d3d12_16bit_rtv_full_range, true,
"Use full -32...32 range for RG16 and RGBA16 render targets "
@@ -1501,11 +1500,11 @@ void RenderTargetCache::RestoreEdramSnapshot(const void* snapshot) {
auto& provider = command_processor_.GetD3D12Context().GetD3D12Provider();
if (!edram_snapshot_restore_pool_) {
edram_snapshot_restore_pool_ =
std::make_unique<ui::d3d12::UploadBufferPool>(provider,
xenos::kEdramSizeBytes);
std::make_unique<ui::d3d12::D3D12UploadBufferPool>(
provider, xenos::kEdramSizeBytes);
}
ID3D12Resource* upload_buffer;
uint32_t upload_buffer_offset;
size_t upload_buffer_offset;
void* upload_buffer_mapping = edram_snapshot_restore_pool_->Request(
command_processor_.GetCurrentSubmission(), xenos::kEdramSizeBytes, 1,
&upload_buffer, &upload_buffer_offset, nullptr);
@@ -1518,7 +1517,7 @@ void RenderTargetCache::RestoreEdramSnapshot(const void* snapshot) {
TransitionEdramBuffer(D3D12_RESOURCE_STATE_COPY_DEST);
command_processor_.SubmitBarriers();
command_list.D3DCopyBufferRegion(edram_buffer_, 0, upload_buffer,
upload_buffer_offset,
UINT64(upload_buffer_offset),
xenos::kEdramSizeBytes);
if (!edram_rov_used_) {
// Clear and ignore the old 32-bit float depth - the non-ROV path is

View File

@@ -23,7 +23,7 @@
#include "xenia/gpu/xenos.h"
#include "xenia/memory.h"
#include "xenia/ui/d3d12/d3d12_api.h"
#include "xenia/ui/d3d12/pools.h"
#include "xenia/ui/d3d12/d3d12_upload_buffer_pool.h"
DECLARE_bool(d3d12_16bit_rtv_full_range);
@@ -602,8 +602,8 @@ class RenderTargetCache {
// For traces only.
ID3D12Resource* edram_snapshot_download_buffer_ = nullptr;
std::unique_ptr<ui::d3d12::UploadBufferPool> edram_snapshot_restore_pool_ =
nullptr;
std::unique_ptr<ui::d3d12::D3D12UploadBufferPool>
edram_snapshot_restore_pool_ = nullptr;
};
} // namespace d3d12

View File

@@ -153,9 +153,9 @@ bool SharedMemory::Initialize() {
system_page_flags_.clear();
system_page_flags_.resize((page_count_ + 63) / 64);
upload_buffer_pool_ = std::make_unique<ui::d3d12::UploadBufferPool>(
provider, xe::align(ui::d3d12::UploadBufferPool::kDefaultPageSize,
uint32_t(1) << page_size_log2_));
upload_buffer_pool_ = std::make_unique<ui::d3d12::D3D12UploadBufferPool>(
provider, xe::align(ui::d3d12::D3D12UploadBufferPool::kDefaultPageSize,
size_t(1) << page_size_log2_));
memory_invalidation_callback_handle_ =
memory_.RegisterPhysicalMemoryInvalidationCallback(
@@ -439,26 +439,26 @@ bool SharedMemory::RequestRange(uint32_t start, uint32_t length) {
upload_range_length << page_size_log2_);
while (upload_range_length != 0) {
ID3D12Resource* upload_buffer;
uint32_t upload_buffer_offset, upload_buffer_size;
size_t upload_buffer_offset, upload_buffer_size;
uint8_t* upload_buffer_mapping = upload_buffer_pool_->RequestPartial(
command_processor_.GetCurrentSubmission(),
upload_range_length << page_size_log2_,
uint32_t(1) << page_size_log2_, &upload_buffer, &upload_buffer_offset,
&upload_buffer_size, nullptr);
upload_range_length << page_size_log2_, size_t(1) << page_size_log2_,
&upload_buffer, &upload_buffer_offset, &upload_buffer_size, nullptr);
if (upload_buffer_mapping == nullptr) {
XELOGE("Shared memory: Failed to get an upload buffer");
return false;
}
uint32_t upload_buffer_pages = upload_buffer_size >> page_size_log2_;
MakeRangeValid(upload_range_start << page_size_log2_,
upload_buffer_pages << page_size_log2_, false);
uint32_t(upload_buffer_size), false);
std::memcpy(
upload_buffer_mapping,
memory_.TranslatePhysical(upload_range_start << page_size_log2_),
upload_buffer_size);
command_list.D3DCopyBufferRegion(
buffer_, upload_range_start << page_size_log2_, upload_buffer,
upload_buffer_offset, upload_buffer_size);
UINT64(upload_buffer_offset), UINT64(upload_buffer_size));
uint32_t upload_buffer_pages =
uint32_t(upload_buffer_size >> page_size_log2_);
upload_range_start += upload_buffer_pages;
upload_range_length -= upload_buffer_pages;
}

View File

@@ -18,7 +18,7 @@
#include "xenia/gpu/trace_writer.h"
#include "xenia/memory.h"
#include "xenia/ui/d3d12/d3d12_api.h"
#include "xenia/ui/d3d12/pools.h"
#include "xenia/ui/d3d12/d3d12_upload_buffer_pool.h"
namespace xe {
namespace gpu {
@@ -212,7 +212,8 @@ class SharedMemory {
std::vector<UploadRange> upload_ranges_;
void GetRangesToUpload(uint32_t request_page_first,
uint32_t request_page_last);
std::unique_ptr<ui::d3d12::UploadBufferPool> upload_buffer_pool_ = nullptr;
std::unique_ptr<ui::d3d12::D3D12UploadBufferPool> upload_buffer_pool_ =
nullptr;
// GPU-written memory downloading for traces.
// Start page, length in pages.

View File

@@ -25,8 +25,8 @@
#include "xenia/gpu/gpu_flags.h"
#include "xenia/gpu/texture_info.h"
#include "xenia/gpu/texture_util.h"
#include "xenia/ui/d3d12/d3d12_upload_buffer_pool.h"
#include "xenia/ui/d3d12/d3d12_util.h"
#include "xenia/ui/d3d12/pools.h"
DEFINE_int32(d3d12_resolution_scale, 1,
"Scale of rendering width and height (currently only 1 and 2 "