Merge branch 'master' into vulkan

This commit is contained in:
Triang3l
2020-09-15 23:22:17 +03:00
11 changed files with 123 additions and 79 deletions

View File

@@ -287,8 +287,7 @@ bool D3D12ImmediateDrawer::Initialize() {
device->CreateSampler(&sampler_desc, sampler_handle);
// Create pools for draws.
vertex_buffer_pool_ =
std::make_unique<UploadBufferPool>(provider, 2 * 1024 * 1024);
vertex_buffer_pool_ = std::make_unique<UploadBufferPool>(provider);
texture_descriptor_pool_ = std::make_unique<DescriptorHeapPool>(
device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 2048);
texture_descriptor_pool_heap_index_ = DescriptorHeapPool::kHeapIndexInvalid;
@@ -506,8 +505,8 @@ void D3D12ImmediateDrawer::BeginDrawBatch(const ImmediateDrawBatch& batch) {
vertex_buffer_view.SizeInBytes =
batch.vertex_count * uint32_t(sizeof(ImmediateVertex));
void* vertex_buffer_mapping = vertex_buffer_pool_->Request(
current_fence_value, vertex_buffer_view.SizeInBytes, nullptr, nullptr,
&vertex_buffer_view.BufferLocation);
current_fence_value, vertex_buffer_view.SizeInBytes, sizeof(uint32_t),
nullptr, nullptr, &vertex_buffer_view.BufferLocation);
if (vertex_buffer_mapping == nullptr) {
XELOGE("Failed to get a buffer for {} vertices in the immediate drawer",
batch.vertex_count);
@@ -524,8 +523,7 @@ void D3D12ImmediateDrawer::BeginDrawBatch(const ImmediateDrawBatch& batch) {
index_buffer_view.SizeInBytes = batch.index_count * sizeof(uint16_t);
index_buffer_view.Format = DXGI_FORMAT_R16_UINT;
void* index_buffer_mapping = vertex_buffer_pool_->Request(
current_fence_value,
xe::align(index_buffer_view.SizeInBytes, UINT(sizeof(uint32_t))),
current_fence_value, index_buffer_view.SizeInBytes, sizeof(uint16_t),
nullptr, nullptr, &index_buffer_view.BufferLocation);
if (index_buffer_mapping == nullptr) {
XELOGE("Failed to get a buffer for {} indices in the immediate drawer",

View File

@@ -383,6 +383,14 @@ bool D3D12Provider::Initialize() {
device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
// Check if optional features are supported.
// D3D12_HEAP_FLAG_CREATE_NOT_ZEROED requires Windows 10 2004 (indicated by
// the availability of ID3D12Device8 or D3D12_FEATURE_D3D12_OPTIONS7).
heap_flag_create_not_zeroed_ = D3D12_HEAP_FLAG_NONE;
D3D12_FEATURE_DATA_D3D12_OPTIONS7 options7;
if (SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7,
&options7, sizeof(options7)))) {
heap_flag_create_not_zeroed_ = D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
}
rasterizer_ordered_views_supported_ = false;
resource_binding_tier_ = D3D12_RESOURCE_BINDING_TIER_1;
tiled_resources_tier_ = D3D12_TILED_RESOURCES_TIER_NOT_SUPPORTED;

View File

@@ -68,6 +68,9 @@ class D3D12Provider : public GraphicsProvider {
uint32_t GetAdapterVendorID() const { return adapter_vendor_id_; }
// Device features.
D3D12_HEAP_FLAGS GetHeapFlagCreateNotZeroed() const {
return heap_flag_create_not_zeroed_;
}
D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER
GetProgrammableSamplePositionsTier() const {
return programmable_sample_positions_tier_;
@@ -162,6 +165,7 @@ class D3D12Provider : public GraphicsProvider {
uint32_t adapter_vendor_id_;
D3D12_HEAP_FLAGS heap_flag_create_not_zeroed_;
D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER programmable_sample_positions_tier_;
bool rasterizer_ordered_views_supported_;
D3D12_RESOURCE_BINDING_TIER resource_binding_tier_;

View File

@@ -13,14 +13,20 @@
#include "xenia/base/assert.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/ui/d3d12/d3d12_util.h"
namespace xe {
namespace ui {
namespace d3d12 {
// Align to D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT not to waste any space if
// it's smaller (the size of the heap backing the buffer will be aligned to
// D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT anyway).
UploadBufferPool::UploadBufferPool(D3D12Provider& provider, uint32_t page_size)
: provider_(provider), page_size_(page_size) {}
: provider_(provider),
page_size_(xe::align(
page_size, uint32_t(D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT))) {}
UploadBufferPool::~UploadBufferPool() { ClearCache(); }
@@ -68,9 +74,13 @@ void UploadBufferPool::ClearCache() {
}
uint8_t* UploadBufferPool::Request(uint64_t submission_index, uint32_t size,
uint32_t alignment,
ID3D12Resource** buffer_out,
uint32_t* offset_out,
D3D12_GPU_VIRTUAL_ADDRESS* gpu_address_out) {
assert_not_zero(alignment);
assert_true(xe::is_pow2(alignment));
size = xe::align(size, alignment);
assert_true(size <= page_size_);
if (size > page_size_) {
return nullptr;
@@ -79,7 +89,8 @@ uint8_t* UploadBufferPool::Request(uint64_t submission_index, uint32_t size,
submission_index >= writable_first_->last_submission_index);
assert_true(!submitted_last_ ||
submission_index >= submitted_last_->last_submission_index);
if (page_size_ - current_page_used_ < size || !writable_first_) {
uint32_t current_page_used_aligned = xe::align(current_page_used_, alignment);
if (current_page_used_aligned + size > page_size_ || !writable_first_) {
// Start a new page if can't fit all the bytes or don't have an open page.
if (writable_first_) {
// Close the page that was current.
@@ -128,33 +139,39 @@ uint8_t* UploadBufferPool::Request(uint64_t submission_index, uint32_t size,
writable_last_ = writable_first_;
}
current_page_used_ = 0;
current_page_used_aligned = 0;
}
writable_first_->last_submission_index = submission_index;
if (buffer_out) {
*buffer_out = writable_first_->buffer;
}
if (offset_out) {
*offset_out = current_page_used_;
*offset_out = current_page_used_aligned;
}
if (gpu_address_out) {
*gpu_address_out = writable_first_->gpu_address + current_page_used_;
*gpu_address_out = writable_first_->gpu_address + current_page_used_aligned;
}
uint8_t* mapping =
reinterpret_cast<uint8_t*>(writable_first_->mapping) + current_page_used_;
current_page_used_ += size;
uint8_t* mapping = reinterpret_cast<uint8_t*>(writable_first_->mapping) +
current_page_used_aligned;
current_page_used_ = current_page_used_aligned + size;
return mapping;
}
uint8_t* UploadBufferPool::RequestPartial(
uint64_t submission_index, uint32_t size, ID3D12Resource** buffer_out,
uint32_t* offset_out, uint32_t* size_out,
uint64_t submission_index, uint32_t size, uint32_t alignment,
ID3D12Resource** buffer_out, uint32_t* offset_out, uint32_t* size_out,
D3D12_GPU_VIRTUAL_ADDRESS* gpu_address_out) {
assert_not_zero(alignment);
assert_true(xe::is_pow2(alignment));
size = xe::align(size, alignment);
size = std::min(size, page_size_);
if (current_page_used_ < page_size_) {
size = std::min(size, page_size_ - current_page_used_);
uint32_t current_page_used_aligned = xe::align(current_page_used_, alignment);
if (current_page_used_aligned + alignment <= page_size_) {
size = std::min(
size, (page_size_ - current_page_used_aligned) & ~(alignment - 1));
}
uint8_t* mapping =
Request(submission_index, size, buffer_out, offset_out, gpu_address_out);
uint8_t* mapping = Request(submission_index, size, alignment, buffer_out,
offset_out, gpu_address_out);
if (!mapping) {
return nullptr;
}

View File

@@ -23,7 +23,12 @@ namespace d3d12 {
class UploadBufferPool {
public:
UploadBufferPool(D3D12Provider& provider, uint32_t page_size);
// Taken from the Direct3D 12 MiniEngine sample (LinearAllocator
// kCpuAllocatorPageSize). Large enough for most cases.
static constexpr uint32_t kDefaultPageSize = 2 * 1024 * 1024;
UploadBufferPool(D3D12Provider& provider,
uint32_t page_size = kDefaultPageSize);
~UploadBufferPool();
void Reclaim(uint64_t completed_submission_index);
@@ -31,13 +36,13 @@ class UploadBufferPool {
// Request to write data in a single piece, creating a new page if the current
// one doesn't have enough free space.
uint8_t* Request(uint64_t submission_index, uint32_t size,
uint8_t* Request(uint64_t submission_index, uint32_t size, uint32_t alignment,
ID3D12Resource** buffer_out, uint32_t* offset_out,
D3D12_GPU_VIRTUAL_ADDRESS* gpu_address_out);
// Request to write data in multiple parts, filling the buffer entirely.
uint8_t* RequestPartial(uint64_t submission_index, uint32_t size,
ID3D12Resource** buffer_out, uint32_t* offset_out,
uint32_t* size_out,
uint32_t alignment, ID3D12Resource** buffer_out,
uint32_t* offset_out, uint32_t* size_out,
D3D12_GPU_VIRTUAL_ADDRESS* gpu_address_out);
private: