diff --git a/src/xenia/gpu/d3d12/d3d12_command_processor.cc b/src/xenia/gpu/d3d12/d3d12_command_processor.cc index f6e3e0a96..26351efcd 100644 --- a/src/xenia/gpu/d3d12/d3d12_command_processor.cc +++ b/src/xenia/gpu/d3d12/d3d12_command_processor.cc @@ -377,13 +377,11 @@ uint64_t D3D12CommandProcessor::RequestViewDescriptors( } GetCurrentCommandList()->SetDescriptorHeaps(heap_count, heaps); } - uint32_t descriptor_offset = - descriptor_index * - GetD3D12Context()->GetD3D12Provider()->GetDescriptorSizeView(); - cpu_handle_out.ptr = - view_heap_pool_->GetLastRequestHeapCPUStart().ptr + descriptor_offset; - gpu_handle_out.ptr = - view_heap_pool_->GetLastRequestHeapGPUStart().ptr + descriptor_offset; + auto provider = GetD3D12Context()->GetD3D12Provider(); + cpu_handle_out = provider->OffsetViewDescriptor( + view_heap_pool_->GetLastRequestHeapCPUStart(), descriptor_index); + gpu_handle_out = provider->OffsetViewDescriptor( + view_heap_pool_->GetLastRequestHeapGPUStart(), descriptor_index); return current_full_update; } @@ -413,7 +411,7 @@ uint64_t D3D12CommandProcessor::RequestSamplerDescriptors( } uint32_t descriptor_offset = descriptor_index * - GetD3D12Context()->GetD3D12Provider()->GetDescriptorSizeSampler(); + GetD3D12Context()->GetD3D12Provider()->GetSamplerDescriptorSize(); cpu_handle_out.ptr = sampler_heap_pool_->GetLastRequestHeapCPUStart().ptr + descriptor_offset; gpu_handle_out.ptr = @@ -1619,7 +1617,7 @@ bool D3D12CommandProcessor::UpdateBindings( uint32_t view_count_full_update = 20 + texture_count; D3D12_CPU_DESCRIPTOR_HANDLE view_cpu_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( draw_view_full_update_, view_count_partial_update, view_count_full_update, view_cpu_handle, view_gpu_handle); @@ -1629,7 +1627,7 @@ bool D3D12CommandProcessor::UpdateBindings( } D3D12_CPU_DESCRIPTOR_HANDLE sampler_cpu_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; if (sampler_count != 0) { sampler_full_update_index = RequestSamplerDescriptors( @@ -1651,8 +1649,8 @@ bool D3D12CommandProcessor::UpdateBindings( // If updating fully, write the shared memory descriptor (t0, space1). shared_memory_->CreateSRV(view_cpu_handle); gpu_handle_shared_memory_ = view_gpu_handle; - view_cpu_handle.ptr += view_handle_size; - view_gpu_handle.ptr += view_handle_size; + view_cpu_handle.ptr += descriptor_size_view; + view_gpu_handle.ptr += descriptor_size_view; current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_SharedMemory); } if (sampler_count != 0 && @@ -1671,15 +1669,15 @@ bool D3D12CommandProcessor::UpdateBindings( constant_buffer_desc.SizeInBytes = xe::align(uint32_t(sizeof(system_constants_)), 256u); device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); - view_cpu_handle.ptr += view_handle_size; - view_gpu_handle.ptr += view_handle_size; + view_cpu_handle.ptr += descriptor_size_view; + view_gpu_handle.ptr += descriptor_size_view; // Bool/loop constants (b1). constant_buffer_desc.BufferLocation = cbuffer_bindings_bool_loop_.buffer_address; constant_buffer_desc.SizeInBytes = 768; device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); - view_cpu_handle.ptr += view_handle_size; - view_gpu_handle.ptr += view_handle_size; + view_cpu_handle.ptr += descriptor_size_view; + view_gpu_handle.ptr += descriptor_size_view; current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_CommonConstants); } @@ -1690,8 +1688,8 @@ bool D3D12CommandProcessor::UpdateBindings( cbuffer_bindings_fetch_.buffer_address; constant_buffer_desc.SizeInBytes = 768; device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); - view_cpu_handle.ptr += view_handle_size; - view_gpu_handle.ptr += view_handle_size; + view_cpu_handle.ptr += descriptor_size_view; + view_gpu_handle.ptr += descriptor_size_view; current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_FetchConstants); } if (write_vertex_float_constant_views) { @@ -1702,8 +1700,8 @@ bool D3D12CommandProcessor::UpdateBindings( cbuffer_bindings_float_[i].buffer_address; constant_buffer_desc.SizeInBytes = 512; device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); - view_cpu_handle.ptr += view_handle_size; - view_gpu_handle.ptr += view_handle_size; + view_cpu_handle.ptr += descriptor_size_view; + view_gpu_handle.ptr += descriptor_size_view; } current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_VertexFloatConstants); @@ -1716,8 +1714,8 @@ bool D3D12CommandProcessor::UpdateBindings( cbuffer_bindings_float_[8 + i].buffer_address; constant_buffer_desc.SizeInBytes = 512; device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); - view_cpu_handle.ptr += view_handle_size; - view_gpu_handle.ptr += view_handle_size; + view_cpu_handle.ptr += descriptor_size_view; + view_gpu_handle.ptr += descriptor_size_view; } current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_PixelFloatConstants); @@ -1731,8 +1729,8 @@ bool D3D12CommandProcessor::UpdateBindings( const D3D12Shader::TextureSRV& srv = pixel_textures[i]; texture_cache_->WriteTextureSRV(srv.fetch_constant, srv.dimension, view_cpu_handle); - view_cpu_handle.ptr += view_handle_size; - view_gpu_handle.ptr += view_handle_size; + view_cpu_handle.ptr += descriptor_size_view; + view_gpu_handle.ptr += descriptor_size_view; } current_graphics_root_up_to_date_ &= ~(1u << current_graphics_root_extras_.pixel_textures); @@ -1745,8 +1743,8 @@ bool D3D12CommandProcessor::UpdateBindings( const D3D12Shader::TextureSRV& srv = vertex_textures[i]; texture_cache_->WriteTextureSRV(srv.fetch_constant, srv.dimension, view_cpu_handle); - view_cpu_handle.ptr += view_handle_size; - view_gpu_handle.ptr += view_handle_size; + view_cpu_handle.ptr += descriptor_size_view; + view_gpu_handle.ptr += descriptor_size_view; } current_graphics_root_up_to_date_ &= ~(1u << current_graphics_root_extras_.vertex_textures); @@ -1759,8 +1757,8 @@ bool D3D12CommandProcessor::UpdateBindings( gpu_handle_pixel_samplers_ = sampler_gpu_handle; for (uint32_t i = 0; i < pixel_sampler_count; ++i) { texture_cache_->WriteSampler(pixel_samplers[i], sampler_cpu_handle); - sampler_cpu_handle.ptr += sampler_handle_size; - sampler_gpu_handle.ptr += sampler_handle_size; + sampler_cpu_handle.ptr += descriptor_size_sampler; + sampler_gpu_handle.ptr += descriptor_size_sampler; } current_graphics_root_up_to_date_ &= ~(1u << current_graphics_root_extras_.pixel_samplers); @@ -1771,8 +1769,8 @@ bool D3D12CommandProcessor::UpdateBindings( gpu_handle_vertex_samplers_ = sampler_gpu_handle; for (uint32_t i = 0; i < vertex_sampler_count; ++i) { texture_cache_->WriteSampler(vertex_samplers[i], sampler_cpu_handle); - sampler_cpu_handle.ptr += sampler_handle_size; - sampler_gpu_handle.ptr += sampler_handle_size; + sampler_cpu_handle.ptr += descriptor_size_sampler; + sampler_gpu_handle.ptr += descriptor_size_sampler; } current_graphics_root_up_to_date_ &= ~(1u << current_graphics_root_extras_.vertex_samplers); diff --git a/src/xenia/gpu/d3d12/render_target_cache.cc b/src/xenia/gpu/d3d12/render_target_cache.cc index c9892406c..92fc48467 100644 --- a/src/xenia/gpu/d3d12/render_target_cache.cc +++ b/src/xenia/gpu/d3d12/render_target_cache.cc @@ -982,8 +982,8 @@ bool RenderTargetCache::Resolve(SharedMemory* shared_memory, } XELOGGPU( - "Resolving (%d,%d)->(%d,%d) of RT %u (pitch %u, %u sample%s, format " - "%u) at %u", + "Resolve: (%d,%d)->(%d,%d) of RT %u (pitch %u, %u sample%s, format %u) " + "at %u", src_rect.left, src_rect.top, src_rect.right, src_rect.bottom, surface_index, surface_pitch, 1 << uint32_t(msaa_samples), 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. 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", uint32_t(sample_select), dest_address, dest_pitch, dest_height, FormatInfo::Get(dest_format)->name, dest_exp_bias, @@ -1098,8 +1098,6 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory, // Nothing to copy. 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 // have to map directly to kRaw and kConvert CopyCommands. @@ -1119,13 +1117,12 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory, // RTV of the destination format. auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider(); auto device = provider->GetDevice(); - auto descriptor_size_view = provider->GetDescriptorSizeView(); if (sample_select <= xenos::CopySampleSelect::k3 && src_texture_format == dest_format && dest_exp_bias == 0) { // ************************************************************************* // Raw copy // ************************************************************************* - XELOGGPU("Resolving a single sample without conversion"); + XELOGGPU("Resolve: Copying using a compute shader"); if (src_64bpp) { // TODO(Triang3l): 64bpp sample copy shader. return false; @@ -1153,9 +1150,8 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory, srv_desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW; device->CreateShaderResourceView(edram_buffer_, &srv_desc, descriptor_cpu_start); - D3D12_CPU_DESCRIPTOR_HANDLE uav_cpu_handle; - uav_cpu_handle.ptr = descriptor_cpu_start.ptr + descriptor_size_view; - shared_memory->CreateRawUAV(uav_cpu_handle); + shared_memory->CreateRawUAV( + provider->OffsetViewDescriptor(descriptor_cpu_start, 1)); // Transition the buffers. command_processor_->PushTransitionBarrier( @@ -1227,7 +1223,7 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory, // ************************************************************************* // Conversion and AA resolving // ************************************************************************* - XELOGGPU("Resolving with a pixel shader"); + XELOGGPU("Resolve: Copying via drawing"); // 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.CounterOffsetInBytes = 0; uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; - D3D12_CPU_DESCRIPTOR_HANDLE copy_buffer_cpu_handle; - copy_buffer_cpu_handle.ptr = - descriptor_cpu_start.ptr + descriptor_size_view; - device->CreateUnorderedAccessView(copy_buffer, nullptr, &uav_desc, - copy_buffer_cpu_handle); + device->CreateUnorderedAccessView( + copy_buffer, nullptr, &uav_desc, + provider->OffsetViewDescriptor(descriptor_cpu_start, 1)); command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start); command_processor_->SetComputePipeline( @@ -1340,8 +1334,10 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory, // Go to the next descriptor set. - descriptor_cpu_start.ptr += 2 * descriptor_size_view; - descriptor_gpu_start.ptr += 2 * descriptor_size_view; + descriptor_cpu_start = + provider->OffsetViewDescriptor(descriptor_cpu_start, 2); + descriptor_gpu_start = + provider->OffsetViewDescriptor(descriptor_gpu_start, 2); // Copy the EDRAM buffer contents to the source texture. @@ -1540,6 +1536,8 @@ bool RenderTargetCache::ResolveClear(uint32_t edram_base, return true; } + XELOGGPU("Resolve: Clearing the render target"); + // Calculate the layout. bool is_64bpp = !is_depth && IsColorFormat64bpp(ColorRenderTargetFormat(format)); @@ -1752,10 +1750,9 @@ RenderTargetCache::ResolveTarget* RenderTargetCache::FindOrCreateResolveTarget( } // Create the RTV. - D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle; - rtv_handle.ptr = descriptor_heaps_color_->start_handle.ptr + - descriptor_heaps_color_->descriptors_used * - provider->GetDescriptorSizeRTV(); + D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle = + provider->OffsetRTVDescriptor(descriptor_heaps_color_->start_handle, + descriptor_heaps_color_->descriptors_used); D3D12_RENDER_TARGET_VIEW_DESC rtv_desc; rtv_desc.Format = format; rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; @@ -1967,9 +1964,9 @@ RenderTargetCache::RenderTarget* RenderTargetCache::FindOrCreateRenderTarget( // Create the descriptor for the render target. D3D12_CPU_DESCRIPTOR_HANDLE descriptor_handle; if (key.is_depth) { - descriptor_handle.ptr = descriptor_heaps_depth_->start_handle.ptr + - descriptor_heaps_depth_->descriptors_used * - provider->GetDescriptorSizeDSV(); + descriptor_handle = provider->OffsetDSVDescriptor( + descriptor_heaps_depth_->start_handle, + descriptor_heaps_depth_->descriptors_used); D3D12_DEPTH_STENCIL_VIEW_DESC dsv_desc; dsv_desc.Format = resource_desc.Format; dsv_desc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; @@ -1978,9 +1975,9 @@ RenderTargetCache::RenderTarget* RenderTargetCache::FindOrCreateRenderTarget( device->CreateDepthStencilView(resource, &dsv_desc, descriptor_handle); ++descriptor_heaps_depth_->descriptors_used; } else { - descriptor_handle.ptr = descriptor_heaps_color_->start_handle.ptr + - descriptor_heaps_color_->descriptors_used * - provider->GetDescriptorSizeRTV(); + descriptor_handle = provider->OffsetRTVDescriptor( + descriptor_heaps_color_->start_handle, + descriptor_heaps_color_->descriptors_used); D3D12_RENDER_TARGET_VIEW_DESC rtv_desc; rtv_desc.Format = resource_desc.Format; rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; @@ -2148,7 +2145,6 @@ void RenderTargetCache::StoreRenderTargetsToEDRAM() { // Prepare for storing. auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider(); auto device = provider->GetDevice(); - auto descriptor_size_view = provider->GetDescriptorSizeView(); D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc; srv_desc.Format = DXGI_FORMAT_R32_TYPELESS; srv_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; @@ -2167,10 +2163,9 @@ void RenderTargetCache::StoreRenderTargetsToEDRAM() { uav_desc.Buffer.StructureByteStride = 0; uav_desc.Buffer.CounterOffsetInBytes = 0; uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; - D3D12_CPU_DESCRIPTOR_HANDLE uav_cpu_handle; - uav_cpu_handle.ptr = descriptor_cpu_start.ptr + descriptor_size_view; - device->CreateUnorderedAccessView(edram_buffer_, nullptr, &uav_desc, - uav_cpu_handle); + device->CreateUnorderedAccessView( + edram_buffer_, nullptr, &uav_desc, + provider->OffsetViewDescriptor(descriptor_cpu_start, 1)); command_list->SetComputeRootSignature(edram_load_store_root_signature_); command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start); @@ -2316,7 +2311,6 @@ void RenderTargetCache::LoadRenderTargetsFromEDRAM( // Set up the bindings. auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider(); auto device = provider->GetDevice(); - auto descriptor_size_view = provider->GetDescriptorSizeView(); D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc; srv_desc.Format = DXGI_FORMAT_R32_TYPELESS; srv_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; @@ -2335,10 +2329,9 @@ void RenderTargetCache::LoadRenderTargetsFromEDRAM( uav_desc.Buffer.StructureByteStride = 0; uav_desc.Buffer.CounterOffsetInBytes = 0; uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; - D3D12_CPU_DESCRIPTOR_HANDLE uav_cpu_handle; - uav_cpu_handle.ptr = descriptor_cpu_start.ptr + descriptor_size_view; - device->CreateUnorderedAccessView(copy_buffer, nullptr, &uav_desc, - uav_cpu_handle); + device->CreateUnorderedAccessView( + copy_buffer, nullptr, &uav_desc, + provider->OffsetViewDescriptor(descriptor_cpu_start, 1)); command_list->SetComputeRootSignature(edram_load_store_root_signature_); command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start); diff --git a/src/xenia/gpu/d3d12/texture_cache.cc b/src/xenia/gpu/d3d12/texture_cache.cc index 05d375612..d182724f8 100644 --- a/src/xenia/gpu/d3d12/texture_cache.cc +++ b/src/xenia/gpu/d3d12/texture_cache.cc @@ -638,10 +638,8 @@ bool TextureCache::TileResolvedTexture( srv_desc.Buffer.StructureByteStride = 0; srv_desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW; device->CreateShaderResourceView(buffer, &srv_desc, descriptor_cpu_start); - D3D12_CPU_DESCRIPTOR_HANDLE uav_cpu_handle; - uav_cpu_handle.ptr = - descriptor_cpu_start.ptr + provider->GetDescriptorSizeView(); - shared_memory_->CreateRawUAV(uav_cpu_handle); + shared_memory_->CreateRawUAV( + provider->OffsetViewDescriptor(descriptor_cpu_start, 1)); command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start); command_processor_->SetComputePipeline(tile_pipelines_[uint32_t(tile_mode)]); 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.CounterOffsetInBytes = 0; uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; - D3D12_CPU_DESCRIPTOR_HANDLE descriptor_cpu_uav; - descriptor_cpu_uav.ptr = - descriptor_cpu_start.ptr + provider->GetDescriptorSizeView(); - device->CreateUnorderedAccessView(copy_buffer, nullptr, &uav_desc, - descriptor_cpu_uav); + device->CreateUnorderedAccessView( + copy_buffer, nullptr, &uav_desc, + provider->OffsetViewDescriptor(descriptor_cpu_start, 1)); command_processor_->SetComputePipeline(pipeline); command_list->SetComputeRootSignature(load_root_signature_); command_list->SetComputeRootDescriptorTable(1, descriptor_gpu_start); diff --git a/src/xenia/ui/d3d12/d3d12_context.cc b/src/xenia/ui/d3d12/d3d12_context.cc index 2f0b7c4b7..c799b8a8c 100644 --- a/src/xenia/ui/d3d12/d3d12_context.cc +++ b/src/xenia/ui/d3d12/d3d12_context.cc @@ -342,9 +342,8 @@ void D3D12Context::AwaitAllFramesCompletion() { D3D12_CPU_DESCRIPTOR_HANDLE D3D12Context::GetSwapChainBufferRTV( uint32_t buffer_index) const { - D3D12_CPU_DESCRIPTOR_HANDLE handle = swap_chain_rtv_heap_start_; - handle.ptr += buffer_index * GetD3D12Provider()->GetDescriptorSizeRTV(); - return handle; + return GetD3D12Provider()->OffsetRTVDescriptor(swap_chain_rtv_heap_start_, + buffer_index); } } // namespace d3d12 diff --git a/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc b/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc index b3c72a5c3..9cf7f5198 100644 --- a/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc +++ b/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc @@ -266,7 +266,7 @@ bool D3D12ImmediateDrawer::Initialize() { } sampler_heap_cpu_start_ = sampler_heap_->GetCPUDescriptorHandleForHeapStart(); sampler_heap_gpu_start_ = sampler_heap_->GetGPUDescriptorHandleForHeapStart(); - uint32_t sampler_size = provider->GetDescriptorSizeSampler(); + uint32_t sampler_size = provider->GetSamplerDescriptorSize(); // Nearest neighbor, clamp. D3D12_SAMPLER_DESC sampler_desc; 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); } if (bind_texture) { - auto descriptor_size_view = provider->GetDescriptorSizeView(); D3D12_SHADER_RESOURCE_VIEW_DESC texture_view_desc; texture_view_desc.Format = D3D12ImmediateTexture::kFormat; 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.PlaneSlice = 0; texture_view_desc.Texture2D.ResourceMinLODClamp = 0.0f; - D3D12_CPU_DESCRIPTOR_HANDLE texture_view_cpu_handle; - texture_view_cpu_handle.ptr = - texture_descriptor_pool_->GetLastRequestHeapCPUStart().ptr + - texture_descriptor_index * descriptor_size_view; - device->CreateShaderResourceView(texture_resource, &texture_view_desc, - 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; + device->CreateShaderResourceView( + texture_resource, &texture_view_desc, + provider->OffsetViewDescriptor( + texture_descriptor_pool_->GetLastRequestHeapCPUStart(), + texture_descriptor_index)); 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; } @@ -655,12 +652,10 @@ void D3D12ImmediateDrawer::Draw(const ImmediateDraw& draw) { sampler_index = SamplerIndex::kNearestClamp; } 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( - UINT(RootParameter::kSampler), sampler_gpu_handle); + UINT(RootParameter::kSampler), + provider->OffsetSamplerDescriptor(sampler_heap_gpu_start_, + uint32_t(sampler_index))); current_sampler_index_ = sampler_index; } diff --git a/src/xenia/ui/d3d12/d3d12_provider.h b/src/xenia/ui/d3d12/d3d12_provider.h index 37d683e1e..22c187795 100644 --- a/src/xenia/ui/d3d12/d3d12_provider.h +++ b/src/xenia/ui/d3d12/d3d12_provider.h @@ -33,10 +33,30 @@ class D3D12Provider : public GraphicsProvider { ID3D12Device* GetDevice() const { return device_; } ID3D12CommandQueue* GetDirectQueue() const { return direct_queue_; } - uint32_t GetDescriptorSizeView() const { return descriptor_size_view_; } - uint32_t GetDescriptorSizeSampler() const { return descriptor_size_sampler_; } - uint32_t GetDescriptorSizeRTV() const { return descriptor_size_rtv_; } - uint32_t GetDescriptorSizeDSV() const { return descriptor_size_dsv_; } + uint32_t GetViewDescriptorSize() const { return descriptor_size_view_; } + uint32_t GetSamplerDescriptorSize() const { return descriptor_size_sampler_; } + uint32_t GetRTVDescriptorSize() const { return descriptor_size_rtv_; } + uint32_t GetDSVDescriptorSize() const { return descriptor_size_dsv_; } + template + inline T OffsetViewDescriptor(T start, uint32_t index) const { + start.ptr += index * descriptor_size_view_; + return start; + } + template + inline T OffsetSamplerDescriptor(T start, uint32_t index) const { + start.ptr += index * descriptor_size_sampler_; + return start; + } + template + inline T OffsetRTVDescriptor(T start, uint32_t index) const { + start.ptr += index * descriptor_size_rtv_; + return start; + } + template + inline T OffsetDSVDescriptor(T start, uint32_t index) const { + start.ptr += index * descriptor_size_dsv_; + return start; + } uint32_t GetProgrammableSamplePositionsTier() const { return programmable_sample_positions_tier_;