[D3D12] Refactor descriptors and resolve logging

This commit is contained in:
Triang3l 2018-08-25 22:42:18 +03:00
parent 50470d67a8
commit dba8ab4eed
6 changed files with 103 additions and 102 deletions

View File

@ -377,13 +377,11 @@ uint64_t D3D12CommandProcessor::RequestViewDescriptors(
} }
GetCurrentCommandList()->SetDescriptorHeaps(heap_count, heaps); GetCurrentCommandList()->SetDescriptorHeaps(heap_count, heaps);
} }
uint32_t descriptor_offset = auto provider = GetD3D12Context()->GetD3D12Provider();
descriptor_index * cpu_handle_out = provider->OffsetViewDescriptor(
GetD3D12Context()->GetD3D12Provider()->GetDescriptorSizeView(); view_heap_pool_->GetLastRequestHeapCPUStart(), descriptor_index);
cpu_handle_out.ptr = gpu_handle_out = provider->OffsetViewDescriptor(
view_heap_pool_->GetLastRequestHeapCPUStart().ptr + descriptor_offset; view_heap_pool_->GetLastRequestHeapGPUStart(), descriptor_index);
gpu_handle_out.ptr =
view_heap_pool_->GetLastRequestHeapGPUStart().ptr + descriptor_offset;
return current_full_update; return current_full_update;
} }
@ -413,7 +411,7 @@ uint64_t D3D12CommandProcessor::RequestSamplerDescriptors(
} }
uint32_t descriptor_offset = uint32_t descriptor_offset =
descriptor_index * descriptor_index *
GetD3D12Context()->GetD3D12Provider()->GetDescriptorSizeSampler(); GetD3D12Context()->GetD3D12Provider()->GetSamplerDescriptorSize();
cpu_handle_out.ptr = cpu_handle_out.ptr =
sampler_heap_pool_->GetLastRequestHeapCPUStart().ptr + descriptor_offset; sampler_heap_pool_->GetLastRequestHeapCPUStart().ptr + descriptor_offset;
gpu_handle_out.ptr = gpu_handle_out.ptr =
@ -1619,7 +1617,7 @@ bool D3D12CommandProcessor::UpdateBindings(
uint32_t view_count_full_update = 20 + texture_count; uint32_t view_count_full_update = 20 + texture_count;
D3D12_CPU_DESCRIPTOR_HANDLE view_cpu_handle; D3D12_CPU_DESCRIPTOR_HANDLE view_cpu_handle;
D3D12_GPU_DESCRIPTOR_HANDLE view_gpu_handle; D3D12_GPU_DESCRIPTOR_HANDLE view_gpu_handle;
uint32_t view_handle_size = provider->GetDescriptorSizeView(); uint32_t descriptor_size_view = provider->GetViewDescriptorSize();
uint64_t view_full_update_index = RequestViewDescriptors( uint64_t view_full_update_index = RequestViewDescriptors(
draw_view_full_update_, view_count_partial_update, view_count_full_update, draw_view_full_update_, view_count_partial_update, view_count_full_update,
view_cpu_handle, view_gpu_handle); view_cpu_handle, view_gpu_handle);
@ -1629,7 +1627,7 @@ bool D3D12CommandProcessor::UpdateBindings(
} }
D3D12_CPU_DESCRIPTOR_HANDLE sampler_cpu_handle = {}; D3D12_CPU_DESCRIPTOR_HANDLE sampler_cpu_handle = {};
D3D12_GPU_DESCRIPTOR_HANDLE sampler_gpu_handle = {}; D3D12_GPU_DESCRIPTOR_HANDLE sampler_gpu_handle = {};
uint32_t sampler_handle_size = provider->GetDescriptorSizeSampler(); uint32_t descriptor_size_sampler = provider->GetSamplerDescriptorSize();
uint64_t sampler_full_update_index = 0; uint64_t sampler_full_update_index = 0;
if (sampler_count != 0) { if (sampler_count != 0) {
sampler_full_update_index = RequestSamplerDescriptors( sampler_full_update_index = RequestSamplerDescriptors(
@ -1651,8 +1649,8 @@ bool D3D12CommandProcessor::UpdateBindings(
// If updating fully, write the shared memory descriptor (t0, space1). // If updating fully, write the shared memory descriptor (t0, space1).
shared_memory_->CreateSRV(view_cpu_handle); shared_memory_->CreateSRV(view_cpu_handle);
gpu_handle_shared_memory_ = view_gpu_handle; gpu_handle_shared_memory_ = view_gpu_handle;
view_cpu_handle.ptr += view_handle_size; view_cpu_handle.ptr += descriptor_size_view;
view_gpu_handle.ptr += view_handle_size; view_gpu_handle.ptr += descriptor_size_view;
current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_SharedMemory); current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_SharedMemory);
} }
if (sampler_count != 0 && if (sampler_count != 0 &&
@ -1671,15 +1669,15 @@ bool D3D12CommandProcessor::UpdateBindings(
constant_buffer_desc.SizeInBytes = constant_buffer_desc.SizeInBytes =
xe::align(uint32_t(sizeof(system_constants_)), 256u); xe::align(uint32_t(sizeof(system_constants_)), 256u);
device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle);
view_cpu_handle.ptr += view_handle_size; view_cpu_handle.ptr += descriptor_size_view;
view_gpu_handle.ptr += view_handle_size; view_gpu_handle.ptr += descriptor_size_view;
// Bool/loop constants (b1). // Bool/loop constants (b1).
constant_buffer_desc.BufferLocation = constant_buffer_desc.BufferLocation =
cbuffer_bindings_bool_loop_.buffer_address; cbuffer_bindings_bool_loop_.buffer_address;
constant_buffer_desc.SizeInBytes = 768; constant_buffer_desc.SizeInBytes = 768;
device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle);
view_cpu_handle.ptr += view_handle_size; view_cpu_handle.ptr += descriptor_size_view;
view_gpu_handle.ptr += view_handle_size; view_gpu_handle.ptr += descriptor_size_view;
current_graphics_root_up_to_date_ &= current_graphics_root_up_to_date_ &=
~(1u << kRootParameter_CommonConstants); ~(1u << kRootParameter_CommonConstants);
} }
@ -1690,8 +1688,8 @@ bool D3D12CommandProcessor::UpdateBindings(
cbuffer_bindings_fetch_.buffer_address; cbuffer_bindings_fetch_.buffer_address;
constant_buffer_desc.SizeInBytes = 768; constant_buffer_desc.SizeInBytes = 768;
device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle);
view_cpu_handle.ptr += view_handle_size; view_cpu_handle.ptr += descriptor_size_view;
view_gpu_handle.ptr += view_handle_size; view_gpu_handle.ptr += descriptor_size_view;
current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_FetchConstants); current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_FetchConstants);
} }
if (write_vertex_float_constant_views) { if (write_vertex_float_constant_views) {
@ -1702,8 +1700,8 @@ bool D3D12CommandProcessor::UpdateBindings(
cbuffer_bindings_float_[i].buffer_address; cbuffer_bindings_float_[i].buffer_address;
constant_buffer_desc.SizeInBytes = 512; constant_buffer_desc.SizeInBytes = 512;
device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle);
view_cpu_handle.ptr += view_handle_size; view_cpu_handle.ptr += descriptor_size_view;
view_gpu_handle.ptr += view_handle_size; view_gpu_handle.ptr += descriptor_size_view;
} }
current_graphics_root_up_to_date_ &= current_graphics_root_up_to_date_ &=
~(1u << kRootParameter_VertexFloatConstants); ~(1u << kRootParameter_VertexFloatConstants);
@ -1716,8 +1714,8 @@ bool D3D12CommandProcessor::UpdateBindings(
cbuffer_bindings_float_[8 + i].buffer_address; cbuffer_bindings_float_[8 + i].buffer_address;
constant_buffer_desc.SizeInBytes = 512; constant_buffer_desc.SizeInBytes = 512;
device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle);
view_cpu_handle.ptr += view_handle_size; view_cpu_handle.ptr += descriptor_size_view;
view_gpu_handle.ptr += view_handle_size; view_gpu_handle.ptr += descriptor_size_view;
} }
current_graphics_root_up_to_date_ &= current_graphics_root_up_to_date_ &=
~(1u << kRootParameter_PixelFloatConstants); ~(1u << kRootParameter_PixelFloatConstants);
@ -1731,8 +1729,8 @@ bool D3D12CommandProcessor::UpdateBindings(
const D3D12Shader::TextureSRV& srv = pixel_textures[i]; const D3D12Shader::TextureSRV& srv = pixel_textures[i];
texture_cache_->WriteTextureSRV(srv.fetch_constant, srv.dimension, texture_cache_->WriteTextureSRV(srv.fetch_constant, srv.dimension,
view_cpu_handle); view_cpu_handle);
view_cpu_handle.ptr += view_handle_size; view_cpu_handle.ptr += descriptor_size_view;
view_gpu_handle.ptr += view_handle_size; view_gpu_handle.ptr += descriptor_size_view;
} }
current_graphics_root_up_to_date_ &= current_graphics_root_up_to_date_ &=
~(1u << current_graphics_root_extras_.pixel_textures); ~(1u << current_graphics_root_extras_.pixel_textures);
@ -1745,8 +1743,8 @@ bool D3D12CommandProcessor::UpdateBindings(
const D3D12Shader::TextureSRV& srv = vertex_textures[i]; const D3D12Shader::TextureSRV& srv = vertex_textures[i];
texture_cache_->WriteTextureSRV(srv.fetch_constant, srv.dimension, texture_cache_->WriteTextureSRV(srv.fetch_constant, srv.dimension,
view_cpu_handle); view_cpu_handle);
view_cpu_handle.ptr += view_handle_size; view_cpu_handle.ptr += descriptor_size_view;
view_gpu_handle.ptr += view_handle_size; view_gpu_handle.ptr += descriptor_size_view;
} }
current_graphics_root_up_to_date_ &= current_graphics_root_up_to_date_ &=
~(1u << current_graphics_root_extras_.vertex_textures); ~(1u << current_graphics_root_extras_.vertex_textures);
@ -1759,8 +1757,8 @@ bool D3D12CommandProcessor::UpdateBindings(
gpu_handle_pixel_samplers_ = sampler_gpu_handle; gpu_handle_pixel_samplers_ = sampler_gpu_handle;
for (uint32_t i = 0; i < pixel_sampler_count; ++i) { for (uint32_t i = 0; i < pixel_sampler_count; ++i) {
texture_cache_->WriteSampler(pixel_samplers[i], sampler_cpu_handle); texture_cache_->WriteSampler(pixel_samplers[i], sampler_cpu_handle);
sampler_cpu_handle.ptr += sampler_handle_size; sampler_cpu_handle.ptr += descriptor_size_sampler;
sampler_gpu_handle.ptr += sampler_handle_size; sampler_gpu_handle.ptr += descriptor_size_sampler;
} }
current_graphics_root_up_to_date_ &= current_graphics_root_up_to_date_ &=
~(1u << current_graphics_root_extras_.pixel_samplers); ~(1u << current_graphics_root_extras_.pixel_samplers);
@ -1771,8 +1769,8 @@ bool D3D12CommandProcessor::UpdateBindings(
gpu_handle_vertex_samplers_ = sampler_gpu_handle; gpu_handle_vertex_samplers_ = sampler_gpu_handle;
for (uint32_t i = 0; i < vertex_sampler_count; ++i) { for (uint32_t i = 0; i < vertex_sampler_count; ++i) {
texture_cache_->WriteSampler(vertex_samplers[i], sampler_cpu_handle); texture_cache_->WriteSampler(vertex_samplers[i], sampler_cpu_handle);
sampler_cpu_handle.ptr += sampler_handle_size; sampler_cpu_handle.ptr += descriptor_size_sampler;
sampler_gpu_handle.ptr += sampler_handle_size; sampler_gpu_handle.ptr += descriptor_size_sampler;
} }
current_graphics_root_up_to_date_ &= current_graphics_root_up_to_date_ &=
~(1u << current_graphics_root_extras_.vertex_samplers); ~(1u << current_graphics_root_extras_.vertex_samplers);

View File

@ -982,8 +982,8 @@ bool RenderTargetCache::Resolve(SharedMemory* shared_memory,
} }
XELOGGPU( XELOGGPU(
"Resolving (%d,%d)->(%d,%d) of RT %u (pitch %u, %u sample%s, format " "Resolve: (%d,%d)->(%d,%d) of RT %u (pitch %u, %u sample%s, format %u) "
"%u) at %u", "at %u",
src_rect.left, src_rect.top, src_rect.right, src_rect.bottom, src_rect.left, src_rect.top, src_rect.right, src_rect.bottom,
surface_index, surface_pitch, 1 << uint32_t(msaa_samples), surface_index, surface_pitch, 1 << uint32_t(msaa_samples),
msaa_samples != MsaaSamples::k1X ? "s" : "", surface_format, msaa_samples != MsaaSamples::k1X ? "s" : "", surface_format,
@ -1084,7 +1084,7 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory,
// TODO(Triang3l): Investigate what copy_dest_number is. // TODO(Triang3l): Investigate what copy_dest_number is.
XELOGGPU( XELOGGPU(
"Copying samples %u to 0x%.8X (%ux%u), destination format %s, " "Resolve: Copying samples %u to 0x%.8X (%ux%u), destination format %s, "
"exponent bias %d, red and blue %sswapped", "exponent bias %d, red and blue %sswapped",
uint32_t(sample_select), dest_address, dest_pitch, dest_height, uint32_t(sample_select), dest_address, dest_pitch, dest_height,
FormatInfo::Get(dest_format)->name, dest_exp_bias, FormatInfo::Get(dest_format)->name, dest_exp_bias,
@ -1098,8 +1098,6 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory,
// Nothing to copy. // Nothing to copy.
return true; return true;
} }
XELOGGPU("Pitch is %u tiles, %u rows of %u tiles", surface_pitch_tiles, rows,
row_tiles);
// There are 2 paths for resolving in this function - they don't necessarily // There are 2 paths for resolving in this function - they don't necessarily
// have to map directly to kRaw and kConvert CopyCommands. // have to map directly to kRaw and kConvert CopyCommands.
@ -1119,13 +1117,12 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory,
// RTV of the destination format. // RTV of the destination format.
auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider(); auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider();
auto device = provider->GetDevice(); auto device = provider->GetDevice();
auto descriptor_size_view = provider->GetDescriptorSizeView();
if (sample_select <= xenos::CopySampleSelect::k3 && if (sample_select <= xenos::CopySampleSelect::k3 &&
src_texture_format == dest_format && dest_exp_bias == 0) { src_texture_format == dest_format && dest_exp_bias == 0) {
// ************************************************************************* // *************************************************************************
// Raw copy // Raw copy
// ************************************************************************* // *************************************************************************
XELOGGPU("Resolving a single sample without conversion"); XELOGGPU("Resolve: Copying using a compute shader");
if (src_64bpp) { if (src_64bpp) {
// TODO(Triang3l): 64bpp sample copy shader. // TODO(Triang3l): 64bpp sample copy shader.
return false; return false;
@ -1153,9 +1150,8 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory,
srv_desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW; srv_desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
device->CreateShaderResourceView(edram_buffer_, &srv_desc, device->CreateShaderResourceView(edram_buffer_, &srv_desc,
descriptor_cpu_start); descriptor_cpu_start);
D3D12_CPU_DESCRIPTOR_HANDLE uav_cpu_handle; shared_memory->CreateRawUAV(
uav_cpu_handle.ptr = descriptor_cpu_start.ptr + descriptor_size_view; provider->OffsetViewDescriptor(descriptor_cpu_start, 1));
shared_memory->CreateRawUAV(uav_cpu_handle);
// Transition the buffers. // Transition the buffers.
command_processor_->PushTransitionBarrier( command_processor_->PushTransitionBarrier(
@ -1227,7 +1223,7 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory,
// ************************************************************************* // *************************************************************************
// Conversion and AA resolving // Conversion and AA resolving
// ************************************************************************* // *************************************************************************
XELOGGPU("Resolving with a pixel shader"); XELOGGPU("Resolve: Copying via drawing");
// Get everything we need for the conversion. // Get everything we need for the conversion.
@ -1326,11 +1322,9 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory,
uav_desc.Buffer.StructureByteStride = 0; uav_desc.Buffer.StructureByteStride = 0;
uav_desc.Buffer.CounterOffsetInBytes = 0; uav_desc.Buffer.CounterOffsetInBytes = 0;
uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
D3D12_CPU_DESCRIPTOR_HANDLE copy_buffer_cpu_handle; device->CreateUnorderedAccessView(
copy_buffer_cpu_handle.ptr = copy_buffer, nullptr, &uav_desc,
descriptor_cpu_start.ptr + descriptor_size_view; provider->OffsetViewDescriptor(descriptor_cpu_start, 1));
device->CreateUnorderedAccessView(copy_buffer, nullptr, &uav_desc,
copy_buffer_cpu_handle);
command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start); command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start);
command_processor_->SetComputePipeline( command_processor_->SetComputePipeline(
@ -1340,8 +1334,10 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory,
// Go to the next descriptor set. // Go to the next descriptor set.
descriptor_cpu_start.ptr += 2 * descriptor_size_view; descriptor_cpu_start =
descriptor_gpu_start.ptr += 2 * descriptor_size_view; provider->OffsetViewDescriptor(descriptor_cpu_start, 2);
descriptor_gpu_start =
provider->OffsetViewDescriptor(descriptor_gpu_start, 2);
// Copy the EDRAM buffer contents to the source texture. // Copy the EDRAM buffer contents to the source texture.
@ -1540,6 +1536,8 @@ bool RenderTargetCache::ResolveClear(uint32_t edram_base,
return true; return true;
} }
XELOGGPU("Resolve: Clearing the render target");
// Calculate the layout. // Calculate the layout.
bool is_64bpp = bool is_64bpp =
!is_depth && IsColorFormat64bpp(ColorRenderTargetFormat(format)); !is_depth && IsColorFormat64bpp(ColorRenderTargetFormat(format));
@ -1752,10 +1750,9 @@ RenderTargetCache::ResolveTarget* RenderTargetCache::FindOrCreateResolveTarget(
} }
// Create the RTV. // Create the RTV.
D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle; D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle =
rtv_handle.ptr = descriptor_heaps_color_->start_handle.ptr + provider->OffsetRTVDescriptor(descriptor_heaps_color_->start_handle,
descriptor_heaps_color_->descriptors_used * descriptor_heaps_color_->descriptors_used);
provider->GetDescriptorSizeRTV();
D3D12_RENDER_TARGET_VIEW_DESC rtv_desc; D3D12_RENDER_TARGET_VIEW_DESC rtv_desc;
rtv_desc.Format = format; rtv_desc.Format = format;
rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
@ -1967,9 +1964,9 @@ RenderTargetCache::RenderTarget* RenderTargetCache::FindOrCreateRenderTarget(
// Create the descriptor for the render target. // Create the descriptor for the render target.
D3D12_CPU_DESCRIPTOR_HANDLE descriptor_handle; D3D12_CPU_DESCRIPTOR_HANDLE descriptor_handle;
if (key.is_depth) { if (key.is_depth) {
descriptor_handle.ptr = descriptor_heaps_depth_->start_handle.ptr + descriptor_handle = provider->OffsetDSVDescriptor(
descriptor_heaps_depth_->descriptors_used * descriptor_heaps_depth_->start_handle,
provider->GetDescriptorSizeDSV(); descriptor_heaps_depth_->descriptors_used);
D3D12_DEPTH_STENCIL_VIEW_DESC dsv_desc; D3D12_DEPTH_STENCIL_VIEW_DESC dsv_desc;
dsv_desc.Format = resource_desc.Format; dsv_desc.Format = resource_desc.Format;
dsv_desc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; dsv_desc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
@ -1978,9 +1975,9 @@ RenderTargetCache::RenderTarget* RenderTargetCache::FindOrCreateRenderTarget(
device->CreateDepthStencilView(resource, &dsv_desc, descriptor_handle); device->CreateDepthStencilView(resource, &dsv_desc, descriptor_handle);
++descriptor_heaps_depth_->descriptors_used; ++descriptor_heaps_depth_->descriptors_used;
} else { } else {
descriptor_handle.ptr = descriptor_heaps_color_->start_handle.ptr + descriptor_handle = provider->OffsetRTVDescriptor(
descriptor_heaps_color_->descriptors_used * descriptor_heaps_color_->start_handle,
provider->GetDescriptorSizeRTV(); descriptor_heaps_color_->descriptors_used);
D3D12_RENDER_TARGET_VIEW_DESC rtv_desc; D3D12_RENDER_TARGET_VIEW_DESC rtv_desc;
rtv_desc.Format = resource_desc.Format; rtv_desc.Format = resource_desc.Format;
rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
@ -2148,7 +2145,6 @@ void RenderTargetCache::StoreRenderTargetsToEDRAM() {
// Prepare for storing. // Prepare for storing.
auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider(); auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider();
auto device = provider->GetDevice(); auto device = provider->GetDevice();
auto descriptor_size_view = provider->GetDescriptorSizeView();
D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc; D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc;
srv_desc.Format = DXGI_FORMAT_R32_TYPELESS; srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
srv_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; srv_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
@ -2167,10 +2163,9 @@ void RenderTargetCache::StoreRenderTargetsToEDRAM() {
uav_desc.Buffer.StructureByteStride = 0; uav_desc.Buffer.StructureByteStride = 0;
uav_desc.Buffer.CounterOffsetInBytes = 0; uav_desc.Buffer.CounterOffsetInBytes = 0;
uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
D3D12_CPU_DESCRIPTOR_HANDLE uav_cpu_handle; device->CreateUnorderedAccessView(
uav_cpu_handle.ptr = descriptor_cpu_start.ptr + descriptor_size_view; edram_buffer_, nullptr, &uav_desc,
device->CreateUnorderedAccessView(edram_buffer_, nullptr, &uav_desc, provider->OffsetViewDescriptor(descriptor_cpu_start, 1));
uav_cpu_handle);
command_list->SetComputeRootSignature(edram_load_store_root_signature_); command_list->SetComputeRootSignature(edram_load_store_root_signature_);
command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start); command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start);
@ -2316,7 +2311,6 @@ void RenderTargetCache::LoadRenderTargetsFromEDRAM(
// Set up the bindings. // Set up the bindings.
auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider(); auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider();
auto device = provider->GetDevice(); auto device = provider->GetDevice();
auto descriptor_size_view = provider->GetDescriptorSizeView();
D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc; D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc;
srv_desc.Format = DXGI_FORMAT_R32_TYPELESS; srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
srv_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; srv_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
@ -2335,10 +2329,9 @@ void RenderTargetCache::LoadRenderTargetsFromEDRAM(
uav_desc.Buffer.StructureByteStride = 0; uav_desc.Buffer.StructureByteStride = 0;
uav_desc.Buffer.CounterOffsetInBytes = 0; uav_desc.Buffer.CounterOffsetInBytes = 0;
uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
D3D12_CPU_DESCRIPTOR_HANDLE uav_cpu_handle; device->CreateUnorderedAccessView(
uav_cpu_handle.ptr = descriptor_cpu_start.ptr + descriptor_size_view; copy_buffer, nullptr, &uav_desc,
device->CreateUnorderedAccessView(copy_buffer, nullptr, &uav_desc, provider->OffsetViewDescriptor(descriptor_cpu_start, 1));
uav_cpu_handle);
command_list->SetComputeRootSignature(edram_load_store_root_signature_); command_list->SetComputeRootSignature(edram_load_store_root_signature_);
command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start); command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start);

View File

@ -638,10 +638,8 @@ bool TextureCache::TileResolvedTexture(
srv_desc.Buffer.StructureByteStride = 0; srv_desc.Buffer.StructureByteStride = 0;
srv_desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW; srv_desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
device->CreateShaderResourceView(buffer, &srv_desc, descriptor_cpu_start); device->CreateShaderResourceView(buffer, &srv_desc, descriptor_cpu_start);
D3D12_CPU_DESCRIPTOR_HANDLE uav_cpu_handle; shared_memory_->CreateRawUAV(
uav_cpu_handle.ptr = provider->OffsetViewDescriptor(descriptor_cpu_start, 1));
descriptor_cpu_start.ptr + provider->GetDescriptorSizeView();
shared_memory_->CreateRawUAV(uav_cpu_handle);
command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start); command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start);
command_processor_->SetComputePipeline(tile_pipelines_[uint32_t(tile_mode)]); command_processor_->SetComputePipeline(tile_pipelines_[uint32_t(tile_mode)]);
command_list->Dispatch((resolve_width + 31) >> 5, (resolve_height + 31) >> 5, command_list->Dispatch((resolve_width + 31) >> 5, (resolve_height + 31) >> 5,
@ -1028,11 +1026,9 @@ bool TextureCache::LoadTextureData(Texture* texture) {
uav_desc.Buffer.StructureByteStride = 0; uav_desc.Buffer.StructureByteStride = 0;
uav_desc.Buffer.CounterOffsetInBytes = 0; uav_desc.Buffer.CounterOffsetInBytes = 0;
uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
D3D12_CPU_DESCRIPTOR_HANDLE descriptor_cpu_uav; device->CreateUnorderedAccessView(
descriptor_cpu_uav.ptr = copy_buffer, nullptr, &uav_desc,
descriptor_cpu_start.ptr + provider->GetDescriptorSizeView(); provider->OffsetViewDescriptor(descriptor_cpu_start, 1));
device->CreateUnorderedAccessView(copy_buffer, nullptr, &uav_desc,
descriptor_cpu_uav);
command_processor_->SetComputePipeline(pipeline); command_processor_->SetComputePipeline(pipeline);
command_list->SetComputeRootSignature(load_root_signature_); command_list->SetComputeRootSignature(load_root_signature_);
command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start); command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start);

View File

@ -342,9 +342,8 @@ void D3D12Context::AwaitAllFramesCompletion() {
D3D12_CPU_DESCRIPTOR_HANDLE D3D12Context::GetSwapChainBufferRTV( D3D12_CPU_DESCRIPTOR_HANDLE D3D12Context::GetSwapChainBufferRTV(
uint32_t buffer_index) const { uint32_t buffer_index) const {
D3D12_CPU_DESCRIPTOR_HANDLE handle = swap_chain_rtv_heap_start_; return GetD3D12Provider()->OffsetRTVDescriptor(swap_chain_rtv_heap_start_,
handle.ptr += buffer_index * GetD3D12Provider()->GetDescriptorSizeRTV(); buffer_index);
return handle;
} }
} // namespace d3d12 } // namespace d3d12

View File

@ -266,7 +266,7 @@ bool D3D12ImmediateDrawer::Initialize() {
} }
sampler_heap_cpu_start_ = sampler_heap_->GetCPUDescriptorHandleForHeapStart(); sampler_heap_cpu_start_ = sampler_heap_->GetCPUDescriptorHandleForHeapStart();
sampler_heap_gpu_start_ = sampler_heap_->GetGPUDescriptorHandleForHeapStart(); sampler_heap_gpu_start_ = sampler_heap_->GetGPUDescriptorHandleForHeapStart();
uint32_t sampler_size = provider->GetDescriptorSizeSampler(); uint32_t sampler_size = provider->GetSamplerDescriptorSize();
// Nearest neighbor, clamp. // Nearest neighbor, clamp.
D3D12_SAMPLER_DESC sampler_desc; D3D12_SAMPLER_DESC sampler_desc;
sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT; sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
@ -616,7 +616,6 @@ void D3D12ImmediateDrawer::Draw(const ImmediateDraw& draw) {
current_command_list_->SetDescriptorHeaps(2, descriptor_heaps); current_command_list_->SetDescriptorHeaps(2, descriptor_heaps);
} }
if (bind_texture) { if (bind_texture) {
auto descriptor_size_view = provider->GetDescriptorSizeView();
D3D12_SHADER_RESOURCE_VIEW_DESC texture_view_desc; D3D12_SHADER_RESOURCE_VIEW_DESC texture_view_desc;
texture_view_desc.Format = D3D12ImmediateTexture::kFormat; texture_view_desc.Format = D3D12ImmediateTexture::kFormat;
texture_view_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; texture_view_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
@ -626,18 +625,16 @@ void D3D12ImmediateDrawer::Draw(const ImmediateDraw& draw) {
texture_view_desc.Texture2D.MipLevels = 1; texture_view_desc.Texture2D.MipLevels = 1;
texture_view_desc.Texture2D.PlaneSlice = 0; texture_view_desc.Texture2D.PlaneSlice = 0;
texture_view_desc.Texture2D.ResourceMinLODClamp = 0.0f; texture_view_desc.Texture2D.ResourceMinLODClamp = 0.0f;
D3D12_CPU_DESCRIPTOR_HANDLE texture_view_cpu_handle; device->CreateShaderResourceView(
texture_view_cpu_handle.ptr = texture_resource, &texture_view_desc,
texture_descriptor_pool_->GetLastRequestHeapCPUStart().ptr + provider->OffsetViewDescriptor(
texture_descriptor_index * descriptor_size_view; texture_descriptor_pool_->GetLastRequestHeapCPUStart(),
device->CreateShaderResourceView(texture_resource, &texture_view_desc, texture_descriptor_index));
texture_view_cpu_handle);
D3D12_GPU_DESCRIPTOR_HANDLE texture_view_gpu_handle;
texture_view_gpu_handle.ptr =
texture_descriptor_pool_->GetLastRequestHeapGPUStart().ptr +
texture_descriptor_index * descriptor_size_view;
current_command_list_->SetGraphicsRootDescriptorTable( current_command_list_->SetGraphicsRootDescriptorTable(
UINT(RootParameter::kTexture), texture_view_gpu_handle); UINT(RootParameter::kTexture),
provider->OffsetViewDescriptor(
texture_descriptor_pool_->GetLastRequestHeapGPUStart(),
texture_descriptor_index));
current_texture_ = texture; current_texture_ = texture;
} }
@ -655,12 +652,10 @@ void D3D12ImmediateDrawer::Draw(const ImmediateDraw& draw) {
sampler_index = SamplerIndex::kNearestClamp; sampler_index = SamplerIndex::kNearestClamp;
} }
if (current_sampler_index_ != sampler_index) { if (current_sampler_index_ != sampler_index) {
D3D12_GPU_DESCRIPTOR_HANDLE sampler_gpu_handle;
sampler_gpu_handle.ptr =
sampler_heap_gpu_start_.ptr +
UINT(sampler_index) * provider->GetDescriptorSizeSampler();
current_command_list_->SetGraphicsRootDescriptorTable( current_command_list_->SetGraphicsRootDescriptorTable(
UINT(RootParameter::kSampler), sampler_gpu_handle); UINT(RootParameter::kSampler),
provider->OffsetSamplerDescriptor(sampler_heap_gpu_start_,
uint32_t(sampler_index)));
current_sampler_index_ = sampler_index; current_sampler_index_ = sampler_index;
} }

View File

@ -33,10 +33,30 @@ class D3D12Provider : public GraphicsProvider {
ID3D12Device* GetDevice() const { return device_; } ID3D12Device* GetDevice() const { return device_; }
ID3D12CommandQueue* GetDirectQueue() const { return direct_queue_; } ID3D12CommandQueue* GetDirectQueue() const { return direct_queue_; }
uint32_t GetDescriptorSizeView() const { return descriptor_size_view_; } uint32_t GetViewDescriptorSize() const { return descriptor_size_view_; }
uint32_t GetDescriptorSizeSampler() const { return descriptor_size_sampler_; } uint32_t GetSamplerDescriptorSize() const { return descriptor_size_sampler_; }
uint32_t GetDescriptorSizeRTV() const { return descriptor_size_rtv_; } uint32_t GetRTVDescriptorSize() const { return descriptor_size_rtv_; }
uint32_t GetDescriptorSizeDSV() const { return descriptor_size_dsv_; } uint32_t GetDSVDescriptorSize() const { return descriptor_size_dsv_; }
template <typename T>
inline T OffsetViewDescriptor(T start, uint32_t index) const {
start.ptr += index * descriptor_size_view_;
return start;
}
template <typename T>
inline T OffsetSamplerDescriptor(T start, uint32_t index) const {
start.ptr += index * descriptor_size_sampler_;
return start;
}
template <typename T>
inline T OffsetRTVDescriptor(T start, uint32_t index) const {
start.ptr += index * descriptor_size_rtv_;
return start;
}
template <typename T>
inline T OffsetDSVDescriptor(T start, uint32_t index) const {
start.ptr += index * descriptor_size_dsv_;
return start;
}
uint32_t GetProgrammableSamplePositionsTier() const { uint32_t GetProgrammableSamplePositionsTier() const {
return programmable_sample_positions_tier_; return programmable_sample_positions_tier_;