d3d12: clean code

This commit is contained in:
Vincent Lejeune 2015-09-20 18:34:12 +02:00
parent f10c812301
commit 23bd197bd4
3 changed files with 100 additions and 122 deletions

View File

@ -229,8 +229,6 @@ ComPtr<ID3D12Resource> createVertexBuffer(const VertexBufferFormat &vbf, const R
)); ));
void *bufferMap; void *bufferMap;
ThrowIfFailed(vertexBuffer->Map(0, nullptr, (void**)&bufferMap)); ThrowIfFailed(vertexBuffer->Map(0, nullptr, (void**)&bufferMap));
memset(bufferMap, -1, subBufferSize);
#pragma omp parallel for
for (int vertex = 0; vertex < vbf.elementCount; vertex++) for (int vertex = 0; vertex < vbf.elementCount; vertex++)
{ {
for (size_t attributeId : vbf.attributeId) for (size_t attributeId : vbf.attributeId)
@ -243,7 +241,7 @@ ComPtr<ID3D12Resource> createVertexBuffer(const VertexBufferFormat &vbf, const R
size_t offset = (size_t)vertexData[attributeId].addr + baseOffset - vbf.range.first; size_t offset = (size_t)vertexData[attributeId].addr + baseOffset - vbf.range.first;
size_t tsize = vertexData[attributeId].GetTypeSize(); size_t tsize = vertexData[attributeId].GetTypeSize();
size_t size = vertexData[attributeId].size; size_t size = vertexData[attributeId].size;
auto src = vm::get_ptr<const u8>(vertexData[attributeId].addr + baseOffset + (int)vbf.stride * vertex); auto src = vm::get_ptr<const u8>(vertexData[attributeId].addr + (u32)baseOffset + (u32)vbf.stride * vertex);
char* dst = (char*)bufferMap + offset + vbf.stride * vertex; char* dst = (char*)bufferMap + offset + vbf.stride * vertex;
switch (tsize) switch (tsize)

View File

@ -373,7 +373,6 @@ void D3D12GSRender::OnReset()
void D3D12GSRender::Clear(u32 cmd) void D3D12GSRender::Clear(u32 cmd)
{ {
std::chrono::time_point<std::chrono::system_clock> startDuration = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> startDuration = std::chrono::system_clock::now();
PrepareRenderTargets(getCurrentResourceStorage().m_commandList.Get());
assert(cmd == NV4097_CLEAR_SURFACE); assert(cmd == NV4097_CLEAR_SURFACE);
PrepareRenderTargets(getCurrentResourceStorage().m_commandList.Get()); PrepareRenderTargets(getCurrentResourceStorage().m_commandList.Get());
@ -950,15 +949,15 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
// Except when a semaphore is written by RSX // Except when a semaphore is written by RSX
ID3D12Fence *fence; ComPtr<ID3D12Fence> fence;
ThrowIfFailed( 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.GetAddressOf()))
); );
HANDLE handle = CreateEvent(0, FALSE, FALSE, 0); HANDLE handle = CreateEvent(0, FALSE, FALSE, 0);
fence->SetEventOnCompletion(1, handle); fence->SetEventOnCompletion(1, handle);
ComPtr<ID3D12Resource> writeDest, depthConverted; ComPtr<ID3D12Resource> writeDest, depthConverted;
ID3D12DescriptorHeap *descriptorHeap; ComPtr<ID3D12DescriptorHeap> descriptorHeap;
size_t depthRowPitch = m_surface_clip_w; size_t depthRowPitch = m_surface_clip_w;
depthRowPitch = (depthRowPitch + 255) & ~255; depthRowPitch = (depthRowPitch + 255) & ~255;
@ -981,7 +980,6 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
IID_PPV_ARGS(depthConverted.GetAddressOf()) IID_PPV_ARGS(depthConverted.GetAddressOf())
) )
); );
getCurrentResourceStorage().m_singleFrameLifetimeResources.push_back(depthConverted);
sizeInByte = depthRowPitch * m_surface_clip_h; sizeInByte = depthRowPitch * m_surface_clip_h;
assert(m_readbackResources.canAlloc(sizeInByte)); assert(m_readbackResources.canAlloc(sizeInByte));
@ -997,11 +995,10 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
IID_PPV_ARGS(writeDest.GetAddressOf()) IID_PPV_ARGS(writeDest.GetAddressOf())
) )
); );
getCurrentResourceStorage().m_singleFrameLifetimeResources.push_back(writeDest);
D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV , 2, 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( ThrowIfFailed(
m_device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(&descriptorHeap)) m_device->CreateDescriptorHeap(&descriptorHeapDesc, IID_PPV_ARGS(descriptorHeap.GetAddressOf()))
); );
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
switch (m_surface_depth_format) switch (m_surface_depth_format)
@ -1034,7 +1031,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
getCurrentResourceStorage().m_commandList->SetPipelineState(m_convertPSO); getCurrentResourceStorage().m_commandList->SetPipelineState(m_convertPSO);
getCurrentResourceStorage().m_commandList->SetComputeRootSignature(m_convertRootSignature); getCurrentResourceStorage().m_commandList->SetComputeRootSignature(m_convertRootSignature);
getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, &descriptorHeap); getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, descriptorHeap.GetAddressOf());
getCurrentResourceStorage().m_commandList->SetComputeRootDescriptorTable(0, descriptorHeap->GetGPUDescriptorHandleForHeapStart()); getCurrentResourceStorage().m_commandList->SetComputeRootDescriptorTable(0, descriptorHeap->GetGPUDescriptorHandleForHeapStart());
getCurrentResourceStorage().m_commandList->Dispatch(m_surface_clip_w / 8, m_surface_clip_h / 8, 1); getCurrentResourceStorage().m_commandList->Dispatch(m_surface_clip_w / 8, m_surface_clip_h / 8, 1);
@ -1045,10 +1042,6 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
}; };
getCurrentResourceStorage().m_commandList->ResourceBarrier(2, barriers); getCurrentResourceStorage().m_commandList->ResourceBarrier(2, barriers);
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(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())
{
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, 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); &CD3DX12_TEXTURE_COPY_LOCATION(depthConverted.Get(), 0), nullptr);
@ -1103,12 +1096,9 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
} }
//Wait for result //Wait for result
m_commandQueueGraphic->Signal(fence, 1); m_commandQueueGraphic->Signal(fence.Get(), 1);
auto tmp = [=]() {
WaitForSingleObject(handle, INFINITE); WaitForSingleObject(handle, INFINITE);
CloseHandle(handle); CloseHandle(handle);
fence->Release();
if (m_set_context_dma_z && Ini.GSDumpDepthBuffer.GetValue()) if (m_set_context_dma_z && Ini.GSDumpDepthBuffer.GetValue())
{ {
@ -1117,7 +1107,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
char *ptrAsChar = (char*)ptr; char *ptrAsChar = (char*)ptr;
unsigned char *writeDestPtr; unsigned char *writeDestPtr;
ThrowIfFailed(writeDest->Map(0, nullptr, (void**)&writeDestPtr)); ThrowIfFailed(writeDest->Map(0, nullptr, (void**)&writeDestPtr));
// 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++)
{ {
for (unsigned i = 0; i < m_surface_clip_w; i++) for (unsigned i = 0; i < m_surface_clip_w; i++)
@ -1129,7 +1119,6 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
ptrAsChar[4 * (row * m_surface_clip_w + i) + 3] = c; ptrAsChar[4 * (row * m_surface_clip_w + i) + 3] = c;
} }
} }
descriptorHeap->Release();
} }
size_t srcPitch, dstPitch; size_t srcPitch, dstPitch;
@ -1151,7 +1140,6 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
{ {
case CELL_GCM_SURFACE_TARGET_NONE: case CELL_GCM_SURFACE_TARGET_NONE:
break; break;
case CELL_GCM_SURFACE_TARGET_0: case CELL_GCM_SURFACE_TARGET_0:
{ {
u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000);
@ -1159,7 +1147,6 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
copyToCellRamAndRelease(dstAddress, rtt0, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); copyToCellRamAndRelease(dstAddress, rtt0, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h);
} }
break; break;
case CELL_GCM_SURFACE_TARGET_1: case CELL_GCM_SURFACE_TARGET_1:
{ {
u32 address = GetAddress(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000); u32 address = GetAddress(m_surface_offset_b, m_context_dma_color_b - 0xfeed0000);
@ -1167,7 +1154,6 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h);
} }
break; break;
case CELL_GCM_SURFACE_TARGET_MRT1: case CELL_GCM_SURFACE_TARGET_MRT1:
{ {
u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000);
@ -1178,7 +1164,6 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); copyToCellRamAndRelease(dstAddress, rtt1, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h);
} }
break; break;
case CELL_GCM_SURFACE_TARGET_MRT2: case CELL_GCM_SURFACE_TARGET_MRT2:
{ {
u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000);
@ -1192,7 +1177,6 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
copyToCellRamAndRelease(dstAddress, rtt2, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h); copyToCellRamAndRelease(dstAddress, rtt2, srcPitch, dstPitch, m_surface_clip_w, m_surface_clip_h);
} }
break; break;
case CELL_GCM_SURFACE_TARGET_MRT3: case CELL_GCM_SURFACE_TARGET_MRT3:
{ {
u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000); u32 address = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000);
@ -1213,8 +1197,6 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
} }
vm::write32(m_label_addr + offset, value); vm::write32(m_label_addr + offset, value);
};
tmp();
} }
void D3D12GSRender::semaphorePFIFOAcquire(u32 offset, u32 value) void D3D12GSRender::semaphorePFIFOAcquire(u32 offset, u32 value)

View File

@ -222,7 +222,6 @@ writeTexelsSwizzled(const char *src, char *dst, size_t widthInBlock, size_t heig
log2width = (u32)(logf((float)currentWidth) / logf(2.f)); log2width = (u32)(logf((float)currentWidth) / logf(2.f));
log2height = (u32)(logf((float)currentHeight) / logf(2.f)); log2height = (u32)(logf((float)currentHeight) / logf(2.f));
#pragma omp parallel for
for (int row = 0; row < currentHeight; row++) for (int row = 0; row < currentHeight; row++)
for (int j = 0; j < currentWidth; j++) for (int j = 0; j < currentWidth; j++)
castedDst[(row * rowPitch / 4) + j] = castedSrc[LinearToSwizzleAddress(j, row, 0, log2width, log2height, 0)]; castedDst[(row * rowPitch / 4) + j] = castedSrc[LinearToSwizzleAddress(j, row, 0, log2width, log2height, 0)];
@ -298,7 +297,6 @@ write16bTexelsSwizzled(const char *src, char *dst, size_t widthInBlock, size_t h
log2width = (u32)(logf((float)currentWidth) / logf(2.f)); log2width = (u32)(logf((float)currentWidth) / logf(2.f));
log2height = (u32)(logf((float)currentHeight) / logf(2.f)); log2height = (u32)(logf((float)currentHeight) / logf(2.f));
#pragma omp parallel for
for (int row = 0; row < currentHeight; row++) for (int row = 0; row < currentHeight; row++)
for (int j = 0; j < currentWidth; j++) for (int j = 0; j < currentWidth; j++)
castedDst[(row * rowPitch / 2) + j] = castedSrc[LinearToSwizzleAddress(j, row, 0, log2width, log2height, 0)]; castedDst[(row * rowPitch / 2) + j] = castedSrc[LinearToSwizzleAddress(j, row, 0, log2width, log2height, 0)];