mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-20 19:45:20 +00:00
d3d12: Use d3dx12.h defined struct.
This commit is contained in:
parent
ae51ce2349
commit
f10c812301
7 changed files with 108 additions and 273 deletions
|
@ -67,46 +67,6 @@ void streamBuffer(void* dst, void* src, size_t sizeInBytes)
|
|||
memcpy((char*)dst + offset, (char*)src + offset, sizeInBytes - offset);
|
||||
}
|
||||
|
||||
inline
|
||||
D3D12_RESOURCE_DESC getBufferResourceDesc(size_t sizeInByte)
|
||||
{
|
||||
D3D12_RESOURCE_DESC BufferDesc = {};
|
||||
BufferDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
BufferDesc.Width = (UINT)sizeInByte;
|
||||
BufferDesc.Height = 1;
|
||||
BufferDesc.DepthOrArraySize = 1;
|
||||
BufferDesc.SampleDesc.Count = 1;
|
||||
BufferDesc.MipLevels = 1;
|
||||
BufferDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
||||
return BufferDesc;
|
||||
}
|
||||
|
||||
inline
|
||||
D3D12_RESOURCE_DESC getTexture2DResourceDesc(size_t width, size_t height, DXGI_FORMAT dxgiFormat, size_t mipmapLevels)
|
||||
{
|
||||
D3D12_RESOURCE_DESC result;
|
||||
result = {};
|
||||
result.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
|
||||
result.Width = (UINT)width;
|
||||
result.Height = (UINT)height;
|
||||
result.Format = dxgiFormat;
|
||||
result.DepthOrArraySize = 1;
|
||||
result.SampleDesc.Count = 1;
|
||||
result.MipLevels = (UINT16)mipmapLevels;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
D3D12_RESOURCE_BARRIER getResourceBarrierTransition(ID3D12Resource *res, D3D12_RESOURCE_STATES stateBefore, D3D12_RESOURCE_STATES stateAfter)
|
||||
{
|
||||
D3D12_RESOURCE_BARRIER barrier = {};
|
||||
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
barrier.Transition.pResource = res;
|
||||
barrier.Transition.StateBefore = stateBefore;
|
||||
barrier.Transition.StateAfter = stateAfter;
|
||||
return barrier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert GCM blend operator code to D3D12 one
|
||||
*/
|
||||
|
@ -323,20 +283,4 @@ inline DXGI_FORMAT getTextureDXGIFormat(int format)
|
|||
}
|
||||
}
|
||||
|
||||
inline
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE getCPUDescriptorHandle(ID3D12DescriptorHeap *descriptors, size_t offset)
|
||||
{
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE result = descriptors->GetCPUDescriptorHandleForHeapStart();
|
||||
result.ptr += offset;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE getGPUDescriptorHandle(ID3D12DescriptorHeap *descriptors, size_t offset)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE result = descriptors->GetGPUDescriptorHandleForHeapStart();
|
||||
result.ptr += offset;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "Utilities/Log.h"
|
||||
|
||||
#include "D3D12GSRender.h"
|
||||
#include "d3dx12.h"
|
||||
|
||||
const int g_vertexCount = 32;
|
||||
|
||||
|
@ -221,7 +222,7 @@ ComPtr<ID3D12Resource> createVertexBuffer(const VertexBufferFormat &vbf, const R
|
|||
ThrowIfFailed(device->CreatePlacedResource(
|
||||
vertexIndexHeap.m_heap,
|
||||
heapOffset,
|
||||
&getBufferResourceDesc(subBufferSize),
|
||||
&CD3DX12_RESOURCE_DESC::Buffer(subBufferSize),
|
||||
D3D12_RESOURCE_STATE_GENERIC_READ,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(vertexBuffer.GetAddressOf())
|
||||
|
@ -432,7 +433,7 @@ D3D12_INDEX_BUFFER_VIEW D3D12GSRender::uploadIndexBuffers(bool indexed_draw)
|
|||
ThrowIfFailed(m_device->CreatePlacedResource(
|
||||
m_vertexIndexData.m_heap,
|
||||
heapOffset,
|
||||
&getBufferResourceDesc(subBufferSize),
|
||||
&CD3DX12_RESOURCE_DESC::Buffer(subBufferSize),
|
||||
D3D12_RESOURCE_STATE_GENERIC_READ,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(indexBuffer.GetAddressOf())
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <d3dcompiler.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include "d3dx12.h"
|
||||
|
||||
PFN_D3D12_CREATE_DEVICE wrapD3D12CreateDevice;
|
||||
PFN_D3D12_GET_DEBUG_INTERFACE wrapD3D12GetDebugInterface;
|
||||
|
@ -63,28 +64,14 @@ void D3D12GSRender::ResourceStorage::Init(ID3D12Device *device)
|
|||
ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocator.Get(), nullptr, IID_PPV_ARGS(m_commandList.GetAddressOf())));
|
||||
ThrowIfFailed(m_commandList->Close());
|
||||
|
||||
D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = {};
|
||||
descriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||
descriptorHeapDesc.NumDescriptors = 10000; // For safety
|
||||
descriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||
D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 10000, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE };
|
||||
ThrowIfFailed(device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(&m_constantsBufferDescriptorsHeap)));
|
||||
|
||||
descriptorHeapDesc = {};
|
||||
descriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||
descriptorHeapDesc.NumDescriptors = 10000; // For safety
|
||||
descriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||
ThrowIfFailed(device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(&m_scaleOffsetDescriptorHeap)));
|
||||
ThrowIfFailed(device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(&m_textureDescriptorsHeap)));
|
||||
|
||||
D3D12_DESCRIPTOR_HEAP_DESC textureDescriptorDesc = {};
|
||||
textureDescriptorDesc.NumDescriptors = 10000; // For safety
|
||||
textureDescriptorDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||
textureDescriptorDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||
ThrowIfFailed(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_textureDescriptorsHeap)));
|
||||
|
||||
textureDescriptorDesc.NumDescriptors = 2048; // For safety
|
||||
textureDescriptorDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
|
||||
ThrowIfFailed(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap[0])));
|
||||
ThrowIfFailed(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap[1])));
|
||||
D3D12_DESCRIPTOR_HEAP_DESC samplerHeapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER , 2048, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE };
|
||||
ThrowIfFailed(device->CreateDescriptorHeap(&samplerHeapDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap[0])));
|
||||
ThrowIfFailed(device->CreateDescriptorHeap(&samplerHeapDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap[1])));
|
||||
|
||||
m_frameFinishedHandle = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
|
||||
m_fenceValue = 0;
|
||||
|
@ -225,9 +212,7 @@ D3D12GSRender::D3D12GSRender()
|
|||
m_swapChain->GetBuffer(0, IID_PPV_ARGS(&m_backBuffer[0]));
|
||||
m_swapChain->GetBuffer(1, IID_PPV_ARGS(&m_backBuffer[1]));
|
||||
|
||||
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
|
||||
heapDesc.NumDescriptors = 1;
|
||||
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
|
||||
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1};
|
||||
D3D12_RENDER_TARGET_VIEW_DESC rttDesc = {};
|
||||
rttDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
|
||||
rttDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
|
@ -297,13 +282,11 @@ D3D12GSRender::D3D12GSRender()
|
|||
initConvertShader();
|
||||
m_outputScalingPass.Init(m_device.Get());
|
||||
|
||||
D3D12_HEAP_PROPERTIES hp = {};
|
||||
hp.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
ThrowIfFailed(
|
||||
m_device->CreateCommittedResource(
|
||||
&hp,
|
||||
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&getTexture2DResourceDesc(2, 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1),
|
||||
&CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, 2, 2, 1, 1),
|
||||
D3D12_RESOURCE_STATE_GENERIC_READ,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(&m_dummyTexture))
|
||||
|
@ -427,7 +410,6 @@ void D3D12GSRender::Clear(u32 cmd)
|
|||
m_clear_surface_color_a / 255.0f
|
||||
};
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE handle = m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
size_t g_RTTIncrement = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
|
||||
switch (m_surface_color_target)
|
||||
{
|
||||
|
@ -435,26 +417,22 @@ void D3D12GSRender::Clear(u32 cmd)
|
|||
|
||||
case CELL_GCM_SURFACE_TARGET_0:
|
||||
case CELL_GCM_SURFACE_TARGET_1:
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart()), clearColor, 0, nullptr);
|
||||
break;
|
||||
case CELL_GCM_SURFACE_TARGET_MRT1:
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart()), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart()).Offset(1, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
break;
|
||||
case CELL_GCM_SURFACE_TARGET_MRT2:
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
handle.ptr += g_RTTIncrement;
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 2 * g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart()), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart()).Offset(1, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart()).Offset(2, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
break;
|
||||
case CELL_GCM_SURFACE_TARGET_MRT3:
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr);
|
||||
handle.ptr += g_RTTIncrement;
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
handle.ptr += g_RTTIncrement;
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 2 * g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
handle.ptr += g_RTTIncrement;
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 3 * g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart()), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart()).Offset(1, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart()).Offset(2, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->ClearRenderTargetView(CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart()).Offset(3, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR(RSX, "Bad surface color target: %d", m_surface_color_target);
|
||||
|
@ -527,8 +505,8 @@ void D3D12GSRender::Draw()
|
|||
setScaleOffset();
|
||||
getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_scaleOffsetDescriptorHeap.GetAddressOf());
|
||||
getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(0,
|
||||
getGPUDescriptorHandle(getCurrentResourceStorage().m_scaleOffsetDescriptorHeap.Get(),
|
||||
getCurrentResourceStorage().m_currentScaleOffsetBufferIndex * g_descriptorStrideSRVCBVUAV)
|
||||
CD3DX12_GPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_scaleOffsetDescriptorHeap->GetGPUDescriptorHandleForHeapStart())
|
||||
.Offset((INT)getCurrentResourceStorage().m_currentScaleOffsetBufferIndex, g_descriptorStrideSRVCBVUAV)
|
||||
);
|
||||
getCurrentResourceStorage().m_currentScaleOffsetBufferIndex++;
|
||||
|
||||
|
@ -540,8 +518,8 @@ void D3D12GSRender::Draw()
|
|||
|
||||
getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_constantsBufferDescriptorsHeap.GetAddressOf());
|
||||
getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(1,
|
||||
getGPUDescriptorHandle(getCurrentResourceStorage().m_constantsBufferDescriptorsHeap.Get(),
|
||||
currentBufferIndex * g_descriptorStrideSRVCBVUAV)
|
||||
CD3DX12_GPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_constantsBufferDescriptorsHeap->GetGPUDescriptorHandleForHeapStart())
|
||||
.Offset((INT)currentBufferIndex, g_descriptorStrideSRVCBVUAV)
|
||||
);
|
||||
getCurrentResourceStorage().m_commandList->SetPipelineState(m_PSO->first);
|
||||
|
||||
|
@ -561,9 +539,9 @@ void D3D12GSRender::Draw()
|
|||
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, &srvDesc,
|
||||
getCPUDescriptorHandle(getCurrentResourceStorage().m_textureDescriptorsHeap.Get(),
|
||||
(getCurrentResourceStorage().m_currentTextureIndex + usedTexture) * g_descriptorStrideSRVCBVUAV)
|
||||
m_device->CreateShaderResourceView(m_dummyTexture, &srvDesc,
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_textureDescriptorsHeap->GetCPUDescriptorHandleForHeapStart())
|
||||
.Offset((INT)getCurrentResourceStorage().m_currentTextureIndex + (INT)usedTexture, g_descriptorStrideSRVCBVUAV)
|
||||
);
|
||||
|
||||
D3D12_SAMPLER_DESC samplerDesc = {};
|
||||
|
@ -572,21 +550,21 @@ void D3D12GSRender::Draw()
|
|||
samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
m_device->CreateSampler(&samplerDesc,
|
||||
getCPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex].Get(),
|
||||
(getCurrentResourceStorage().m_currentSamplerIndex + usedTexture) * g_descriptorStrideSamplers)
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex]->GetCPUDescriptorHandleForHeapStart())
|
||||
.Offset((INT)getCurrentResourceStorage().m_currentSamplerIndex + (INT)usedTexture, g_descriptorStrideSamplers)
|
||||
);
|
||||
}
|
||||
|
||||
getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_textureDescriptorsHeap.GetAddressOf());
|
||||
getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(2,
|
||||
getGPUDescriptorHandle(getCurrentResourceStorage().m_textureDescriptorsHeap.Get(),
|
||||
getCurrentResourceStorage().m_currentTextureIndex * g_descriptorStrideSRVCBVUAV)
|
||||
CD3DX12_GPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_textureDescriptorsHeap->GetGPUDescriptorHandleForHeapStart())
|
||||
.Offset((INT)getCurrentResourceStorage().m_currentTextureIndex, g_descriptorStrideSRVCBVUAV)
|
||||
);
|
||||
|
||||
getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex].GetAddressOf());
|
||||
getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(3,
|
||||
getGPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex].Get(),
|
||||
getCurrentResourceStorage().m_currentSamplerIndex * g_descriptorStrideSamplers)
|
||||
CD3DX12_GPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex]->GetGPUDescriptorHandleForHeapStart())
|
||||
.Offset((INT)getCurrentResourceStorage().m_currentSamplerIndex, g_descriptorStrideSamplers)
|
||||
);
|
||||
|
||||
getCurrentResourceStorage().m_currentTextureIndex += usedTexture;
|
||||
|
@ -615,7 +593,7 @@ void D3D12GSRender::Draw()
|
|||
}
|
||||
|
||||
getCurrentResourceStorage().m_commandList->OMSetRenderTargets((UINT)numRTT, &m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart(), true,
|
||||
&getCPUDescriptorHandle(m_rtts.m_depthStencilDescriptorHeap, 0));
|
||||
&CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.m_depthStencilDescriptorHeap->GetCPUDescriptorHandleForHeapStart()));
|
||||
|
||||
D3D12_VIEWPORT viewport =
|
||||
{
|
||||
|
@ -714,9 +692,6 @@ void D3D12GSRender::Flip()
|
|||
ResourceStorage &storage = getCurrentResourceStorage();
|
||||
assert(storage.m_RAMFramebuffer == nullptr);
|
||||
|
||||
D3D12_HEAP_PROPERTIES heapProp = {};
|
||||
heapProp.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
|
||||
size_t w = 0, h = 0, rowPitch = 0;
|
||||
|
||||
ID3D12Resource *stagingTexture;
|
||||
|
@ -736,7 +711,7 @@ void D3D12GSRender::Flip()
|
|||
ThrowIfFailed(m_device->CreatePlacedResource(
|
||||
m_textureUploadData.m_heap,
|
||||
heapOffset,
|
||||
&getBufferResourceDesc(textureSize),
|
||||
&CD3DX12_RESOURCE_DESC::Buffer(textureSize),
|
||||
D3D12_RESOURCE_STATE_GENERIC_READ,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(&stagingTexture)
|
||||
|
@ -752,38 +727,29 @@ void D3D12GSRender::Flip()
|
|||
|
||||
ThrowIfFailed(
|
||||
m_device->CreateCommittedResource(
|
||||
&heapProp,
|
||||
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&getTexture2DResourceDesc(w, h, DXGI_FORMAT_R8G8B8A8_UNORM, 1),
|
||||
&CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)w, (UINT)h, 1, 1),
|
||||
D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(storage.m_RAMFramebuffer.GetAddressOf())
|
||||
)
|
||||
);
|
||||
D3D12_TEXTURE_COPY_LOCATION src = {}, dst = {};
|
||||
dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
|
||||
dst.pResource = storage.m_RAMFramebuffer.Get();
|
||||
src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
|
||||
src.pResource = stagingTexture;
|
||||
src.PlacedFootprint.Footprint.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
src.PlacedFootprint.Footprint.Width = (UINT)w;
|
||||
src.PlacedFootprint.Footprint.Height = (UINT)h;
|
||||
src.PlacedFootprint.Footprint.Depth = (UINT)1;
|
||||
src.PlacedFootprint.Footprint.RowPitch = (UINT)rowPitch;
|
||||
getCurrentResourceStorage().m_commandList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(storage.m_RAMFramebuffer.Get(), 0), 0, 0, 0,
|
||||
&CD3DX12_TEXTURE_COPY_LOCATION(stagingTexture, { 0, { DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)w, (UINT)h, 1, (UINT)rowPitch} }), nullptr);
|
||||
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(storage.m_RAMFramebuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ));
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(storage.m_RAMFramebuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ));
|
||||
resourceToFlip = storage.m_RAMFramebuffer.Get();
|
||||
viewport_w = (float)w, viewport_h = (float)h;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_rtts.m_currentlyBoundRenderTargets[0] != nullptr)
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundRenderTargets[0], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_GENERIC_READ));
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.m_currentlyBoundRenderTargets[0], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_GENERIC_READ));
|
||||
resourceToFlip = m_rtts.m_currentlyBoundRenderTargets[0];
|
||||
}
|
||||
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
||||
|
||||
D3D12_VIEWPORT viewport =
|
||||
{
|
||||
|
@ -806,9 +772,7 @@ void D3D12GSRender::Flip()
|
|||
getCurrentResourceStorage().m_commandList->RSSetScissorRects(1, &box);
|
||||
getCurrentResourceStorage().m_commandList->SetGraphicsRootSignature(m_outputScalingPass.m_rootSignature);
|
||||
getCurrentResourceStorage().m_commandList->SetPipelineState(m_outputScalingPass.m_PSO);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE CPUHandle;
|
||||
CPUHandle = m_outputScalingPass.m_textureDescriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
CPUHandle.ptr += m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) * m_swapChain->GetCurrentBackBufferIndex();
|
||||
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
|
||||
// FIXME: Not always true
|
||||
srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
|
@ -823,29 +787,27 @@ void D3D12GSRender::Flip()
|
|||
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_3,
|
||||
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_0
|
||||
);
|
||||
m_device->CreateShaderResourceView(resourceToFlip, &srvDesc, CPUHandle);
|
||||
m_device->CreateShaderResourceView(resourceToFlip, &srvDesc,
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_outputScalingPass.m_textureDescriptorHeap->GetCPUDescriptorHandleForHeapStart()).Offset(m_swapChain->GetCurrentBackBufferIndex(), g_descriptorStrideSRVCBVUAV));
|
||||
|
||||
D3D12_SAMPLER_DESC samplerDesc = {};
|
||||
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT;
|
||||
samplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
CPUHandle = m_outputScalingPass.m_samplerDescriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
CPUHandle.ptr += m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER) * m_swapChain->GetCurrentBackBufferIndex();
|
||||
m_device->CreateSampler(&samplerDesc, CPUHandle);
|
||||
m_device->CreateSampler(&samplerDesc,
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_outputScalingPass.m_samplerDescriptorHeap->GetCPUDescriptorHandleForHeapStart()).Offset(m_swapChain->GetCurrentBackBufferIndex(), g_descriptorStrideSamplers));
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GPUHandle;
|
||||
GPUHandle = m_outputScalingPass.m_textureDescriptorHeap->GetGPUDescriptorHandleForHeapStart();
|
||||
GPUHandle.ptr += m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) * m_swapChain->GetCurrentBackBufferIndex();
|
||||
getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, &m_outputScalingPass.m_textureDescriptorHeap);
|
||||
getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(0, GPUHandle);
|
||||
GPUHandle = m_outputScalingPass.m_samplerDescriptorHeap->GetGPUDescriptorHandleForHeapStart();
|
||||
GPUHandle.ptr += m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER) * m_swapChain->GetCurrentBackBufferIndex();
|
||||
getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(0,
|
||||
CD3DX12_GPU_DESCRIPTOR_HANDLE(m_outputScalingPass.m_textureDescriptorHeap->GetGPUDescriptorHandleForHeapStart()).Offset(m_swapChain->GetCurrentBackBufferIndex(), g_descriptorStrideSRVCBVUAV));
|
||||
getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, &m_outputScalingPass.m_samplerDescriptorHeap);
|
||||
getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(1, GPUHandle);
|
||||
getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(1,
|
||||
CD3DX12_GPU_DESCRIPTOR_HANDLE(m_outputScalingPass.m_samplerDescriptorHeap->GetGPUDescriptorHandleForHeapStart()).Offset(m_swapChain->GetCurrentBackBufferIndex(), g_descriptorStrideSamplers));
|
||||
|
||||
CPUHandle = m_backbufferAsRendertarget[m_swapChain->GetCurrentBackBufferIndex()]->GetCPUDescriptorHandleForHeapStart();
|
||||
getCurrentResourceStorage().m_commandList->OMSetRenderTargets(1, &CPUHandle, true, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->OMSetRenderTargets(1,
|
||||
&CD3DX12_CPU_DESCRIPTOR_HANDLE(m_backbufferAsRendertarget[m_swapChain->GetCurrentBackBufferIndex()]->GetCPUDescriptorHandleForHeapStart()),
|
||||
true, nullptr);
|
||||
D3D12_VERTEX_BUFFER_VIEW vbv = {};
|
||||
vbv.BufferLocation = m_outputScalingPass.m_vertexBuffer->GetGPUVirtualAddress();
|
||||
vbv.StrideInBytes = 4 * sizeof(float);
|
||||
|
@ -856,9 +818,9 @@ void D3D12GSRender::Flip()
|
|||
getCurrentResourceStorage().m_commandList->DrawInstanced(4, 1, 0, 0);
|
||||
|
||||
if (!Ini.GSOverlay.GetValue())
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
|
||||
if (isFlipSurfaceInLocalMemory(m_surface_color_target) && m_rtts.m_currentlyBoundRenderTargets[0] != nullptr)
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundRenderTargets[0], D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.m_currentlyBoundRenderTargets[0], D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
||||
ThrowIfFailed(getCurrentResourceStorage().m_commandList->Close());
|
||||
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().m_commandList.GetAddressOf());
|
||||
|
||||
|
@ -941,20 +903,15 @@ ID3D12Resource * D3D12GSRender::writeColorBuffer(ID3D12Resource * RTT, ID3D12Gra
|
|||
break;
|
||||
}
|
||||
|
||||
D3D12_HEAP_PROPERTIES heapProp = {};
|
||||
heapProp.Type = D3D12_HEAP_TYPE_READBACK;
|
||||
D3D12_RESOURCE_DESC resdesc = getBufferResourceDesc(rowPitch * h);
|
||||
|
||||
size_t sizeInByte = rowPitch * h;
|
||||
assert(m_readbackResources.canAlloc(sizeInByte));
|
||||
size_t heapOffset = m_readbackResources.alloc(sizeInByte);
|
||||
|
||||
resdesc = getBufferResourceDesc(sizeInByte);
|
||||
ThrowIfFailed(
|
||||
m_device->CreatePlacedResource(
|
||||
m_readbackResources.m_heap,
|
||||
heapOffset,
|
||||
&resdesc,
|
||||
&CD3DX12_RESOURCE_DESC::Buffer(rowPitch * h),
|
||||
D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(&Result)
|
||||
|
@ -962,21 +919,11 @@ ID3D12Resource * D3D12GSRender::writeColorBuffer(ID3D12Resource * RTT, ID3D12Gra
|
|||
);
|
||||
getCurrentResourceStorage().m_singleFrameLifetimeResources.push_back(Result);
|
||||
|
||||
cmdlist->ResourceBarrier(1, &getResourceBarrierTransition(RTT, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE));
|
||||
cmdlist->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(RTT, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE));
|
||||
|
||||
D3D12_TEXTURE_COPY_LOCATION dst = {}, src = {};
|
||||
src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
|
||||
src.pResource = RTT;
|
||||
dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
|
||||
dst.pResource = Result;
|
||||
dst.PlacedFootprint.Offset = 0;
|
||||
dst.PlacedFootprint.Footprint.Depth = 1;
|
||||
dst.PlacedFootprint.Footprint.Format = dxgiFormat;
|
||||
dst.PlacedFootprint.Footprint.Height = (UINT)h;
|
||||
dst.PlacedFootprint.Footprint.Width = (UINT)w;
|
||||
dst.PlacedFootprint.Footprint.RowPitch = (UINT)rowPitch;
|
||||
cmdlist->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
|
||||
cmdlist->ResourceBarrier(1, &getResourceBarrierTransition(RTT, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
||||
cmdlist->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(Result, { 0, {dxgiFormat, (UINT)h, (UINT)w, 1, (UINT)rowPitch } }), 0, 0, 0,
|
||||
&CD3DX12_TEXTURE_COPY_LOCATION(RTT, 0), nullptr);
|
||||
cmdlist->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(RTT, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
@ -1020,11 +967,6 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
|||
|
||||
if (m_set_context_dma_z && Ini.GSDumpDepthBuffer.GetValue())
|
||||
{
|
||||
D3D12_HEAP_PROPERTIES heapProp = {};
|
||||
heapProp.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
D3D12_RESOURCE_DESC resdesc = getTexture2DResourceDesc(m_surface_clip_w, m_surface_clip_h, DXGI_FORMAT_R8_UNORM, 1);
|
||||
resdesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
|
||||
|
||||
size_t sizeInByte = m_surface_clip_w * m_surface_clip_h * 2;
|
||||
assert(m_UAVHeap.canAlloc(sizeInByte));
|
||||
size_t heapOffset = m_UAVHeap.alloc(sizeInByte);
|
||||
|
@ -1033,7 +975,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
|||
m_device->CreatePlacedResource(
|
||||
m_UAVHeap.m_heap,
|
||||
heapOffset,
|
||||
&resdesc,
|
||||
&CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8_UNORM, m_surface_clip_w, m_surface_clip_h, 1, 1, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS),
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(depthConverted.GetAddressOf())
|
||||
|
@ -1045,12 +987,11 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
|||
assert(m_readbackResources.canAlloc(sizeInByte));
|
||||
heapOffset = m_readbackResources.alloc(sizeInByte);
|
||||
|
||||
resdesc = getBufferResourceDesc(sizeInByte);
|
||||
ThrowIfFailed(
|
||||
m_device->CreatePlacedResource(
|
||||
m_readbackResources.m_heap,
|
||||
heapOffset,
|
||||
&resdesc,
|
||||
&CD3DX12_RESOURCE_DESC::Buffer(sizeInByte),
|
||||
D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(writeDest.GetAddressOf())
|
||||
|
@ -1058,14 +999,10 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
|||
);
|
||||
getCurrentResourceStorage().m_singleFrameLifetimeResources.push_back(writeDest);
|
||||
|
||||
D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = {};
|
||||
descriptorHeapDesc.NumDescriptors = 2;
|
||||
descriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||
descriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||
D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV , 2, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE };
|
||||
ThrowIfFailed(
|
||||
m_device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(&descriptorHeap))
|
||||
);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE Handle = descriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
|
||||
switch (m_surface_depth_format)
|
||||
{
|
||||
|
@ -1084,15 +1021,16 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
|||
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
||||
srvDesc.Texture2D.MipLevels = 1;
|
||||
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
||||
m_device->CreateShaderResourceView(m_rtts.m_currentlyBoundDepthStencil, &srvDesc, Handle);
|
||||
Handle.ptr += m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
||||
m_device->CreateShaderResourceView(m_rtts.m_currentlyBoundDepthStencil, &srvDesc,
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE(descriptorHeap->GetCPUDescriptorHandleForHeapStart()));
|
||||
D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
|
||||
uavDesc.Format = DXGI_FORMAT_R8_UNORM;
|
||||
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
|
||||
m_device->CreateUnorderedAccessView(depthConverted.Get(), nullptr, &uavDesc, Handle);
|
||||
m_device->CreateUnorderedAccessView(depthConverted.Get(), nullptr, &uavDesc,
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE(descriptorHeap->GetCPUDescriptorHandleForHeapStart()).Offset(1, g_descriptorStrideSRVCBVUAV));
|
||||
|
||||
// Convert
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundDepthStencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ));
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.m_currentlyBoundDepthStencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ));
|
||||
|
||||
getCurrentResourceStorage().m_commandList->SetPipelineState(m_convertPSO);
|
||||
getCurrentResourceStorage().m_commandList->SetComputeRootSignature(m_convertRootSignature);
|
||||
|
@ -1100,35 +1038,19 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
|||
getCurrentResourceStorage().m_commandList->SetComputeRootDescriptorTable(0, descriptorHeap->GetGPUDescriptorHandleForHeapStart());
|
||||
getCurrentResourceStorage().m_commandList->Dispatch(m_surface_clip_w / 8, m_surface_clip_h / 8, 1);
|
||||
|
||||
// Flush UAV
|
||||
D3D12_RESOURCE_BARRIER uavbarrier = {};
|
||||
uavbarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
|
||||
uavbarrier.UAV.pResource = depthConverted.Get();
|
||||
|
||||
D3D12_RESOURCE_BARRIER barriers[] =
|
||||
{
|
||||
getResourceBarrierTransition(m_rtts.m_currentlyBoundDepthStencil, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_DEPTH_WRITE),
|
||||
uavbarrier,
|
||||
CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.m_currentlyBoundDepthStencil, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_DEPTH_WRITE),
|
||||
CD3DX12_RESOURCE_BARRIER::UAV(depthConverted.Get()),
|
||||
};
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(2, barriers);
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(depthConverted.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE));
|
||||
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(depthConverted.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE));
|
||||
}
|
||||
|
||||
if (m_set_context_dma_z && Ini.GSDumpDepthBuffer.GetValue())
|
||||
{
|
||||
// Copy
|
||||
D3D12_TEXTURE_COPY_LOCATION dst = {}, src = {};
|
||||
src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
|
||||
src.pResource = depthConverted.Get();
|
||||
dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
|
||||
dst.pResource = writeDest.Get();
|
||||
dst.PlacedFootprint.Offset = 0;
|
||||
dst.PlacedFootprint.Footprint.Depth = 1;
|
||||
dst.PlacedFootprint.Footprint.Format = DXGI_FORMAT_R8_UNORM;
|
||||
dst.PlacedFootprint.Footprint.Height = m_surface_clip_h;
|
||||
dst.PlacedFootprint.Footprint.Width = m_surface_clip_w;
|
||||
dst.PlacedFootprint.Footprint.RowPitch = (UINT)depthRowPitch;
|
||||
getCurrentResourceStorage().m_commandList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
|
||||
getCurrentResourceStorage().m_commandList->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(writeDest.Get(), { 0, { DXGI_FORMAT_R8_UNORM, m_surface_clip_w, m_surface_clip_h, 1, (UINT)depthRowPitch } }), 0, 0, 0,
|
||||
&CD3DX12_TEXTURE_COPY_LOCATION(depthConverted.Get(), 0), nullptr);
|
||||
|
||||
invalidateTexture(GetAddress(m_surface_offset_z, m_context_dma_z - 0xfeed0000));
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "D3D12RenderTargetSets.h"
|
||||
#include "D3D12PipelineState.h"
|
||||
#include "D3D12Buffer.h"
|
||||
#include "d3dx12.h"
|
||||
|
||||
// Some constants are the same between RSX and GL
|
||||
#include <GL\GL.h>
|
||||
|
@ -94,7 +95,7 @@ struct InitHeap<ID3D12Resource>
|
|||
heapProperties.Type = type;
|
||||
ThrowIfFailed(device->CreateCommittedResource(&heapProperties,
|
||||
flags,
|
||||
&getBufferResourceDesc(heapSize),
|
||||
&CD3DX12_RESOURCE_DESC::Buffer(heapSize),
|
||||
D3D12_RESOURCE_STATE_GENERIC_READ,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(&result))
|
||||
|
@ -344,10 +345,10 @@ private:
|
|||
|
||||
std::vector<D3D12_INPUT_ELEMENT_DESC> m_IASet;
|
||||
|
||||
size_t g_descriptorStrideSRVCBVUAV;
|
||||
size_t g_descriptorStrideDSV;
|
||||
size_t g_descriptorStrideRTV;
|
||||
size_t g_descriptorStrideSamplers;
|
||||
INT g_descriptorStrideSRVCBVUAV;
|
||||
INT g_descriptorStrideDSV;
|
||||
INT g_descriptorStrideRTV;
|
||||
INT g_descriptorStrideSamplers;
|
||||
|
||||
// Used to fill unused texture slot
|
||||
ID3D12Resource *m_dummyTexture;
|
||||
|
|
|
@ -26,11 +26,11 @@ void D3D12GSRender::PrepareRenderTargets(ID3D12GraphicsCommandList *copycmdlist)
|
|||
{
|
||||
if (m_rtts.m_currentlyBoundRenderTargets[i] == nullptr)
|
||||
continue;
|
||||
copycmdlist->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundRenderTargets[i], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_GENERIC_READ));
|
||||
copycmdlist->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.m_currentlyBoundRenderTargets[i], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_GENERIC_READ));
|
||||
}
|
||||
// Same for depth buffer
|
||||
if (m_rtts.m_currentlyBoundDepthStencil != nullptr)
|
||||
copycmdlist->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundDepthStencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ));
|
||||
copycmdlist->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.m_currentlyBoundDepthStencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ));
|
||||
|
||||
memset(m_rtts.m_currentlyBoundRenderTargetsAddress, 0, 4 * sizeof(u32));
|
||||
memset(m_rtts.m_currentlyBoundRenderTargets, 0, 4 * sizeof(ID3D12Resource *));
|
||||
|
@ -148,7 +148,7 @@ ID3D12Resource *RenderTargets::bindAddressAsRenderTargets(ID3D12Device *device,
|
|||
if (It != m_renderTargets.end())
|
||||
{
|
||||
rtt = It->second;
|
||||
cmdList->ResourceBarrier(1, &getResourceBarrierTransition(rtt, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
||||
cmdList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(rtt, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -170,16 +170,10 @@ ID3D12Resource *RenderTargets::bindAddressAsRenderTargets(ID3D12Device *device,
|
|||
clearColorValue.Color[2] = clearColorB;
|
||||
clearColorValue.Color[3] = clearColorA;
|
||||
|
||||
D3D12_HEAP_PROPERTIES heapProp = {};
|
||||
heapProp.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
|
||||
D3D12_RESOURCE_DESC resourceDesc = getTexture2DResourceDesc(width, height, dxgiFormat, 1);
|
||||
resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
|
||||
|
||||
device->CreateCommittedResource(
|
||||
&heapProp,
|
||||
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&resourceDesc,
|
||||
&CD3DX12_RESOURCE_DESC::Tex2D(dxgiFormat, (UINT)width, (UINT)height, 1, 1, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET),
|
||||
D3D12_RESOURCE_STATE_RENDER_TARGET,
|
||||
&clearColorValue,
|
||||
IID_PPV_ARGS(&rtt)
|
||||
|
@ -200,7 +194,7 @@ ID3D12Resource * RenderTargets::bindAddressAsDepthStencil(ID3D12Device * device,
|
|||
if (It != m_depthStencil.end())
|
||||
{
|
||||
ds = It->second;
|
||||
cmdList->ResourceBarrier(1, &getResourceBarrierTransition(ds, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_DEPTH_WRITE));
|
||||
cmdList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(ds, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_DEPTH_WRITE));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -228,13 +222,10 @@ ID3D12Resource * RenderTargets::bindAddressAsDepthStencil(ID3D12Device * device,
|
|||
assert(0);
|
||||
}
|
||||
|
||||
D3D12_RESOURCE_DESC resourceDesc = getTexture2DResourceDesc(width, height, dxgiFormat, 1);
|
||||
resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
|
||||
|
||||
device->CreateCommittedResource(
|
||||
&heapProp,
|
||||
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&resourceDesc,
|
||||
&CD3DX12_RESOURCE_DESC::Tex2D(dxgiFormat, (UINT)width, (UINT)height, 1, 1, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL),
|
||||
D3D12_RESOURCE_STATE_DEPTH_WRITE,
|
||||
&clearDepthValue,
|
||||
IID_PPV_ARGS(&ds)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "stdafx.h"
|
||||
#if defined(DX12_SUPPORT)
|
||||
#include "D3D12GSRender.h"
|
||||
#include "d3dx12.h"
|
||||
// For clarity this code deals with texture but belongs to D3D12GSRender class
|
||||
|
||||
|
||||
|
@ -559,7 +560,7 @@ ID3D12Resource *uploadSingleTexture(
|
|||
ThrowIfFailed(device->CreatePlacedResource(
|
||||
textureBuffersHeap.m_heap,
|
||||
heapOffset,
|
||||
&getBufferResourceDesc(textureSize),
|
||||
&CD3DX12_RESOURCE_DESC::Buffer(textureSize),
|
||||
D3D12_RESOURCE_STATE_GENERIC_READ,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(Texture.GetAddressOf())
|
||||
|
@ -611,14 +612,11 @@ ID3D12Resource *uploadSingleTexture(
|
|||
}
|
||||
Texture->Unmap(0, nullptr);
|
||||
|
||||
D3D12_RESOURCE_DESC texturedesc = getTexture2DResourceDesc(w, h, dxgiFormat, texture.GetMipmap());
|
||||
D3D12_RESOURCE_DESC texturedesc = CD3DX12_RESOURCE_DESC::Tex2D(dxgiFormat, (UINT)w, (UINT)h, 1, texture.GetMipmap());
|
||||
textureSize = device->GetResourceAllocationInfo(0, 1, &texturedesc).SizeInBytes;
|
||||
|
||||
D3D12_HEAP_PROPERTIES heapProp = {};
|
||||
heapProp.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
|
||||
ThrowIfFailed(device->CreateCommittedResource(
|
||||
&heapProp,
|
||||
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&texturedesc,
|
||||
D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
|
@ -629,29 +627,12 @@ ID3D12Resource *uploadSingleTexture(
|
|||
size_t miplevel = 0;
|
||||
for (const MipmapLevelInfo mli : mipInfos)
|
||||
{
|
||||
D3D12_TEXTURE_COPY_LOCATION dst = {}, src = {};
|
||||
dst.pResource = vramTexture;
|
||||
dst.SubresourceIndex = (UINT)miplevel;
|
||||
dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
|
||||
src.PlacedFootprint.Offset = mli.offset;
|
||||
src.pResource = Texture.Get();
|
||||
src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
|
||||
src.PlacedFootprint.Footprint.Depth = 1;
|
||||
src.PlacedFootprint.Footprint.Width = (UINT)mli.width;
|
||||
src.PlacedFootprint.Footprint.Height = (UINT)mli.height;
|
||||
src.PlacedFootprint.Footprint.RowPitch = (UINT)mli.rowPitch;
|
||||
src.PlacedFootprint.Footprint.Format = dxgiFormat;
|
||||
|
||||
commandList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
|
||||
commandList->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(vramTexture, (UINT)miplevel), 0, 0, 0,
|
||||
&CD3DX12_TEXTURE_COPY_LOCATION(Texture.Get(), { mli.offset, { dxgiFormat, (UINT)mli.width, (UINT)mli.height, 1, (UINT)mli.rowPitch } }), nullptr);
|
||||
miplevel++;
|
||||
}
|
||||
|
||||
D3D12_RESOURCE_BARRIER barrier = {};
|
||||
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
barrier.Transition.pResource = vramTexture;
|
||||
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_GENERIC_READ;
|
||||
commandList->ResourceBarrier(1, &barrier);
|
||||
commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(vramTexture, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ));
|
||||
return vramTexture;
|
||||
}
|
||||
|
||||
|
@ -892,19 +873,17 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist)
|
|||
break;
|
||||
}
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE Handle = getCurrentResourceStorage().m_textureDescriptorsHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
Handle.ptr += (getCurrentResourceStorage().m_currentTextureIndex + usedTexture) * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
||||
m_device->CreateShaderResourceView(vramTexture, &srvDesc, Handle);
|
||||
m_device->CreateShaderResourceView(vramTexture, &srvDesc,
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_textureDescriptorsHeap->GetCPUDescriptorHandleForHeapStart()).Offset((UINT)getCurrentResourceStorage().m_currentTextureIndex + (UINT)usedTexture, g_descriptorStrideSRVCBVUAV));
|
||||
|
||||
if (getCurrentResourceStorage().m_currentSamplerIndex + 16 > 2048)
|
||||
{
|
||||
getCurrentResourceStorage().m_samplerDescriptorHeapIndex = 1;
|
||||
getCurrentResourceStorage().m_currentSamplerIndex = 0;
|
||||
}
|
||||
|
||||
Handle = getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex]->GetCPUDescriptorHandleForHeapStart();
|
||||
Handle.ptr += (getCurrentResourceStorage().m_currentSamplerIndex + usedTexture) * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
|
||||
m_device->CreateSampler(&getSamplerDesc(m_textures[i]), Handle);
|
||||
m_device->CreateSampler(&getSamplerDesc(m_textures[i]),
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex]->GetCPUDescriptorHandleForHeapStart())
|
||||
.Offset((UINT)getCurrentResourceStorage().m_currentSamplerIndex + (UINT)usedTexture, g_descriptorStrideSRVCBVUAV));
|
||||
|
||||
usedTexture++;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#if defined(DX12_SUPPORT)
|
||||
#include "D3D12GSRender.h"
|
||||
#include <d3dcompiler.h>
|
||||
#include "d3dx12.h"
|
||||
#define STRINGIFY(x) #x
|
||||
|
||||
extern PFN_D3D12_SERIALIZE_ROOT_SIGNATURE wrapD3D12SerializeRootSignature;
|
||||
|
@ -201,7 +202,7 @@ void D3D12GSRender::Shader::Init(ID3D12Device *device)
|
|||
device->CreateCommittedResource(
|
||||
&heapProp,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&getBufferResourceDesc(16 * sizeof(float)),
|
||||
&CD3DX12_RESOURCE_DESC::Buffer(16 * sizeof(float)),
|
||||
D3D12_RESOURCE_STATE_GENERIC_READ,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(&m_vertexBuffer)
|
||||
|
@ -212,17 +213,13 @@ void D3D12GSRender::Shader::Init(ID3D12Device *device)
|
|||
memcpy(tmp, quadVertex, 16 * sizeof(float));
|
||||
m_vertexBuffer->Unmap(0, nullptr);
|
||||
|
||||
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
|
||||
heapDesc.NumDescriptors = 2;
|
||||
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||
|
||||
D3D12_DESCRIPTOR_HEAP_DESC textureHeapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV , 2, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE };
|
||||
ThrowIfFailed(
|
||||
device->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&m_textureDescriptorHeap))
|
||||
device->CreateDescriptorHeap(&textureHeapDesc, IID_PPV_ARGS(&m_textureDescriptorHeap))
|
||||
);
|
||||
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
|
||||
D3D12_DESCRIPTOR_HEAP_DESC samplerHeapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER , 2, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE };
|
||||
ThrowIfFailed(
|
||||
device->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap))
|
||||
device->CreateDescriptorHeap(&samplerHeapDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue