From fdae12c52ebb05d557749f99fd4346b99293860a Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Wed, 28 Oct 2015 17:32:03 +0100 Subject: [PATCH] d3d12: Move empty texture slot filling code to D3D12Texture. --- rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp | 34 +++------------------------ rpcs3/Emu/RSX/D3D12/D3D12GSRender.h | 4 ++-- rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp | 34 +++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index 588be48702..b060946979 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -471,35 +471,7 @@ void D3D12GSRender::end() std::chrono::time_point texture_duration_start = std::chrono::system_clock::now(); if (std::get<2>(*m_PSO) > 0) { - size_t used_texture = UploadTextures(getCurrentResourceStorage().m_commandList.Get(), currentDescriptorIndex + 3); - - // Fill empty slots - for (; used_texture < std::get<2>(*m_PSO); used_texture++) - { - D3D12_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {}; - shader_resource_view_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; - shader_resource_view_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - shader_resource_view_desc.Texture2D.MipLevels = 1; - shader_resource_view_desc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING( - D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0, - D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0, - D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0, - D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0); - m_device->CreateShaderResourceView(m_dummyTexture, &shader_resource_view_desc, - CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_descriptorsHeap->GetCPUDescriptorHandleForHeapStart()) - .Offset((INT)currentDescriptorIndex + 3 + (INT)used_texture, g_descriptorStrideSRVCBVUAV) - ); - - D3D12_SAMPLER_DESC sampler_desc = {}; - sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT; - sampler_desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP; - sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP; - sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; - m_device->CreateSampler(&sampler_desc, - CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex]->GetCPUDescriptorHandleForHeapStart()) - .Offset((INT)getCurrentResourceStorage().m_currentSamplerIndex + (INT)used_texture, g_descriptorStrideSamplers) - ); - } + upload_and_bind_textures(getCurrentResourceStorage().m_commandList.Get(), currentDescriptorIndex + 3, std::get<2>(*m_PSO) > 0); ID3D12DescriptorHeap *descriptors[] = { @@ -517,8 +489,8 @@ void D3D12GSRender::end() .Offset((INT)getCurrentResourceStorage().m_currentSamplerIndex, g_descriptorStrideSamplers) ); - getCurrentResourceStorage().m_currentSamplerIndex += used_texture; - getCurrentResourceStorage().m_descriptorsHeapIndex += used_texture + 3; + getCurrentResourceStorage().m_currentSamplerIndex += std::get<2>(*m_PSO); + getCurrentResourceStorage().m_descriptorsHeapIndex += std::get<2>(*m_PSO) + 3; } else { diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h index e697f10476..5dd3ec4c9e 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h @@ -476,9 +476,9 @@ private: * Fetch all textures recorded in the state in the render target cache and in the texture cache. * If a texture is not cached, populate cmdlist with uploads command. * Create necessary resource view/sampler descriptors in the per frame storage struct. - * returns the number of texture uploaded. + * If the count of enabled texture is below texture_count, fills with dummy texture and sampler. */ - size_t UploadTextures(ID3D12GraphicsCommandList *cmdlist, size_t descriptorIndex); + void upload_and_bind_textures(ID3D12GraphicsCommandList *command_list, size_t descriptor_index, size_t texture_count); /** * Creates render target if necessary. diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp index 6d55e9135e..04e85f580a 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp @@ -124,7 +124,7 @@ void update_existing_texture( } } -size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist, size_t descriptor_index) +void D3D12GSRender::upload_and_bind_textures(ID3D12GraphicsCommandList *command_list, size_t descriptor_index, size_t texture_count) { size_t used_texture = 0; @@ -152,7 +152,7 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist, size_t { if (cached_texture->first.m_isDirty) { - update_existing_texture(textures[i], cmdlist, m_textureUploadData, cached_texture->second.Get()); + update_existing_texture(textures[i], command_list, m_textureUploadData, cached_texture->second.Get()); m_textureCache.protectData(texaddr, texaddr, get_texture_size(textures[i])); } vram_texture = cached_texture->second.Get(); @@ -161,7 +161,7 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist, size_t { if (cached_texture != nullptr) getCurrentResourceStorage().m_dirtyTextures.push_back(m_textureCache.removeFromCache(texaddr)); - ComPtr tex = upload_single_texture(textures[i], m_device.Get(), cmdlist, m_textureUploadData); + ComPtr tex = upload_single_texture(textures[i], m_device.Get(), command_list, m_textureUploadData); vram_texture = tex.Get(); m_textureCache.storeAndProtectData(texaddr, texaddr, get_texture_size(textures[i]), format, w, h, textures[i].mipmap(), tex); } @@ -306,6 +306,32 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist, size_t used_texture++; } - return used_texture; + // Now fill remaining texture slots with dummy texture/sampler + for (; used_texture < texture_count; used_texture++) + { + D3D12_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {}; + shader_resource_view_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; + shader_resource_view_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + shader_resource_view_desc.Texture2D.MipLevels = 1; + shader_resource_view_desc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING( + D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0, + D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0, + D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0, + D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0); + m_device->CreateShaderResourceView(m_dummyTexture, &shader_resource_view_desc, + CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_descriptorsHeap->GetCPUDescriptorHandleForHeapStart()) + .Offset((INT)descriptor_index + (INT)used_texture, g_descriptorStrideSRVCBVUAV) + ); + + D3D12_SAMPLER_DESC sampler_desc = {}; + sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT; + sampler_desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP; + sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP; + sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; + m_device->CreateSampler(&sampler_desc, + CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex]->GetCPUDescriptorHandleForHeapStart()) + .Offset((INT)getCurrentResourceStorage().m_currentSamplerIndex + (INT)used_texture, g_descriptorStrideSamplers) + ); + } } #endif