[D3D12] System constant setting and some cleanup

This commit is contained in:
Triang3l
2018-07-31 16:17:51 +03:00
parent 2183a969af
commit fb1051b610
7 changed files with 363 additions and 47 deletions

View File

@@ -65,9 +65,9 @@ void UploadBufferPool::ClearCache() {
sent_last_ = nullptr;
}
uint8_t* UploadBufferPool::RequestFull(uint32_t size,
ID3D12Resource*& buffer_out,
uint32_t& offset_out) {
uint8_t* UploadBufferPool::RequestFull(
uint32_t size, ID3D12Resource** buffer_out, uint32_t* offset_out,
D3D12_GPU_VIRTUAL_ADDRESS* gpu_address_out) {
assert_true(size <= page_size_);
if (size > page_size_) {
return nullptr;
@@ -78,17 +78,26 @@ uint8_t* UploadBufferPool::RequestFull(uint32_t size,
return nullptr;
}
}
buffer_out = unsent_->buffer;
offset_out = current_size_;
if (buffer_out != nullptr) {
*buffer_out = unsent_->buffer;
}
if (offset_out != nullptr) {
*offset_out = current_size_;
}
if (gpu_address_out != nullptr) {
if (current_gpu_address_ == 0) {
current_gpu_address_ = unsent_->buffer->GetGPUVirtualAddress();
}
*gpu_address_out = current_gpu_address_ = current_size_;
}
uint8_t* mapping = current_mapping_ + current_size_;
current_size_ += size;
return mapping;
}
uint8_t* UploadBufferPool::RequestPartial(uint32_t size,
ID3D12Resource*& buffer_out,
uint32_t& offset_out,
uint32_t& size_out) {
uint8_t* UploadBufferPool::RequestPartial(
uint32_t size, ID3D12Resource** buffer_out, uint32_t* offset_out,
uint32_t* size_out, D3D12_GPU_VIRTUAL_ADDRESS* gpu_address_out) {
if (current_size_ == page_size_ || current_mapping_ == nullptr) {
// Start a new page if can't fit any bytes or don't have an open page.
if (!BeginNextPage()) {
@@ -96,9 +105,21 @@ uint8_t* UploadBufferPool::RequestPartial(uint32_t size,
}
}
size = std::min(size, page_size_ - current_size_);
buffer_out = unsent_->buffer;
offset_out = current_size_;
size_out = size;
if (buffer_out != nullptr) {
*buffer_out = unsent_->buffer;
}
if (offset_out != nullptr) {
*offset_out = current_size_;
}
if (size_out != nullptr) {
*size_out = size;
}
if (gpu_address_out != nullptr) {
if (current_gpu_address_ == 0) {
current_gpu_address_ = unsent_->buffer->GetGPUVirtualAddress();
}
*gpu_address_out = current_gpu_address_ = current_size_;
}
uint8_t* mapping = current_mapping_ + current_size_;
current_size_ += size;
return mapping;
@@ -174,6 +195,7 @@ bool UploadBufferPool::BeginNextPage() {
return false;
}
current_mapping_ = reinterpret_cast<uint8_t*>(mapping);
current_gpu_address_ = 0;
return true;
}

View File

@@ -28,11 +28,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* RequestFull(uint32_t size, ID3D12Resource*& buffer_out,
uint32_t& offset_out);
uint8_t* RequestFull(uint32_t size, 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(uint32_t size, ID3D12Resource*& buffer_out,
uint32_t& offset_out, uint32_t& size_out);
uint8_t* RequestPartial(uint32_t size, ID3D12Resource** buffer_out,
uint32_t* offset_out, uint32_t* size_out,
D3D12_GPU_VIRTUAL_ADDRESS* gpu_address_out);
private:
D3D12Context* context_;
@@ -55,6 +57,8 @@ class UploadBufferPool {
uint32_t current_size_ = 0;
uint8_t* current_mapping_ = nullptr;
// Not updated until actually requested.
D3D12_GPU_VIRTUAL_ADDRESS current_gpu_address_ = 0;
// Reset in the beginning of a frame - don't try and fail to create a new page
// if failed to create one in the current frame.