mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-08-07 08:39:28 +00:00
d3d12: Use ThrowIfFailed instead of check to be inline with DX12 Samples
This commit is contained in:
parent
befe93784f
commit
9cb88b3a8d
6 changed files with 57 additions and 55 deletions
|
@ -11,11 +11,13 @@
|
||||||
|
|
||||||
#define SAFE_RELEASE(x) if (x) x->Release();
|
#define SAFE_RELEASE(x) if (x) x->Release();
|
||||||
|
|
||||||
inline
|
// From DX12 D3D11On12 Sample (MIT Licensed)
|
||||||
void check(HRESULT hr)
|
inline void ThrowIfFailed(HRESULT hr)
|
||||||
{
|
{
|
||||||
if (hr != 0)
|
if (FAILED(hr))
|
||||||
abort();
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -205,7 +205,7 @@ ID3D12Resource *createVertexBuffer(const VertexBufferFormat &vbf, const RSXVerte
|
||||||
size_t heapOffset = vertexIndexHeap.alloc(subBufferSize);
|
size_t heapOffset = vertexIndexHeap.alloc(subBufferSize);
|
||||||
|
|
||||||
ID3D12Resource *vertexBuffer;
|
ID3D12Resource *vertexBuffer;
|
||||||
check(device->CreatePlacedResource(
|
ThrowIfFailed(device->CreatePlacedResource(
|
||||||
vertexIndexHeap.m_heap,
|
vertexIndexHeap.m_heap,
|
||||||
heapOffset,
|
heapOffset,
|
||||||
&getBufferResourceDesc(subBufferSize),
|
&getBufferResourceDesc(subBufferSize),
|
||||||
|
@ -214,7 +214,7 @@ ID3D12Resource *createVertexBuffer(const VertexBufferFormat &vbf, const RSXVerte
|
||||||
IID_PPV_ARGS(&vertexBuffer)
|
IID_PPV_ARGS(&vertexBuffer)
|
||||||
));
|
));
|
||||||
void *bufferMap;
|
void *bufferMap;
|
||||||
check(vertexBuffer->Map(0, nullptr, (void**)&bufferMap));
|
ThrowIfFailed(vertexBuffer->Map(0, nullptr, (void**)&bufferMap));
|
||||||
memset(bufferMap, -1, subBufferSize);
|
memset(bufferMap, -1, subBufferSize);
|
||||||
#pragma omp parallel for
|
#pragma omp parallel for
|
||||||
for (int vertex = 0; vertex < vbf.elementCount; vertex++)
|
for (int vertex = 0; vertex < vbf.elementCount; vertex++)
|
||||||
|
@ -405,7 +405,7 @@ D3D12_INDEX_BUFFER_VIEW D3D12GSRender::uploadIndexBuffers(bool indexed_draw)
|
||||||
size_t heapOffset = m_vertexIndexData.alloc(subBufferSize);
|
size_t heapOffset = m_vertexIndexData.alloc(subBufferSize);
|
||||||
|
|
||||||
ID3D12Resource *indexBuffer;
|
ID3D12Resource *indexBuffer;
|
||||||
check(m_device->CreatePlacedResource(
|
ThrowIfFailed(m_device->CreatePlacedResource(
|
||||||
m_vertexIndexData.m_heap,
|
m_vertexIndexData.m_heap,
|
||||||
heapOffset,
|
heapOffset,
|
||||||
&getBufferResourceDesc(subBufferSize),
|
&getBufferResourceDesc(subBufferSize),
|
||||||
|
@ -415,7 +415,7 @@ D3D12_INDEX_BUFFER_VIEW D3D12GSRender::uploadIndexBuffers(bool indexed_draw)
|
||||||
));
|
));
|
||||||
|
|
||||||
void *bufferMap;
|
void *bufferMap;
|
||||||
check(indexBuffer->Map(0, nullptr, (void**)&bufferMap));
|
ThrowIfFailed(indexBuffer->Map(0, nullptr, (void**)&bufferMap));
|
||||||
if (indexed_draw && !forcedIndexBuffer)
|
if (indexed_draw && !forcedIndexBuffer)
|
||||||
streamBuffer(bufferMap, m_indexed_array.m_data.data(), subBufferSize);
|
streamBuffer(bufferMap, m_indexed_array.m_data.data(), subBufferSize);
|
||||||
else if (indexed_draw && forcedIndexBuffer)
|
else if (indexed_draw && forcedIndexBuffer)
|
||||||
|
@ -499,7 +499,7 @@ void D3D12GSRender::setScaleOffset()
|
||||||
D3D12_RANGE range = { heapOffset, heapOffset + 256 };
|
D3D12_RANGE range = { heapOffset, heapOffset + 256 };
|
||||||
|
|
||||||
void *scaleOffsetMap;
|
void *scaleOffsetMap;
|
||||||
check(m_constantsData.m_heap->Map(0, &range, &scaleOffsetMap));
|
ThrowIfFailed(m_constantsData.m_heap->Map(0, &range, &scaleOffsetMap));
|
||||||
streamToBuffer((char*)scaleOffsetMap + heapOffset, scaleOffsetMat, 16 * sizeof(float));
|
streamToBuffer((char*)scaleOffsetMap + heapOffset, scaleOffsetMat, 16 * sizeof(float));
|
||||||
int isAlphaTested = m_set_alpha_test;
|
int isAlphaTested = m_set_alpha_test;
|
||||||
memcpy((char*)scaleOffsetMap + heapOffset + 16 * sizeof(float), &isAlphaTested, sizeof(int));
|
memcpy((char*)scaleOffsetMap + heapOffset + 16 * sizeof(float), &isAlphaTested, sizeof(int));
|
||||||
|
@ -531,7 +531,7 @@ void D3D12GSRender::FillVertexShaderConstantsBuffer()
|
||||||
D3D12_RANGE range = { heapOffset, heapOffset + bufferSize };
|
D3D12_RANGE range = { heapOffset, heapOffset + bufferSize };
|
||||||
|
|
||||||
void *constantsBufferMap;
|
void *constantsBufferMap;
|
||||||
check(m_constantsData.m_heap->Map(0, &range, &constantsBufferMap));
|
ThrowIfFailed(m_constantsData.m_heap->Map(0, &range, &constantsBufferMap));
|
||||||
for (const auto &vertexConstants : m_vertexConstants)
|
for (const auto &vertexConstants : m_vertexConstants)
|
||||||
{
|
{
|
||||||
float data[4] = {
|
float data[4] = {
|
||||||
|
@ -568,7 +568,7 @@ void D3D12GSRender::FillPixelShaderConstantsBuffer()
|
||||||
|
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
void *constantsBufferMap;
|
void *constantsBufferMap;
|
||||||
check(m_constantsData.m_heap->Map(0, &range, &constantsBufferMap));
|
ThrowIfFailed(m_constantsData.m_heap->Map(0, &range, &constantsBufferMap));
|
||||||
for (size_t offsetInFP : fragmentOffset)
|
for (size_t offsetInFP : fragmentOffset)
|
||||||
{
|
{
|
||||||
u32 vector[4];
|
u32 vector[4];
|
||||||
|
|
|
@ -119,31 +119,31 @@ void D3D12GSRender::ResourceStorage::Init(ID3D12Device *device)
|
||||||
// Create a global command allocator
|
// Create a global command allocator
|
||||||
device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_commandAllocator));
|
device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_commandAllocator));
|
||||||
device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_textureUploadCommandAllocator));
|
device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_textureUploadCommandAllocator));
|
||||||
check(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COPY, IID_PPV_ARGS(&m_downloadCommandAllocator)));
|
ThrowIfFailed(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COPY, IID_PPV_ARGS(&m_downloadCommandAllocator)));
|
||||||
|
|
||||||
D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = {};
|
D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = {};
|
||||||
descriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
descriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||||
descriptorHeapDesc.NumDescriptors = 10000; // For safety
|
descriptorHeapDesc.NumDescriptors = 10000; // For safety
|
||||||
descriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
descriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||||
check(device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(&m_constantsBufferDescriptorsHeap)));
|
ThrowIfFailed(device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(&m_constantsBufferDescriptorsHeap)));
|
||||||
|
|
||||||
|
|
||||||
descriptorHeapDesc = {};
|
descriptorHeapDesc = {};
|
||||||
descriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
descriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||||
descriptorHeapDesc.NumDescriptors = 10000; // For safety
|
descriptorHeapDesc.NumDescriptors = 10000; // For safety
|
||||||
descriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
descriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||||
check(device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(&m_scaleOffsetDescriptorHeap)));
|
ThrowIfFailed(device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(&m_scaleOffsetDescriptorHeap)));
|
||||||
|
|
||||||
D3D12_DESCRIPTOR_HEAP_DESC textureDescriptorDesc = {};
|
D3D12_DESCRIPTOR_HEAP_DESC textureDescriptorDesc = {};
|
||||||
textureDescriptorDesc.NumDescriptors = 10000; // For safety
|
textureDescriptorDesc.NumDescriptors = 10000; // For safety
|
||||||
textureDescriptorDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
textureDescriptorDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||||
textureDescriptorDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
textureDescriptorDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||||
check(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_textureDescriptorsHeap)));
|
ThrowIfFailed(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_textureDescriptorsHeap)));
|
||||||
|
|
||||||
textureDescriptorDesc.NumDescriptors = 2048; // For safety
|
textureDescriptorDesc.NumDescriptors = 2048; // For safety
|
||||||
textureDescriptorDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
|
textureDescriptorDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
|
||||||
check(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap[0])));
|
ThrowIfFailed(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap[0])));
|
||||||
check(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap[1])));
|
ThrowIfFailed(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap[1])));
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D12GSRender::ResourceStorage::Release()
|
void D3D12GSRender::ResourceStorage::Release()
|
||||||
|
@ -221,13 +221,13 @@ D3D12GSRender::D3D12GSRender()
|
||||||
}
|
}
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<IDXGIFactory4> dxgiFactory;
|
Microsoft::WRL::ComPtr<IDXGIFactory4> dxgiFactory;
|
||||||
check(CreateDXGIFactory(IID_PPV_ARGS(&dxgiFactory)));
|
ThrowIfFailed(CreateDXGIFactory(IID_PPV_ARGS(&dxgiFactory)));
|
||||||
// Create adapter
|
// Create adapter
|
||||||
IDXGIAdapter* adaptater = nullptr;
|
IDXGIAdapter* adaptater = nullptr;
|
||||||
switch (Ini.GSD3DAdaptater.GetValue())
|
switch (Ini.GSD3DAdaptater.GetValue())
|
||||||
{
|
{
|
||||||
case 0: // WARP
|
case 0: // WARP
|
||||||
check(dxgiFactory->EnumWarpAdapter(IID_PPV_ARGS(&adaptater)));
|
ThrowIfFailed(dxgiFactory->EnumWarpAdapter(IID_PPV_ARGS(&adaptater)));
|
||||||
break;
|
break;
|
||||||
case 1: // Default
|
case 1: // Default
|
||||||
dxgiFactory->EnumAdapters(0, &adaptater);
|
dxgiFactory->EnumAdapters(0, &adaptater);
|
||||||
|
@ -236,14 +236,14 @@ D3D12GSRender::D3D12GSRender()
|
||||||
dxgiFactory->EnumAdapters(Ini.GSD3DAdaptater.GetValue() - 2,&adaptater);
|
dxgiFactory->EnumAdapters(Ini.GSD3DAdaptater.GetValue() - 2,&adaptater);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
check(wrapD3D12CreateDevice(adaptater, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&m_device)));
|
ThrowIfFailed(wrapD3D12CreateDevice(adaptater, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&m_device)));
|
||||||
|
|
||||||
// Queues
|
// Queues
|
||||||
D3D12_COMMAND_QUEUE_DESC copyQueueDesc = {}, graphicQueueDesc = {};
|
D3D12_COMMAND_QUEUE_DESC copyQueueDesc = {}, graphicQueueDesc = {};
|
||||||
copyQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_COPY;
|
copyQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_COPY;
|
||||||
graphicQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
graphicQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||||
check(m_device->CreateCommandQueue(©QueueDesc, IID_PPV_ARGS(&m_commandQueueCopy)));
|
ThrowIfFailed(m_device->CreateCommandQueue(©QueueDesc, IID_PPV_ARGS(&m_commandQueueCopy)));
|
||||||
check(m_device->CreateCommandQueue(&graphicQueueDesc, IID_PPV_ARGS(&m_commandQueueGraphic)));
|
ThrowIfFailed(m_device->CreateCommandQueue(&graphicQueueDesc, IID_PPV_ARGS(&m_commandQueueGraphic)));
|
||||||
|
|
||||||
g_descriptorStrideSRVCBVUAV = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
g_descriptorStrideSRVCBVUAV = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
||||||
g_descriptorStrideDSV = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
|
g_descriptorStrideDSV = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
|
||||||
|
@ -266,7 +266,7 @@ D3D12GSRender::D3D12GSRender()
|
||||||
swapChain.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
|
swapChain.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
|
||||||
swapChain.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
swapChain.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
||||||
|
|
||||||
check(dxgiFactory->CreateSwapChain(m_commandQueueGraphic, &swapChain, (IDXGISwapChain**)&m_swapChain));
|
ThrowIfFailed(dxgiFactory->CreateSwapChain(m_commandQueueGraphic, &swapChain, (IDXGISwapChain**)&m_swapChain));
|
||||||
m_swapChain->GetBuffer(0, IID_PPV_ARGS(&m_backBuffer[0]));
|
m_swapChain->GetBuffer(0, IID_PPV_ARGS(&m_backBuffer[0]));
|
||||||
m_swapChain->GetBuffer(1, IID_PPV_ARGS(&m_backBuffer[1]));
|
m_swapChain->GetBuffer(1, IID_PPV_ARGS(&m_backBuffer[1]));
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ D3D12GSRender::D3D12GSRender()
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ID3DBlob> rootSignatureBlob;
|
Microsoft::WRL::ComPtr<ID3DBlob> rootSignatureBlob;
|
||||||
Microsoft::WRL::ComPtr<ID3DBlob> errorBlob;
|
Microsoft::WRL::ComPtr<ID3DBlob> errorBlob;
|
||||||
check(wrapD3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &rootSignatureBlob, &errorBlob));
|
ThrowIfFailed(wrapD3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &rootSignatureBlob, &errorBlob));
|
||||||
|
|
||||||
m_device->CreateRootSignature(0,
|
m_device->CreateRootSignature(0,
|
||||||
rootSignatureBlob->GetBufferPointer(),
|
rootSignatureBlob->GetBufferPointer(),
|
||||||
|
@ -344,7 +344,7 @@ D3D12GSRender::D3D12GSRender()
|
||||||
|
|
||||||
D3D12_HEAP_PROPERTIES hp = {};
|
D3D12_HEAP_PROPERTIES hp = {};
|
||||||
hp.Type = D3D12_HEAP_TYPE_DEFAULT;
|
hp.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||||
check(
|
ThrowIfFailed(
|
||||||
m_device->CreateCommittedResource(
|
m_device->CreateCommittedResource(
|
||||||
&hp,
|
&hp,
|
||||||
D3D12_HEAP_FLAG_NONE,
|
D3D12_HEAP_FLAG_NONE,
|
||||||
|
@ -432,7 +432,7 @@ void D3D12GSRender::Clear(u32 cmd)
|
||||||
assert(cmd == NV4097_CLEAR_SURFACE);
|
assert(cmd == NV4097_CLEAR_SURFACE);
|
||||||
|
|
||||||
ID3D12GraphicsCommandList *commandList;
|
ID3D12GraphicsCommandList *commandList;
|
||||||
check(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_commandAllocator, nullptr, IID_PPV_ARGS(&commandList)));
|
ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_commandAllocator, nullptr, IID_PPV_ARGS(&commandList)));
|
||||||
getCurrentResourceStorage().m_inflightCommandList.push_back(commandList);
|
getCurrentResourceStorage().m_inflightCommandList.push_back(commandList);
|
||||||
|
|
||||||
PrepareRenderTargets(commandList);
|
PrepareRenderTargets(commandList);
|
||||||
|
@ -503,7 +503,7 @@ void D3D12GSRender::Clear(u32 cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
check(commandList->Close());
|
ThrowIfFailed(commandList->Close());
|
||||||
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**) &commandList);
|
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**) &commandList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -716,7 +716,7 @@ void D3D12GSRender::Draw()
|
||||||
else
|
else
|
||||||
commandList->DrawInstanced((UINT)m_renderingInfo.m_count, 1, (UINT)m_renderingInfo.m_baseVertex, 0);
|
commandList->DrawInstanced((UINT)m_renderingInfo.m_count, 1, (UINT)m_renderingInfo.m_baseVertex, 0);
|
||||||
|
|
||||||
check(commandList->Close());
|
ThrowIfFailed(commandList->Close());
|
||||||
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&commandList);
|
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&commandList);
|
||||||
m_indexed_array.Reset();
|
m_indexed_array.Reset();
|
||||||
}
|
}
|
||||||
|
@ -771,7 +771,7 @@ void D3D12GSRender::Flip()
|
||||||
assert(m_textureUploadData.canAlloc(textureSize));
|
assert(m_textureUploadData.canAlloc(textureSize));
|
||||||
size_t heapOffset = m_textureUploadData.alloc(textureSize);
|
size_t heapOffset = m_textureUploadData.alloc(textureSize);
|
||||||
|
|
||||||
check(m_device->CreatePlacedResource(
|
ThrowIfFailed(m_device->CreatePlacedResource(
|
||||||
m_textureUploadData.m_heap,
|
m_textureUploadData.m_heap,
|
||||||
heapOffset,
|
heapOffset,
|
||||||
&getBufferResourceDesc(textureSize),
|
&getBufferResourceDesc(textureSize),
|
||||||
|
@ -782,13 +782,13 @@ void D3D12GSRender::Flip()
|
||||||
m_textureUploadData.m_resourceStoredSinceLastSync.push_back(std::make_tuple(heapOffset, textureSize, stagingTexture));
|
m_textureUploadData.m_resourceStoredSinceLastSync.push_back(std::make_tuple(heapOffset, textureSize, stagingTexture));
|
||||||
|
|
||||||
void *dstBuffer;
|
void *dstBuffer;
|
||||||
check(stagingTexture->Map(0, nullptr, &dstBuffer));
|
ThrowIfFailed(stagingTexture->Map(0, nullptr, &dstBuffer));
|
||||||
for (unsigned row = 0; row < h; row++)
|
for (unsigned row = 0; row < h; row++)
|
||||||
memcpy((char*)dstBuffer + row * rowPitch, (char*)src_buffer + row * w * 4, w * 4);
|
memcpy((char*)dstBuffer + row * rowPitch, (char*)src_buffer + row * w * 4, w * 4);
|
||||||
stagingTexture->Unmap(0, nullptr);
|
stagingTexture->Unmap(0, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
check(
|
ThrowIfFailed(
|
||||||
m_device->CreateCommittedResource(
|
m_device->CreateCommittedResource(
|
||||||
&heapProp,
|
&heapProp,
|
||||||
D3D12_HEAP_FLAG_NONE,
|
D3D12_HEAP_FLAG_NONE,
|
||||||
|
@ -896,10 +896,10 @@ void D3D12GSRender::Flip()
|
||||||
commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
|
commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
|
||||||
if (isFlipSurfaceInLocalMemory(m_surface_color_target) && m_rtts.m_currentlyBoundRenderTargets[0] != nullptr)
|
if (isFlipSurfaceInLocalMemory(m_surface_color_target) && m_rtts.m_currentlyBoundRenderTargets[0] != nullptr)
|
||||||
commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundRenderTargets[0], D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundRenderTargets[0], D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
||||||
check(commandList->Close());
|
ThrowIfFailed(commandList->Close());
|
||||||
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&commandList);
|
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&commandList);
|
||||||
|
|
||||||
check(m_swapChain->Present(Ini.GSVSyncEnable.GetValue() ? 1 : 0, 0));
|
ThrowIfFailed(m_swapChain->Present(Ini.GSVSyncEnable.GetValue() ? 1 : 0, 0));
|
||||||
// Add an event signaling queue completion
|
// Add an event signaling queue completion
|
||||||
|
|
||||||
ResourceStorage &storage = getNonCurrentResourceStorage();
|
ResourceStorage &storage = getNonCurrentResourceStorage();
|
||||||
|
@ -996,7 +996,7 @@ ID3D12Resource * D3D12GSRender::writeColorBuffer(ID3D12Resource * RTT, ID3D12Gra
|
||||||
size_t heapOffset = m_readbackResources.alloc(sizeInByte);
|
size_t heapOffset = m_readbackResources.alloc(sizeInByte);
|
||||||
|
|
||||||
resdesc = getBufferResourceDesc(sizeInByte);
|
resdesc = getBufferResourceDesc(sizeInByte);
|
||||||
check(
|
ThrowIfFailed(
|
||||||
m_device->CreatePlacedResource(
|
m_device->CreatePlacedResource(
|
||||||
m_readbackResources.m_heap,
|
m_readbackResources.m_heap,
|
||||||
heapOffset,
|
heapOffset,
|
||||||
|
@ -1030,7 +1030,7 @@ static
|
||||||
void copyToCellRamAndRelease(void *dstAddress, ID3D12Resource *res, size_t dstPitch, size_t srcPitch, size_t width, size_t height)
|
void copyToCellRamAndRelease(void *dstAddress, ID3D12Resource *res, size_t dstPitch, size_t srcPitch, size_t width, size_t height)
|
||||||
{
|
{
|
||||||
void *srcBuffer;
|
void *srcBuffer;
|
||||||
check(res->Map(0, nullptr, &srcBuffer));
|
ThrowIfFailed(res->Map(0, nullptr, &srcBuffer));
|
||||||
for (unsigned row = 0; row < height; row++)
|
for (unsigned row = 0; row < height; row++)
|
||||||
memcpy((char*)dstAddress + row * dstPitch, (char*)srcBuffer + row * srcPitch, srcPitch);
|
memcpy((char*)dstAddress + row * dstPitch, (char*)srcBuffer + row * srcPitch, srcPitch);
|
||||||
res->Unmap(0, nullptr);
|
res->Unmap(0, nullptr);
|
||||||
|
@ -1050,7 +1050,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
||||||
|
|
||||||
|
|
||||||
ID3D12Fence *fence;
|
ID3D12Fence *fence;
|
||||||
check(
|
ThrowIfFailed(
|
||||||
m_device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence))
|
m_device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence))
|
||||||
);
|
);
|
||||||
HANDLE handle = CreateEvent(0, FALSE, FALSE, 0);
|
HANDLE handle = CreateEvent(0, FALSE, FALSE, 0);
|
||||||
|
@ -1076,7 +1076,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
||||||
assert(m_UAVHeap.canAlloc(sizeInByte));
|
assert(m_UAVHeap.canAlloc(sizeInByte));
|
||||||
size_t heapOffset = m_UAVHeap.alloc(sizeInByte);
|
size_t heapOffset = m_UAVHeap.alloc(sizeInByte);
|
||||||
|
|
||||||
check(
|
ThrowIfFailed(
|
||||||
m_device->CreatePlacedResource(
|
m_device->CreatePlacedResource(
|
||||||
m_UAVHeap.m_heap,
|
m_UAVHeap.m_heap,
|
||||||
heapOffset,
|
heapOffset,
|
||||||
|
@ -1093,7 +1093,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
||||||
heapOffset = m_readbackResources.alloc(sizeInByte);
|
heapOffset = m_readbackResources.alloc(sizeInByte);
|
||||||
|
|
||||||
resdesc = getBufferResourceDesc(sizeInByte);
|
resdesc = getBufferResourceDesc(sizeInByte);
|
||||||
check(
|
ThrowIfFailed(
|
||||||
m_device->CreatePlacedResource(
|
m_device->CreatePlacedResource(
|
||||||
m_readbackResources.m_heap,
|
m_readbackResources.m_heap,
|
||||||
heapOffset,
|
heapOffset,
|
||||||
|
@ -1105,7 +1105,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
||||||
);
|
);
|
||||||
m_readbackResources.m_resourceStoredSinceLastSync.push_back(std::make_tuple(heapOffset, sizeInByte, writeDest));
|
m_readbackResources.m_resourceStoredSinceLastSync.push_back(std::make_tuple(heapOffset, sizeInByte, writeDest));
|
||||||
|
|
||||||
check(
|
ThrowIfFailed(
|
||||||
m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_commandAllocator, nullptr, IID_PPV_ARGS(&convertCommandList))
|
m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_commandAllocator, nullptr, IID_PPV_ARGS(&convertCommandList))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1113,7 +1113,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
||||||
descriptorHeapDesc.NumDescriptors = 2;
|
descriptorHeapDesc.NumDescriptors = 2;
|
||||||
descriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
descriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||||
descriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
descriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||||
check(
|
ThrowIfFailed(
|
||||||
m_device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(&descriptorHeap))
|
m_device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(&descriptorHeap))
|
||||||
);
|
);
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE Handle = descriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
D3D12_CPU_DESCRIPTOR_HANDLE Handle = descriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
||||||
|
@ -1164,14 +1164,14 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
||||||
convertCommandList->ResourceBarrier(2, barriers);
|
convertCommandList->ResourceBarrier(2, barriers);
|
||||||
convertCommandList->ResourceBarrier(1, &getResourceBarrierTransition(depthConverted, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE));
|
convertCommandList->ResourceBarrier(1, &getResourceBarrierTransition(depthConverted, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE));
|
||||||
|
|
||||||
check(convertCommandList->Close());
|
ThrowIfFailed(convertCommandList->Close());
|
||||||
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&convertCommandList);
|
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&convertCommandList);
|
||||||
}
|
}
|
||||||
|
|
||||||
ID3D12GraphicsCommandList *downloadCommandList;
|
ID3D12GraphicsCommandList *downloadCommandList;
|
||||||
if (needTransfer)
|
if (needTransfer)
|
||||||
{
|
{
|
||||||
check(
|
ThrowIfFailed(
|
||||||
m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_commandAllocator, nullptr, IID_PPV_ARGS(&downloadCommandList))
|
m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_commandAllocator, nullptr, IID_PPV_ARGS(&downloadCommandList))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1237,7 +1237,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
||||||
}
|
}
|
||||||
if (needTransfer)
|
if (needTransfer)
|
||||||
{
|
{
|
||||||
check(downloadCommandList->Close());
|
ThrowIfFailed(downloadCommandList->Close());
|
||||||
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&downloadCommandList);
|
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&downloadCommandList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1259,7 +1259,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
|
||||||
auto ptr = vm::get_ptr<void>(address);
|
auto ptr = vm::get_ptr<void>(address);
|
||||||
char *ptrAsChar = (char*)ptr;
|
char *ptrAsChar = (char*)ptr;
|
||||||
unsigned char *writeDestPtr;
|
unsigned char *writeDestPtr;
|
||||||
check(writeDest->Map(0, nullptr, (void**)&writeDestPtr));
|
ThrowIfFailed(writeDest->Map(0, nullptr, (void**)&writeDestPtr));
|
||||||
// TODO : this should be done by the gpu
|
// TODO : this should be done by the gpu
|
||||||
for (unsigned row = 0; row < m_surface_clip_h; row++)
|
for (unsigned row = 0; row < m_surface_clip_h; row++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -82,7 +82,7 @@ struct InitHeap<ID3D12Heap>
|
||||||
heapDesc.SizeInBytes = heapSize;
|
heapDesc.SizeInBytes = heapSize;
|
||||||
heapDesc.Properties.Type = type;
|
heapDesc.Properties.Type = type;
|
||||||
heapDesc.Flags = flags;
|
heapDesc.Flags = flags;
|
||||||
check(device->CreateHeap(&heapDesc, IID_PPV_ARGS(&result)));
|
ThrowIfFailed(device->CreateHeap(&heapDesc, IID_PPV_ARGS(&result)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -95,7 +95,7 @@ struct InitHeap<ID3D12Resource>
|
||||||
ID3D12Resource *result;
|
ID3D12Resource *result;
|
||||||
D3D12_HEAP_PROPERTIES heapProperties = {};
|
D3D12_HEAP_PROPERTIES heapProperties = {};
|
||||||
heapProperties.Type = type;
|
heapProperties.Type = type;
|
||||||
check(device->CreateCommittedResource(&heapProperties,
|
ThrowIfFailed(device->CreateCommittedResource(&heapProperties,
|
||||||
flags,
|
flags,
|
||||||
&getBufferResourceDesc(heapSize),
|
&getBufferResourceDesc(heapSize),
|
||||||
D3D12_RESOURCE_STATE_GENERIC_READ,
|
D3D12_RESOURCE_STATE_GENERIC_READ,
|
||||||
|
|
|
@ -555,7 +555,7 @@ ID3D12Resource *uploadSingleTexture(
|
||||||
assert(textureBuffersHeap.canAlloc(textureSize));
|
assert(textureBuffersHeap.canAlloc(textureSize));
|
||||||
size_t heapOffset = textureBuffersHeap.alloc(textureSize);
|
size_t heapOffset = textureBuffersHeap.alloc(textureSize);
|
||||||
|
|
||||||
check(device->CreatePlacedResource(
|
ThrowIfFailed(device->CreatePlacedResource(
|
||||||
textureBuffersHeap.m_heap,
|
textureBuffersHeap.m_heap,
|
||||||
heapOffset,
|
heapOffset,
|
||||||
&getBufferResourceDesc(textureSize),
|
&getBufferResourceDesc(textureSize),
|
||||||
|
@ -567,7 +567,7 @@ ID3D12Resource *uploadSingleTexture(
|
||||||
|
|
||||||
auto pixels = vm::get_ptr<const u8>(texaddr);
|
auto pixels = vm::get_ptr<const u8>(texaddr);
|
||||||
void *textureData;
|
void *textureData;
|
||||||
check(Texture->Map(0, nullptr, (void**)&textureData));
|
ThrowIfFailed(Texture->Map(0, nullptr, (void**)&textureData));
|
||||||
std::vector<MipmapLevelInfo> mipInfos;
|
std::vector<MipmapLevelInfo> mipInfos;
|
||||||
|
|
||||||
switch (format)
|
switch (format)
|
||||||
|
@ -616,7 +616,7 @@ ID3D12Resource *uploadSingleTexture(
|
||||||
D3D12_HEAP_PROPERTIES heapProp = {};
|
D3D12_HEAP_PROPERTIES heapProp = {};
|
||||||
heapProp.Type = D3D12_HEAP_TYPE_DEFAULT;
|
heapProp.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||||
|
|
||||||
check(device->CreateCommittedResource(
|
ThrowIfFailed(device->CreateCommittedResource(
|
||||||
&heapProp,
|
&heapProp,
|
||||||
D3D12_HEAP_FLAG_NONE,
|
D3D12_HEAP_FLAG_NONE,
|
||||||
&texturedesc,
|
&texturedesc,
|
||||||
|
|
|
@ -185,7 +185,7 @@ void D3D12GSRender::Shader::Init(ID3D12Device *device)
|
||||||
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
|
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
|
||||||
psoDesc.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
|
psoDesc.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
|
||||||
|
|
||||||
check(device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_PSO)));
|
ThrowIfFailed(device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_PSO)));
|
||||||
|
|
||||||
|
|
||||||
float quadVertex[16] = {
|
float quadVertex[16] = {
|
||||||
|
@ -197,7 +197,7 @@ void D3D12GSRender::Shader::Init(ID3D12Device *device)
|
||||||
|
|
||||||
D3D12_HEAP_PROPERTIES heapProp = {};
|
D3D12_HEAP_PROPERTIES heapProp = {};
|
||||||
heapProp.Type = D3D12_HEAP_TYPE_UPLOAD;
|
heapProp.Type = D3D12_HEAP_TYPE_UPLOAD;
|
||||||
check(
|
ThrowIfFailed(
|
||||||
device->CreateCommittedResource(
|
device->CreateCommittedResource(
|
||||||
&heapProp,
|
&heapProp,
|
||||||
D3D12_HEAP_FLAG_NONE,
|
D3D12_HEAP_FLAG_NONE,
|
||||||
|
@ -217,11 +217,11 @@ void D3D12GSRender::Shader::Init(ID3D12Device *device)
|
||||||
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||||
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||||
|
|
||||||
check(
|
ThrowIfFailed(
|
||||||
device->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&m_textureDescriptorHeap))
|
device->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&m_textureDescriptorHeap))
|
||||||
);
|
);
|
||||||
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
|
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
|
||||||
check(
|
ThrowIfFailed(
|
||||||
device->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap))
|
device->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ void D3D12GSRender::Shader::Init(ID3D12Device *device)
|
||||||
void D3D12GSRender::initConvertShader()
|
void D3D12GSRender::initConvertShader()
|
||||||
{
|
{
|
||||||
const auto &p = compileF32toU8CS();
|
const auto &p = compileF32toU8CS();
|
||||||
check(
|
ThrowIfFailed(
|
||||||
m_device->CreateRootSignature(0, p.second->GetBufferPointer(), p.second->GetBufferSize(), IID_PPV_ARGS(&m_convertRootSignature))
|
m_device->CreateRootSignature(0, p.second->GetBufferPointer(), p.second->GetBufferSize(), IID_PPV_ARGS(&m_convertRootSignature))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ void D3D12GSRender::initConvertShader()
|
||||||
computePipelineStateDesc.CS.pShaderBytecode = p.first->GetBufferPointer();
|
computePipelineStateDesc.CS.pShaderBytecode = p.first->GetBufferPointer();
|
||||||
computePipelineStateDesc.pRootSignature = m_convertRootSignature;
|
computePipelineStateDesc.pRootSignature = m_convertRootSignature;
|
||||||
|
|
||||||
check(
|
ThrowIfFailed(
|
||||||
m_device->CreateComputePipelineState(&computePipelineStateDesc, IID_PPV_ARGS(&m_convertPSO))
|
m_device->CreateComputePipelineState(&computePipelineStateDesc, IID_PPV_ARGS(&m_convertPSO))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue