d3d12: Use a_b_c style for D3D12GSRender.h members

This commit is contained in:
Vincent Lejeune 2015-11-01 21:40:04 +01:00
parent 6e666b63fa
commit 570ca1c87f
7 changed files with 346 additions and 353 deletions

View File

@ -57,28 +57,28 @@ void D3D12GSRender::upload_vertex_attributes(const std::vector<std::pair<u32, u3
u32 element_size = type_size * info.size;
size_t buffer_size = element_size * vertex_count;
assert(m_vertexIndexData.can_alloc(buffer_size));
size_t heap_offset = m_vertexIndexData.alloc(buffer_size);
assert(m_vertex_index_data.can_alloc(buffer_size));
size_t heap_offset = m_vertex_index_data.alloc(buffer_size);
void *buffer;
ThrowIfFailed(m_vertexIndexData.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), (void**)&buffer));
ThrowIfFailed(m_vertex_index_data.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), (void**)&buffer));
void *mapped_buffer = (char*)buffer + heap_offset;
for (const auto &range : vertex_ranges)
{
write_vertex_array_data_to_buffer(mapped_buffer, range.first, range.second, index, info);
mapped_buffer = (char*)mapped_buffer + range.second * element_size;
}
m_vertexIndexData.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
m_vertex_index_data.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
D3D12_VERTEX_BUFFER_VIEW vertex_buffer_view =
{
m_vertexIndexData.m_heap->GetGPUVirtualAddress() + heap_offset,
m_vertex_index_data.m_heap->GetGPUVirtualAddress() + heap_offset,
(UINT)buffer_size,
(UINT)element_size
};
m_vertex_buffer_views.push_back(vertex_buffer_view);
m_timers.m_bufferUploadSize += buffer_size;
m_timers.m_buffer_upload_size += buffer_size;
D3D12_INPUT_ELEMENT_DESC IAElement = {};
IAElement.SemanticName = "TEXCOORD";
@ -107,17 +107,17 @@ void D3D12GSRender::upload_vertex_attributes(const std::vector<std::pair<u32, u3
u32 element_size = type_size * info.size;
size_t buffer_size = data.size();
assert(m_vertexIndexData.can_alloc(buffer_size));
size_t heap_offset = m_vertexIndexData.alloc(buffer_size);
assert(m_vertex_index_data.can_alloc(buffer_size));
size_t heap_offset = m_vertex_index_data.alloc(buffer_size);
void *buffer;
ThrowIfFailed(m_vertexIndexData.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), (void**)&buffer));
ThrowIfFailed(m_vertex_index_data.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), (void**)&buffer));
void *mapped_buffer = (char*)buffer + heap_offset;
memcpy(mapped_buffer, data.data(), data.size());
m_vertexIndexData.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
m_vertex_index_data.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
D3D12_VERTEX_BUFFER_VIEW vertex_buffer_view = {
m_vertexIndexData.m_heap->GetGPUVirtualAddress() + heap_offset,
m_vertex_index_data.m_heap->GetGPUVirtualAddress() + heap_offset,
(UINT)buffer_size,
(UINT)element_size
};
@ -137,88 +137,88 @@ void D3D12GSRender::upload_vertex_attributes(const std::vector<std::pair<u32, u3
void D3D12GSRender::load_vertex_index_data(u32 first, u32 count)
{
m_renderingInfo.m_indexed = true;
m_rendering_info.m_indexed = true;
}
void D3D12GSRender::upload_and_bind_scale_offset_matrix(size_t descriptorIndex)
{
assert(m_constantsData.can_alloc(256));
size_t heap_offset = m_constantsData.alloc(256);
assert(m_constants_data.can_alloc(256));
size_t heap_offset = m_constants_data.alloc(256);
// Scale offset buffer
// Separate constant buffer
void *mapped_buffer;
ThrowIfFailed(m_constantsData.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + 256), &mapped_buffer));
ThrowIfFailed(m_constants_data.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + 256), &mapped_buffer));
fill_scale_offset_data((char*)mapped_buffer + heap_offset);
int is_alpha_tested = !!(rsx::method_registers[NV4097_SET_ALPHA_TEST_ENABLE]);
float alpha_ref = (float&)rsx::method_registers[NV4097_SET_ALPHA_REF];
memcpy((char*)mapped_buffer + heap_offset + 16 * sizeof(float), &is_alpha_tested, sizeof(int));
memcpy((char*)mapped_buffer + heap_offset + 17 * sizeof(float), &alpha_ref, sizeof(float));
m_constantsData.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + 256));
m_constants_data.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + 256));
D3D12_CONSTANT_BUFFER_VIEW_DESC constant_buffer_view_desc = {
m_constantsData.m_heap->GetGPUVirtualAddress() + heap_offset,
m_constants_data.m_heap->GetGPUVirtualAddress() + heap_offset,
256
};
m_device->CreateConstantBufferView(&constant_buffer_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptorIndex, g_descriptorStrideSRVCBVUAV));
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptorIndex, g_descriptor_stride_srv_cbv_uav));
}
void D3D12GSRender::upload_and_bind_vertex_shader_constants(size_t descriptor_index)
{
size_t buffer_size = 512 * 4 * sizeof(float);
assert(m_constantsData.can_alloc(buffer_size));
size_t heap_offset = m_constantsData.alloc(buffer_size);
assert(m_constants_data.can_alloc(buffer_size));
size_t heap_offset = m_constants_data.alloc(buffer_size);
void *mapped_buffer;
ThrowIfFailed(m_constantsData.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), &mapped_buffer));
ThrowIfFailed(m_constants_data.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), &mapped_buffer));
fill_vertex_program_constants_data((char*)mapped_buffer + heap_offset);
m_constantsData.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
m_constants_data.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
D3D12_CONSTANT_BUFFER_VIEW_DESC constant_buffer_view_desc = {
m_constantsData.m_heap->GetGPUVirtualAddress() + heap_offset,
m_constants_data.m_heap->GetGPUVirtualAddress() + heap_offset,
(UINT)buffer_size
};
m_device->CreateConstantBufferView(&constant_buffer_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptor_index, g_descriptorStrideSRVCBVUAV));
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptor_index, g_descriptor_stride_srv_cbv_uav));
}
void D3D12GSRender::upload_and_bind_fragment_shader_constants(size_t descriptor_index)
{
// Get constant from fragment program
size_t buffer_size = m_cachePSO.get_fragment_constants_buffer_size(&fragment_program);
size_t buffer_size = m_pso_cache.get_fragment_constants_buffer_size(&fragment_program);
// Multiple of 256 never 0
buffer_size = (buffer_size + 255) & ~255;
assert(m_constantsData.can_alloc(buffer_size));
size_t heap_offset = m_constantsData.alloc(buffer_size);
assert(m_constants_data.can_alloc(buffer_size));
size_t heap_offset = m_constants_data.alloc(buffer_size);
size_t offset = 0;
void *mapped_buffer;
ThrowIfFailed(m_constantsData.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), &mapped_buffer));
m_cachePSO.fill_fragment_constans_buffer((char*)mapped_buffer + heap_offset, &fragment_program);
m_constantsData.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
ThrowIfFailed(m_constants_data.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), &mapped_buffer));
m_pso_cache.fill_fragment_constans_buffer((char*)mapped_buffer + heap_offset, &fragment_program);
m_constants_data.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
D3D12_CONSTANT_BUFFER_VIEW_DESC constant_buffer_view_desc = {
m_constantsData.m_heap->GetGPUVirtualAddress() + heap_offset,
m_constants_data.m_heap->GetGPUVirtualAddress() + heap_offset,
(UINT)buffer_size
};
m_device->CreateConstantBufferView(&constant_buffer_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptor_index, g_descriptorStrideSRVCBVUAV));
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptor_index, g_descriptor_stride_srv_cbv_uav));
}
void D3D12GSRender::upload_and_set_vertex_index_data(ID3D12GraphicsCommandList *command_list)
{
// Index count
m_renderingInfo.m_count = 0;
m_rendering_info.m_count = 0;
for (const auto &pair : m_first_count_pairs)
m_renderingInfo.m_count += get_index_count(draw_mode, pair.second);
m_rendering_info.m_count += get_index_count(draw_mode, pair.second);
if (!m_renderingInfo.m_indexed)
if (!m_rendering_info.m_indexed)
{
// Non indexed
upload_vertex_attributes(m_first_count_pairs);
@ -228,12 +228,12 @@ void D3D12GSRender::upload_and_set_vertex_index_data(ID3D12GraphicsCommandList *
// Handle non native primitive
// Alloc
size_t buffer_size = align(m_renderingInfo.m_count * sizeof(u16), 64);
assert(m_vertexIndexData.can_alloc(buffer_size));
size_t heap_offset = m_vertexIndexData.alloc(buffer_size);
size_t buffer_size = align(m_rendering_info.m_count * sizeof(u16), 64);
assert(m_vertex_index_data.can_alloc(buffer_size));
size_t heap_offset = m_vertex_index_data.alloc(buffer_size);
void *buffer;
ThrowIfFailed(m_vertexIndexData.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), (void**)&buffer));
ThrowIfFailed(m_vertex_index_data.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), (void**)&buffer));
void *mapped_buffer = (char*)buffer + heap_offset;
size_t first = 0;
for (const auto &pair : m_first_count_pairs)
@ -243,14 +243,14 @@ void D3D12GSRender::upload_and_set_vertex_index_data(ID3D12GraphicsCommandList *
mapped_buffer = (char*)mapped_buffer + element_count * sizeof(u16);
first += pair.second;
}
m_vertexIndexData.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
m_vertex_index_data.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
D3D12_INDEX_BUFFER_VIEW index_buffer_view = {
m_vertexIndexData.m_heap->GetGPUVirtualAddress() + heap_offset,
m_vertex_index_data.m_heap->GetGPUVirtualAddress() + heap_offset,
(UINT)buffer_size,
DXGI_FORMAT_R16_UINT
};
command_list->IASetIndexBuffer(&index_buffer_view);
m_renderingInfo.m_indexed = true;
m_rendering_info.m_indexed = true;
}
else
{
@ -260,12 +260,12 @@ void D3D12GSRender::upload_and_set_vertex_index_data(ID3D12GraphicsCommandList *
size_t index_size = get_index_type_size(indexed_type);
// Alloc
size_t buffer_size = align(m_renderingInfo.m_count * index_size, 64);
assert(m_vertexIndexData.can_alloc(buffer_size));
size_t heap_offset = m_vertexIndexData.alloc(buffer_size);
size_t buffer_size = align(m_rendering_info.m_count * index_size, 64);
assert(m_vertex_index_data.can_alloc(buffer_size));
size_t heap_offset = m_vertex_index_data.alloc(buffer_size);
void *buffer;
ThrowIfFailed(m_vertexIndexData.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), (void**)&buffer));
ThrowIfFailed(m_vertex_index_data.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size), (void**)&buffer));
void *mapped_buffer = (char*)buffer + heap_offset;
u32 min_index = (u32)-1, max_index = 0;
for (const auto &pair : m_first_count_pairs)
@ -274,15 +274,15 @@ void D3D12GSRender::upload_and_set_vertex_index_data(ID3D12GraphicsCommandList *
write_index_array_data_to_buffer((char*)mapped_buffer, draw_mode, pair.first, pair.second, min_index, max_index);
mapped_buffer = (char*)mapped_buffer + element_count * index_size;
}
m_vertexIndexData.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
m_vertex_index_data.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
D3D12_INDEX_BUFFER_VIEW index_buffer_view = {
m_vertexIndexData.m_heap->GetGPUVirtualAddress() + heap_offset,
m_vertex_index_data.m_heap->GetGPUVirtualAddress() + heap_offset,
(UINT)buffer_size,
get_index_type(indexed_type)
};
m_timers.m_bufferUploadSize += buffer_size;
m_timers.m_buffer_upload_size += buffer_size;
command_list->IASetIndexBuffer(&index_buffer_view);
m_renderingInfo.m_indexed = true;
m_rendering_info.m_indexed = true;
upload_vertex_attributes({ std::make_pair(0, max_index + 1) });
command_list->IASetVertexBuffers(0, (UINT)m_vertex_buffer_views.size(), m_vertex_buffer_views.data());

View File

@ -66,10 +66,10 @@ void D3D12GSRender::Shader::Release()
extern std::function<bool(u32 addr)> gfxHandler;
bool D3D12GSRender::invalidateAddress(u32 addr)
bool D3D12GSRender::invalidate_address(u32 addr)
{
bool result = false;
result |= m_textureCache.invalidate_address(addr);
result |= m_texture_cache.invalidate_address(addr);
return result;
}
@ -84,7 +84,7 @@ D3D12DLLManagement::~D3D12DLLManagement()
}
D3D12GSRender::D3D12GSRender()
: GSRender(frame_type::DX12), m_D3D12Lib(), m_PSO(nullptr)
: GSRender(frame_type::DX12), m_d3d12_lib(), m_current_pso(nullptr)
{
m_previous_address_a = 0;
m_previous_address_b = 0;
@ -92,7 +92,7 @@ D3D12GSRender::D3D12GSRender()
m_previous_address_d = 0;
m_previous_address_z = 0;
gfxHandler = [this](u32 addr) {
bool result = invalidateAddress(addr);
bool result = invalidate_address(addr);
if (result)
LOG_WARNING(RSX, "Reporting Cell writing to %x", addr);
return result;
@ -113,12 +113,12 @@ D3D12GSRender::D3D12GSRender()
// Queues
D3D12_COMMAND_QUEUE_DESC graphic_queue_desc = { D3D12_COMMAND_LIST_TYPE_DIRECT };
ThrowIfFailed(m_device->CreateCommandQueue(&graphic_queue_desc, IID_PPV_ARGS(m_commandQueueGraphic.GetAddressOf())));
ThrowIfFailed(m_device->CreateCommandQueue(&graphic_queue_desc, IID_PPV_ARGS(m_command_queue.GetAddressOf())));
g_descriptorStrideSRVCBVUAV = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
g_descriptorStrideDSV = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
g_descriptorStrideRTV = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
g_descriptorStrideSamplers = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
g_descriptor_stride_srv_cbv_uav = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
g_descriptor_stride_dsv = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
g_descriptor_stride_rtv = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
g_descriptor_stride_samplers = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
// Create swap chain and put them in a descriptor heap as rendertarget
DXGI_SWAP_CHAIN_DESC swap_chain = {};
@ -131,18 +131,18 @@ D3D12GSRender::D3D12GSRender()
swap_chain.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
swap_chain.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
ThrowIfFailed(dxgi_factory->CreateSwapChain(m_commandQueueGraphic.Get(), &swap_chain, (IDXGISwapChain**)m_swapChain.GetAddressOf()));
m_swapChain->GetBuffer(0, IID_PPV_ARGS(&m_backBuffer[0]));
m_swapChain->GetBuffer(1, IID_PPV_ARGS(&m_backBuffer[1]));
ThrowIfFailed(dxgi_factory->CreateSwapChain(m_command_queue.Get(), &swap_chain, (IDXGISwapChain**)m_swap_chain.GetAddressOf()));
m_swap_chain->GetBuffer(0, IID_PPV_ARGS(&m_backbuffer[0]));
m_swap_chain->GetBuffer(1, IID_PPV_ARGS(&m_backbuffer[1]));
D3D12_DESCRIPTOR_HEAP_DESC render_target_descriptor_heap_desc = { D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1};
D3D12_RENDER_TARGET_VIEW_DESC renter_target_view_desc = {};
renter_target_view_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
renter_target_view_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
m_device->CreateDescriptorHeap(&render_target_descriptor_heap_desc, IID_PPV_ARGS(&m_backbufferAsRendertarget[0]));
m_device->CreateRenderTargetView(m_backBuffer[0].Get(), &renter_target_view_desc, m_backbufferAsRendertarget[0]->GetCPUDescriptorHandleForHeapStart());
m_device->CreateDescriptorHeap(&render_target_descriptor_heap_desc, IID_PPV_ARGS(&m_backbufferAsRendertarget[1]));
m_device->CreateRenderTargetView(m_backBuffer[1].Get(), &renter_target_view_desc, m_backbufferAsRendertarget[1]->GetCPUDescriptorHandleForHeapStart());
m_device->CreateDescriptorHeap(&render_target_descriptor_heap_desc, IID_PPV_ARGS(&m_backbuffer_descriptor_heap[0]));
m_device->CreateRenderTargetView(m_backbuffer[0].Get(), &renter_target_view_desc, m_backbuffer_descriptor_heap[0]->GetCPUDescriptorHandleForHeapStart());
m_device->CreateDescriptorHeap(&render_target_descriptor_heap_desc, IID_PPV_ARGS(&m_backbuffer_descriptor_heap[1]));
m_device->CreateRenderTargetView(m_backbuffer[1].Get(), &renter_target_view_desc, m_backbuffer_descriptor_heap[1]->GetCPUDescriptorHandleForHeapStart());
// Common root signatures
for (unsigned texture_count = 0; texture_count < 17; texture_count++)
@ -171,16 +171,16 @@ D3D12GSRender::D3D12GSRender()
m_device->CreateRootSignature(0,
rootSignatureBlob->GetBufferPointer(),
rootSignatureBlob->GetBufferSize(),
IID_PPV_ARGS(m_rootSignatures[texture_count].GetAddressOf()));
IID_PPV_ARGS(m_root_signatures[texture_count].GetAddressOf()));
}
m_perFrameStorage[0].init(m_device.Get());
m_perFrameStorage[0].reset();
m_perFrameStorage[1].init(m_device.Get());
m_perFrameStorage[1].reset();
m_per_frame_storage[0].init(m_device.Get());
m_per_frame_storage[0].reset();
m_per_frame_storage[1].init(m_device.Get());
m_per_frame_storage[1].reset();
initConvertShader();
m_outputScalingPass.Init(m_device.Get(), m_commandQueueGraphic.Get());
m_output_scaling_pass.Init(m_device.Get(), m_command_queue.Get());
ThrowIfFailed(
m_device->CreateCommittedResource(
@ -189,17 +189,17 @@ D3D12GSRender::D3D12GSRender()
&CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, 2, 2, 1, 1),
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&m_dummyTexture))
IID_PPV_ARGS(&m_dummy_texture))
);
m_readbackResources.init(m_device.Get(), 1024 * 1024 * 128, D3D12_HEAP_TYPE_READBACK, D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS);
m_UAVHeap.init(m_device.Get(), 1024 * 1024 * 128, D3D12_HEAP_TYPE_DEFAULT, D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES);
m_readback_resources.init(m_device.Get(), 1024 * 1024 * 128, D3D12_HEAP_TYPE_READBACK, D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS);
m_uav_heap.init(m_device.Get(), 1024 * 1024 * 128, D3D12_HEAP_TYPE_DEFAULT, D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES);
m_rtts.init(m_device.Get());
m_constantsData.init(m_device.Get(), 1024 * 1024 * 64, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE);
m_vertexIndexData.init(m_device.Get(), 1024 * 1024 * 384, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE);
m_textureUploadData.init(m_device.Get(), 1024 * 1024 * 512, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE);
m_constants_data.init(m_device.Get(), 1024 * 1024 * 64, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE);
m_vertex_index_data.init(m_device.Get(), 1024 * 1024 * 384, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE);
m_texture_upload_data.init(m_device.Get(), 1024 * 1024 * 512, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE);
if (rpcs3::config.rsx.d3d12.overlay.value())
init_d2d_structures();
@ -207,23 +207,22 @@ D3D12GSRender::D3D12GSRender()
D3D12GSRender::~D3D12GSRender()
{
wait_for_command_queue(m_device.Get(), m_commandQueueGraphic.Get());
wait_for_command_queue(m_device.Get(), m_command_queue.Get());
m_textureCache.unprotect_all();
m_texture_cache.unprotect_all();
gfxHandler = [this](u32) { return false; };
m_constantsData.release();
m_vertexIndexData.release();
m_textureUploadData.release();
m_UAVHeap.m_heap->Release();
m_readbackResources.m_heap->Release();
m_texturesRTTs.clear();
m_dummyTexture->Release();
m_constants_data.release();
m_vertex_index_data.release();
m_texture_upload_data.release();
m_uav_heap.m_heap->Release();
m_readback_resources.m_heap->Release();
m_dummy_texture->Release();
m_convertPSO->Release();
m_convertRootSignature->Release();
m_perFrameStorage[0].release();
m_perFrameStorage[1].release();
m_outputScalingPass.Release();
m_per_frame_storage[0].release();
m_per_frame_storage[1].release();
m_output_scaling_pass.Release();
release_d2d_structures();
}
@ -256,18 +255,18 @@ void D3D12GSRender::end()
std::chrono::time_point<std::chrono::system_clock> start_duration = std::chrono::system_clock::now();
std::chrono::time_point<std::chrono::system_clock> rtt_duration_start = std::chrono::system_clock::now();
prepare_render_targets(getCurrentResourceStorage().command_list.Get());
prepare_render_targets(get_current_resource_storage().command_list.Get());
std::chrono::time_point<std::chrono::system_clock> rtt_duration_end = std::chrono::system_clock::now();
m_timers.m_rttDuration += std::chrono::duration_cast<std::chrono::microseconds>(rtt_duration_end - rtt_duration_start).count();
m_timers.m_prepare_rtt_duration += std::chrono::duration_cast<std::chrono::microseconds>(rtt_duration_end - rtt_duration_start).count();
std::chrono::time_point<std::chrono::system_clock> vertex_index_duration_start = std::chrono::system_clock::now();
if (!vertex_index_array.empty() || vertex_draw_count)
upload_and_set_vertex_index_data(getCurrentResourceStorage().command_list.Get());
upload_and_set_vertex_index_data(get_current_resource_storage().command_list.Get());
std::chrono::time_point<std::chrono::system_clock> vertex_index_duration_end = std::chrono::system_clock::now();
m_timers.m_vertexIndexDuration += std::chrono::duration_cast<std::chrono::microseconds>(vertex_index_duration_end - vertex_index_duration_start).count();
m_timers.m_vertex_index_duration += std::chrono::duration_cast<std::chrono::microseconds>(vertex_index_duration_end - vertex_index_duration_start).count();
std::chrono::time_point<std::chrono::system_clock> program_load_start = std::chrono::system_clock::now();
if (!load_program())
@ -277,61 +276,61 @@ void D3D12GSRender::end()
return;
}
std::chrono::time_point<std::chrono::system_clock> program_load_end = std::chrono::system_clock::now();
m_timers.m_programLoadDuration += std::chrono::duration_cast<std::chrono::microseconds>(program_load_end - program_load_start).count();
m_timers.m_program_load_duration += std::chrono::duration_cast<std::chrono::microseconds>(program_load_end - program_load_start).count();
getCurrentResourceStorage().command_list->SetGraphicsRootSignature(m_rootSignatures[std::get<2>(*m_PSO)].Get());
getCurrentResourceStorage().command_list->OMSetStencilRef(rsx::method_registers[NV4097_SET_STENCIL_FUNC_REF]);
get_current_resource_storage().command_list->SetGraphicsRootSignature(m_root_signatures[std::get<2>(*m_current_pso)].Get());
get_current_resource_storage().command_list->OMSetStencilRef(rsx::method_registers[NV4097_SET_STENCIL_FUNC_REF]);
std::chrono::time_point<std::chrono::system_clock> constants_duration_start = std::chrono::system_clock::now();
size_t currentDescriptorIndex = getCurrentResourceStorage().descriptors_heap_index;
size_t currentDescriptorIndex = get_current_resource_storage().descriptors_heap_index;
// Constants
upload_and_bind_scale_offset_matrix(currentDescriptorIndex);
upload_and_bind_vertex_shader_constants(currentDescriptorIndex + 1);
upload_and_bind_fragment_shader_constants(currentDescriptorIndex + 2);
std::chrono::time_point<std::chrono::system_clock> constants_duration_end = std::chrono::system_clock::now();
m_timers.m_constantsDuration += std::chrono::duration_cast<std::chrono::microseconds>(constants_duration_end - constants_duration_start).count();
m_timers.m_constants_duration += std::chrono::duration_cast<std::chrono::microseconds>(constants_duration_end - constants_duration_start).count();
getCurrentResourceStorage().command_list->SetPipelineState(std::get<0>(*m_PSO));
get_current_resource_storage().command_list->SetPipelineState(std::get<0>(*m_current_pso));
std::chrono::time_point<std::chrono::system_clock> texture_duration_start = std::chrono::system_clock::now();
if (std::get<2>(*m_PSO) > 0)
if (std::get<2>(*m_current_pso) > 0)
{
upload_and_bind_textures(getCurrentResourceStorage().command_list.Get(), currentDescriptorIndex + 3, std::get<2>(*m_PSO) > 0);
upload_and_bind_textures(get_current_resource_storage().command_list.Get(), currentDescriptorIndex + 3, std::get<2>(*m_current_pso) > 0);
ID3D12DescriptorHeap *descriptors[] =
{
getCurrentResourceStorage().descriptors_heap.Get(),
getCurrentResourceStorage().sampler_descriptor_heap[getCurrentResourceStorage().sampler_descriptors_heap_index].Get(),
get_current_resource_storage().descriptors_heap.Get(),
get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index].Get(),
};
getCurrentResourceStorage().command_list->SetDescriptorHeaps(2, descriptors);
get_current_resource_storage().command_list->SetDescriptorHeaps(2, descriptors);
getCurrentResourceStorage().command_list->SetGraphicsRootDescriptorTable(0,
CD3DX12_GPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().descriptors_heap->GetGPUDescriptorHandleForHeapStart())
.Offset((INT)currentDescriptorIndex, g_descriptorStrideSRVCBVUAV)
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(0,
CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetGPUDescriptorHandleForHeapStart())
.Offset((INT)currentDescriptorIndex, g_descriptor_stride_srv_cbv_uav)
);
getCurrentResourceStorage().command_list->SetGraphicsRootDescriptorTable(1,
CD3DX12_GPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().sampler_descriptor_heap[getCurrentResourceStorage().sampler_descriptors_heap_index]->GetGPUDescriptorHandleForHeapStart())
.Offset((INT)getCurrentResourceStorage().current_sampler_index, g_descriptorStrideSamplers)
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(1,
CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index]->GetGPUDescriptorHandleForHeapStart())
.Offset((INT)get_current_resource_storage().current_sampler_index, g_descriptor_stride_samplers)
);
getCurrentResourceStorage().current_sampler_index += std::get<2>(*m_PSO);
getCurrentResourceStorage().descriptors_heap_index += std::get<2>(*m_PSO) + 3;
get_current_resource_storage().current_sampler_index += std::get<2>(*m_current_pso);
get_current_resource_storage().descriptors_heap_index += std::get<2>(*m_current_pso) + 3;
}
else
{
getCurrentResourceStorage().command_list->SetDescriptorHeaps(1, getCurrentResourceStorage().descriptors_heap.GetAddressOf());
getCurrentResourceStorage().command_list->SetGraphicsRootDescriptorTable(0,
CD3DX12_GPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().descriptors_heap->GetGPUDescriptorHandleForHeapStart())
.Offset((INT)currentDescriptorIndex, g_descriptorStrideSRVCBVUAV)
get_current_resource_storage().command_list->SetDescriptorHeaps(1, get_current_resource_storage().descriptors_heap.GetAddressOf());
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(0,
CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetGPUDescriptorHandleForHeapStart())
.Offset((INT)currentDescriptorIndex, g_descriptor_stride_srv_cbv_uav)
);
getCurrentResourceStorage().descriptors_heap_index += 3;
get_current_resource_storage().descriptors_heap_index += 3;
}
std::chrono::time_point<std::chrono::system_clock> texture_duration_end = std::chrono::system_clock::now();
m_timers.m_textureDuration += std::chrono::duration_cast<std::chrono::microseconds>(texture_duration_end - texture_duration_start).count();
set_rtt_and_ds(getCurrentResourceStorage().command_list.Get());
m_timers.m_texture_duration += std::chrono::duration_cast<std::chrono::microseconds>(texture_duration_end - texture_duration_start).count();
set_rtt_and_ds(get_current_resource_storage().command_list.Get());
int clip_w = rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16;
int clip_h = rsx::method_registers[NV4097_SET_SURFACE_CLIP_VERTICAL] >> 16;
@ -345,30 +344,30 @@ void D3D12GSRender::end()
(f32&)rsx::method_registers[NV4097_SET_CLIP_MIN],
(f32&)rsx::method_registers[NV4097_SET_CLIP_MAX]
};
getCurrentResourceStorage().command_list->RSSetViewports(1, &viewport);
get_current_resource_storage().command_list->RSSetViewports(1, &viewport);
getCurrentResourceStorage().command_list->RSSetScissorRects(1, &get_scissor(rsx::method_registers[NV4097_SET_SCISSOR_HORIZONTAL], rsx::method_registers[NV4097_SET_SCISSOR_VERTICAL]));
get_current_resource_storage().command_list->RSSetScissorRects(1, &get_scissor(rsx::method_registers[NV4097_SET_SCISSOR_HORIZONTAL], rsx::method_registers[NV4097_SET_SCISSOR_VERTICAL]));
getCurrentResourceStorage().command_list->IASetPrimitiveTopology(get_primitive_topology(draw_mode));
get_current_resource_storage().command_list->IASetPrimitiveTopology(get_primitive_topology(draw_mode));
if (m_renderingInfo.m_indexed)
getCurrentResourceStorage().command_list->DrawIndexedInstanced((UINT)m_renderingInfo.m_count, 1, 0, 0, 0);
if (m_rendering_info.m_indexed)
get_current_resource_storage().command_list->DrawIndexedInstanced((UINT)m_rendering_info.m_count, 1, 0, 0, 0);
else
getCurrentResourceStorage().command_list->DrawInstanced((UINT)m_renderingInfo.m_count, 1, 0, 0);
get_current_resource_storage().command_list->DrawInstanced((UINT)m_rendering_info.m_count, 1, 0, 0);
vertex_index_array.clear();
std::chrono::time_point<std::chrono::system_clock> end_duration = std::chrono::system_clock::now();
m_timers.m_drawCallDuration += std::chrono::duration_cast<std::chrono::microseconds>(end_duration - start_duration).count();
m_timers.m_drawCallCount++;
m_timers.m_draw_calls_duration += std::chrono::duration_cast<std::chrono::microseconds>(end_duration - start_duration).count();
m_timers.m_draw_calls_count++;
if (rpcs3::config.rsx.d3d12.debug_output.value())
{
ThrowIfFailed(getCurrentResourceStorage().command_list->Close());
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().command_list.GetAddressOf());
getCurrentResourceStorage().set_new_command_list();
ThrowIfFailed(get_current_resource_storage().command_list->Close());
m_command_queue->ExecuteCommandLists(1, (ID3D12CommandList**)get_current_resource_storage().command_list.GetAddressOf());
get_current_resource_storage().set_new_command_list();
}
m_first_count_pairs.clear();
m_renderingInfo.m_indexed = false;
m_rendering_info.m_indexed = false;
thread::end();
}
@ -398,7 +397,7 @@ void D3D12GSRender::flip(int buffer)
if (!is_flip_surface_in_global_memory(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]))
{
resource_storage &storage = getCurrentResourceStorage();
resource_storage &storage = get_current_resource_storage();
assert(storage.ram_framebuffer == nullptr);
size_t w = 0, h = 0, row_pitch = 0;
@ -414,15 +413,15 @@ void D3D12GSRender::flip(int buffer)
row_pitch = align(w * 4, 256);
size_t texture_size = row_pitch * h; // * 4 for mipmap levels
assert(m_textureUploadData.can_alloc(texture_size));
size_t heap_offset = m_textureUploadData.alloc(texture_size);
assert(m_texture_upload_data.can_alloc(texture_size));
size_t heap_offset = m_texture_upload_data.alloc(texture_size);
void *buffer;
ThrowIfFailed(m_textureUploadData.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + texture_size), &buffer));
ThrowIfFailed(m_texture_upload_data.m_heap->Map(0, &CD3DX12_RANGE(heap_offset, heap_offset + texture_size), &buffer));
void *mapped_buffer = (char*)buffer + heap_offset;
for (unsigned row = 0; row < h; row++)
memcpy((char*)mapped_buffer + row * row_pitch, (char*)src_buffer + row * w * 4, w * 4);
m_textureUploadData.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + texture_size));
m_texture_upload_data.m_heap->Unmap(0, &CD3DX12_RANGE(heap_offset, heap_offset + texture_size));
offset = heap_offset;
}
@ -436,10 +435,10 @@ void D3D12GSRender::flip(int buffer)
IID_PPV_ARGS(storage.ram_framebuffer.GetAddressOf())
)
);
getCurrentResourceStorage().command_list->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(storage.ram_framebuffer.Get(), 0), 0, 0, 0,
&CD3DX12_TEXTURE_COPY_LOCATION(m_textureUploadData.m_heap, { offset, { DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)w, (UINT)h, 1, (UINT)row_pitch } }), nullptr);
get_current_resource_storage().command_list->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(storage.ram_framebuffer.Get(), 0), 0, 0, 0,
&CD3DX12_TEXTURE_COPY_LOCATION(m_texture_upload_data.m_heap, { offset, { DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)w, (UINT)h, 1, (UINT)row_pitch } }), nullptr);
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(storage.ram_framebuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ));
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(storage.ram_framebuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ));
resource_to_flip = storage.ram_framebuffer.Get();
viewport_w = (float)w, viewport_h = (float)h;
}
@ -447,41 +446,41 @@ void D3D12GSRender::flip(int buffer)
{
if (m_rtts.bound_render_targets[0] != nullptr)
{
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_render_targets[0], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_GENERIC_READ));
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_render_targets[0], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_GENERIC_READ));
resource_to_flip = m_rtts.bound_render_targets[0];
}
else if (m_rtts.bound_render_targets[1] != nullptr)
{
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_render_targets[1], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_GENERIC_READ));
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_render_targets[1], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_GENERIC_READ));
resource_to_flip = m_rtts.bound_render_targets[1];
}
else
resource_to_flip = nullptr;
}
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_backbuffer[m_swap_chain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));
D3D12_VIEWPORT viewport =
{
0.f,
0.f,
(float)m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()]->GetDesc().Width,
(float)m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()]->GetDesc().Height,
(float)m_backbuffer[m_swap_chain->GetCurrentBackBufferIndex()]->GetDesc().Width,
(float)m_backbuffer[m_swap_chain->GetCurrentBackBufferIndex()]->GetDesc().Height,
0.f,
1.f
};
getCurrentResourceStorage().command_list->RSSetViewports(1, &viewport);
get_current_resource_storage().command_list->RSSetViewports(1, &viewport);
D3D12_RECT box =
{
0,
0,
(LONG)m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()]->GetDesc().Width,
(LONG)m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()]->GetDesc().Height,
(LONG)m_backbuffer[m_swap_chain->GetCurrentBackBufferIndex()]->GetDesc().Width,
(LONG)m_backbuffer[m_swap_chain->GetCurrentBackBufferIndex()]->GetDesc().Height,
};
getCurrentResourceStorage().command_list->RSSetScissorRects(1, &box);
getCurrentResourceStorage().command_list->SetGraphicsRootSignature(m_outputScalingPass.m_rootSignature);
getCurrentResourceStorage().command_list->SetPipelineState(m_outputScalingPass.m_PSO);
get_current_resource_storage().command_list->RSSetScissorRects(1, &box);
get_current_resource_storage().command_list->SetGraphicsRootSignature(m_output_scaling_pass.m_rootSignature);
get_current_resource_storage().command_list->SetPipelineState(m_output_scaling_pass.m_PSO);
D3D12_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {};
// FIXME: Not always true
@ -498,7 +497,7 @@ void D3D12GSRender::flip(int buffer)
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_0
);
m_device->CreateShaderResourceView(resource_to_flip, &shader_resource_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_outputScalingPass.m_textureDescriptorHeap->GetCPUDescriptorHandleForHeapStart()).Offset(m_swapChain->GetCurrentBackBufferIndex(), g_descriptorStrideSRVCBVUAV));
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.m_textureDescriptorHeap->GetCPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), g_descriptor_stride_srv_cbv_uav));
D3D12_SAMPLER_DESC sampler_desc = {};
sampler_desc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT;
@ -506,37 +505,37 @@ void D3D12GSRender::flip(int buffer)
sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
m_device->CreateSampler(&sampler_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_outputScalingPass.m_samplerDescriptorHeap->GetCPUDescriptorHandleForHeapStart()).Offset(m_swapChain->GetCurrentBackBufferIndex(), g_descriptorStrideSamplers));
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.m_samplerDescriptorHeap->GetCPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), g_descriptor_stride_samplers));
ID3D12DescriptorHeap *descriptors_heaps[] =
{
m_outputScalingPass.m_textureDescriptorHeap,
m_outputScalingPass.m_samplerDescriptorHeap
m_output_scaling_pass.m_textureDescriptorHeap,
m_output_scaling_pass.m_samplerDescriptorHeap
};
getCurrentResourceStorage().command_list->SetDescriptorHeaps(2, descriptors_heaps);
getCurrentResourceStorage().command_list->SetGraphicsRootDescriptorTable(0,
CD3DX12_GPU_DESCRIPTOR_HANDLE(m_outputScalingPass.m_textureDescriptorHeap->GetGPUDescriptorHandleForHeapStart()).Offset(m_swapChain->GetCurrentBackBufferIndex(), g_descriptorStrideSRVCBVUAV));
getCurrentResourceStorage().command_list->SetGraphicsRootDescriptorTable(1,
CD3DX12_GPU_DESCRIPTOR_HANDLE(m_outputScalingPass.m_samplerDescriptorHeap->GetGPUDescriptorHandleForHeapStart()).Offset(m_swapChain->GetCurrentBackBufferIndex(), g_descriptorStrideSamplers));
get_current_resource_storage().command_list->SetDescriptorHeaps(2, descriptors_heaps);
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(0,
CD3DX12_GPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.m_textureDescriptorHeap->GetGPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), g_descriptor_stride_srv_cbv_uav));
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(1,
CD3DX12_GPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.m_samplerDescriptorHeap->GetGPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), g_descriptor_stride_samplers));
getCurrentResourceStorage().command_list->OMSetRenderTargets(1,
&CD3DX12_CPU_DESCRIPTOR_HANDLE(m_backbufferAsRendertarget[m_swapChain->GetCurrentBackBufferIndex()]->GetCPUDescriptorHandleForHeapStart()),
get_current_resource_storage().command_list->OMSetRenderTargets(1,
&CD3DX12_CPU_DESCRIPTOR_HANDLE(m_backbuffer_descriptor_heap[m_swap_chain->GetCurrentBackBufferIndex()]->GetCPUDescriptorHandleForHeapStart()),
true, nullptr);
D3D12_VERTEX_BUFFER_VIEW vertex_buffer_view = {};
vertex_buffer_view.BufferLocation = m_outputScalingPass.m_vertexBuffer->GetGPUVirtualAddress();
vertex_buffer_view.BufferLocation = m_output_scaling_pass.m_vertexBuffer->GetGPUVirtualAddress();
vertex_buffer_view.StrideInBytes = 4 * sizeof(float);
vertex_buffer_view.SizeInBytes = 16 * sizeof(float);
getCurrentResourceStorage().command_list->IASetVertexBuffers(0, 1, &vertex_buffer_view);
getCurrentResourceStorage().command_list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
get_current_resource_storage().command_list->IASetVertexBuffers(0, 1, &vertex_buffer_view);
get_current_resource_storage().command_list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
if (resource_to_flip)
getCurrentResourceStorage().command_list->DrawInstanced(4, 1, 0, 0);
get_current_resource_storage().command_list->DrawInstanced(4, 1, 0, 0);
if (!rpcs3::config.rsx.d3d12.overlay.value())
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_backbuffer[m_swap_chain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
if (is_flip_surface_in_global_memory(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]) && resource_to_flip != nullptr)
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(resource_to_flip, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET));
ThrowIfFailed(getCurrentResourceStorage().command_list->Close());
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().command_list.GetAddressOf());
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(resource_to_flip, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET));
ThrowIfFailed(get_current_resource_storage().command_list->Close());
m_command_queue->ExecuteCommandLists(1, (ID3D12CommandList**)get_current_resource_storage().command_list.GetAddressOf());
if(rpcs3::config.rsx.d3d12.overlay.value())
render_overlay();
@ -545,12 +544,12 @@ void D3D12GSRender::flip(int buffer)
std::chrono::time_point<std::chrono::system_clock> flip_start = std::chrono::system_clock::now();
ThrowIfFailed(m_swapChain->Present(rpcs3::state.config.rsx.vsync.value() ? 1 : 0, 0));
ThrowIfFailed(m_swap_chain->Present(rpcs3::state.config.rsx.vsync.value() ? 1 : 0, 0));
// Add an event signaling queue completion
resource_storage &storage = getNonCurrentResourceStorage();
resource_storage &storage = get_non_current_resource_storage();
m_commandQueueGraphic->Signal(storage.frame_finished_fence.Get(), storage.fence_value);
m_command_queue->Signal(storage.frame_finished_fence.Get(), storage.fence_value);
storage.frame_finished_fence->SetEventOnCompletion(storage.fence_value, storage.frame_finished_handle);
storage.fence_value++;
@ -559,55 +558,52 @@ void D3D12GSRender::flip(int buffer)
// Get the put pos - 1. This way after cleaning we can set the get ptr to
// this value, allowing heap to proceed even if we cleant before allocating
// a new value (that's the reason of the -1)
storage.constants_heap_get_pos = m_constantsData.get_current_put_pos_minus_one();
storage.vertex_index_heap_get_pos = m_vertexIndexData.get_current_put_pos_minus_one();
storage.texture_upload_heap_get_pos = m_textureUploadData.get_current_put_pos_minus_one();
storage.readback_heap_get_pos = m_readbackResources.get_current_put_pos_minus_one();
storage.uav_heap_get_pos = m_UAVHeap.get_current_put_pos_minus_one();
// Flush
m_texturesRTTs.clear();
storage.constants_heap_get_pos = m_constants_data.get_current_put_pos_minus_one();
storage.vertex_index_heap_get_pos = m_vertex_index_data.get_current_put_pos_minus_one();
storage.texture_upload_heap_get_pos = m_texture_upload_data.get_current_put_pos_minus_one();
storage.readback_heap_get_pos = m_readback_resources.get_current_put_pos_minus_one();
storage.uav_heap_get_pos = m_uav_heap.get_current_put_pos_minus_one();
// Now get ready for next frame
resource_storage &new_storage = getCurrentResourceStorage();
resource_storage &new_storage = get_current_resource_storage();
new_storage.wait_and_clean();
if (new_storage.in_use)
{
m_constantsData.m_get_pos = new_storage.constants_heap_get_pos;
m_vertexIndexData.m_get_pos = new_storage.vertex_index_heap_get_pos;
m_textureUploadData.m_get_pos = new_storage.texture_upload_heap_get_pos;
m_readbackResources.m_get_pos = new_storage.readback_heap_get_pos;
m_UAVHeap.m_get_pos = new_storage.uav_heap_get_pos;
m_constants_data.m_get_pos = new_storage.constants_heap_get_pos;
m_vertex_index_data.m_get_pos = new_storage.vertex_index_heap_get_pos;
m_texture_upload_data.m_get_pos = new_storage.texture_upload_heap_get_pos;
m_readback_resources.m_get_pos = new_storage.readback_heap_get_pos;
m_uav_heap.m_get_pos = new_storage.uav_heap_get_pos;
}
m_frame->flip(nullptr);
std::chrono::time_point<std::chrono::system_clock> flip_end = std::chrono::system_clock::now();
m_timers.m_flipDuration += std::chrono::duration_cast<std::chrono::microseconds>(flip_end - flip_start).count();
m_timers.m_flip_duration += std::chrono::duration_cast<std::chrono::microseconds>(flip_end - flip_start).count();
}
void D3D12GSRender::reset_timer()
{
m_timers.m_drawCallCount = 0;
m_timers.m_drawCallDuration = 0;
m_timers.m_rttDuration = 0;
m_timers.m_vertexIndexDuration = 0;
m_timers.m_bufferUploadSize = 0;
m_timers.m_programLoadDuration = 0;
m_timers.m_constantsDuration = 0;
m_timers.m_textureDuration = 0;
m_timers.m_flipDuration = 0;
m_timers.m_draw_calls_count = 0;
m_timers.m_draw_calls_duration = 0;
m_timers.m_prepare_rtt_duration = 0;
m_timers.m_vertex_index_duration = 0;
m_timers.m_buffer_upload_size = 0;
m_timers.m_program_load_duration = 0;
m_timers.m_constants_duration = 0;
m_timers.m_texture_duration = 0;
m_timers.m_flip_duration = 0;
}
resource_storage& D3D12GSRender::getCurrentResourceStorage()
resource_storage& D3D12GSRender::get_current_resource_storage()
{
return m_perFrameStorage[m_swapChain->GetCurrentBackBufferIndex()];
return m_per_frame_storage[m_swap_chain->GetCurrentBackBufferIndex()];
}
resource_storage& D3D12GSRender::getNonCurrentResourceStorage()
resource_storage& D3D12GSRender::get_non_current_resource_storage()
{
return m_perFrameStorage[1 - m_swapChain->GetCurrentBackBufferIndex()];
return m_per_frame_storage[1 - m_swap_chain->GetCurrentBackBufferIndex()];
}
#endif

View File

@ -51,39 +51,36 @@ private:
/** D3D12 structures.
* Note: they should be declared in reverse order of destruction
*/
D3D12DLLManagement m_D3D12Lib;
D3D12DLLManagement m_d3d12_lib;
ComPtr<ID3D12Device> m_device;
ComPtr<ID3D12CommandQueue> m_commandQueueGraphic;
ComPtr<struct IDXGISwapChain3> m_swapChain;
ComPtr<ID3D12Resource> m_backBuffer[2];
ComPtr<ID3D12DescriptorHeap> m_backbufferAsRendertarget[2];
ComPtr<ID3D12CommandQueue> m_command_queue;
ComPtr<struct IDXGISwapChain3> m_swap_chain;
ComPtr<ID3D12Resource> m_backbuffer[2];
ComPtr<ID3D12DescriptorHeap> m_backbuffer_descriptor_heap[2];
// m_rootSignatures[N] is RS with N texture/sample
ComPtr<ID3D12RootSignature> m_rootSignatures[17];
ComPtr<ID3D12RootSignature> m_root_signatures[17];
// TODO: Use a tree structure to parse more efficiently
data_cache m_textureCache;
bool invalidateAddress(u32 addr);
// Copy of RTT to be used as texture
std::unordered_map<u32, ID3D12Resource* > m_texturesRTTs;
data_cache m_texture_cache;
bool invalidate_address(u32 addr);
rsx::surface_info m_surface;
RSXFragmentProgram fragment_program;
PipelineStateObjectCache m_cachePSO;
std::tuple<ID3D12PipelineState *, std::vector<size_t>, size_t> *m_PSO;
PipelineStateObjectCache m_pso_cache;
std::tuple<ID3D12PipelineState *, std::vector<size_t>, size_t> *m_current_pso;
struct
{
size_t m_drawCallDuration;
size_t m_drawCallCount;
size_t m_rttDuration;
size_t m_vertexIndexDuration;
size_t m_bufferUploadSize;
size_t m_programLoadDuration;
size_t m_constantsDuration;
size_t m_textureDuration;
size_t m_flipDuration;
size_t m_draw_calls_duration;
size_t m_draw_calls_count;
size_t m_prepare_rtt_duration;
size_t m_vertex_index_duration;
size_t m_buffer_upload_size;
size_t m_program_load_duration;
size_t m_constants_duration;
size_t m_texture_duration;
size_t m_flip_duration;
} m_timers;
void reset_timer();
@ -103,7 +100,7 @@ private:
* Stores data related to the scaling pass that turns internal
* render targets into presented buffers.
*/
Shader m_outputScalingPass;
Shader m_output_scaling_pass;
/**
* Data used when depth buffer is converted to uchar textures.
@ -112,37 +109,37 @@ private:
ID3D12RootSignature *m_convertRootSignature;
void initConvertShader();
resource_storage m_perFrameStorage[2];
resource_storage &getCurrentResourceStorage();
resource_storage &getNonCurrentResourceStorage();
resource_storage m_per_frame_storage[2];
resource_storage &get_current_resource_storage();
resource_storage &get_non_current_resource_storage();
// Constants storage
data_heap<ID3D12Resource, D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT> m_constantsData;
data_heap<ID3D12Resource, D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT> m_constants_data;
// Vertex storage
data_heap<ID3D12Resource, D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT> m_vertexIndexData;
data_heap<ID3D12Resource, D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT> m_vertex_index_data;
// Texture storage
data_heap<ID3D12Resource, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT> m_textureUploadData;
data_heap<ID3D12Heap, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT> m_UAVHeap;
data_heap<ID3D12Heap, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT> m_readbackResources;
data_heap<ID3D12Resource, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT> m_texture_upload_data;
data_heap<ID3D12Heap, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT> m_uav_heap;
data_heap<ID3D12Heap, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT> m_readback_resources;
struct
{
bool m_indexed; /*<! is draw call using an index buffer */
size_t m_count; /*<! draw call vertex count */
} m_renderingInfo;
} m_rendering_info;
render_targets m_rtts;
std::vector<D3D12_INPUT_ELEMENT_DESC> m_IASet;
std::vector<D3D12_VERTEX_BUFFER_VIEW> m_vertex_buffer_views;
INT g_descriptorStrideSRVCBVUAV;
INT g_descriptorStrideDSV;
INT g_descriptorStrideRTV;
INT g_descriptorStrideSamplers;
INT g_descriptor_stride_srv_cbv_uav;
INT g_descriptor_stride_dsv;
INT g_descriptor_stride_rtv;
INT g_descriptor_stride_samplers;
// Used to fill unused texture slot
ID3D12Resource *m_dummyTexture;
ID3D12Resource *m_dummy_texture;
// Store previous fbo addresses to detect RTT config changes.
u32 m_previous_address_a;

View File

@ -65,7 +65,7 @@ void D3D12GSRender::init_d2d_structures()
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
nullptr,
0,
reinterpret_cast<IUnknown**>(m_commandQueueGraphic.GetAddressOf()),
reinterpret_cast<IUnknown**>(m_command_queue.GetAddressOf()),
1,
0,
&g_d3d11_device,
@ -98,7 +98,7 @@ void D3D12GSRender::init_d2d_structures()
{
D3D11_RESOURCE_FLAGS d3d11Flags = { D3D11_BIND_RENDER_TARGET };
g_d3d11on12_device->CreateWrappedResource(
m_backBuffer[i].Get(),
m_backbuffer[i].Get(),
&d3d11Flags,
D3D12_RESOURCE_STATE_RENDER_TARGET,
D3D12_RESOURCE_STATE_PRESENT,
@ -150,23 +150,23 @@ void D3D12GSRender::release_d2d_structures()
void D3D12GSRender::render_overlay()
{
D2D1_SIZE_F rtSize = g_d2d_render_targets[m_swapChain->GetCurrentBackBufferIndex()]->GetSize();
std::wstring duration = L"Draw duration : " + std::to_wstring(m_timers.m_drawCallDuration) + L" us";
float vtxIdxPercent = (float)m_timers.m_vertexIndexDuration / (float)m_timers.m_drawCallDuration;
std::wstring vertexIndexDuration = L"Vtx/Idx upload : " + std::to_wstring(m_timers.m_vertexIndexDuration) + L" us (" + std::to_wstring(100.f * vtxIdxPercent) + L" %)";
std::wstring size = L"Upload size : " + std::to_wstring(m_timers.m_bufferUploadSize) + L" Bytes";
float texPercent = (float)m_timers.m_textureDuration / (float)m_timers.m_drawCallDuration;
std::wstring texDuration = L"Textures : " + std::to_wstring(m_timers.m_textureDuration) + L" us (" + std::to_wstring(100.f * texPercent) + L" %)";
float programPercent = (float)m_timers.m_programLoadDuration / (float)m_timers.m_drawCallDuration;
std::wstring programDuration = L"Program : " + std::to_wstring(m_timers.m_programLoadDuration) + L" us (" + std::to_wstring(100.f * programPercent) + L" %)";
float constantsPercent = (float)m_timers.m_constantsDuration / (float)m_timers.m_drawCallDuration;
std::wstring constantDuration = L"Constants : " + std::to_wstring(m_timers.m_constantsDuration) + L" us (" + std::to_wstring(100.f * constantsPercent) + L" %)";
float rttPercent = (float)m_timers.m_rttDuration / (float)m_timers.m_drawCallDuration;
std::wstring rttDuration = L"RTT : " + std::to_wstring(m_timers.m_rttDuration) + L" us (" + std::to_wstring(100.f * rttPercent) + L" %)";
std::wstring flipDuration = L"Flip : " + std::to_wstring(m_timers.m_flipDuration) + L" us";
D2D1_SIZE_F rtSize = g_d2d_render_targets[m_swap_chain->GetCurrentBackBufferIndex()]->GetSize();
std::wstring duration = L"Draw duration : " + std::to_wstring(m_timers.m_draw_calls_duration) + L" us";
float vtxIdxPercent = (float)m_timers.m_vertex_index_duration / (float)m_timers.m_draw_calls_duration;
std::wstring vertexIndexDuration = L"Vtx/Idx upload : " + std::to_wstring(m_timers.m_vertex_index_duration) + L" us (" + std::to_wstring(100.f * vtxIdxPercent) + L" %)";
std::wstring size = L"Upload size : " + std::to_wstring(m_timers.m_buffer_upload_size) + L" Bytes";
float texPercent = (float)m_timers.m_texture_duration / (float)m_timers.m_draw_calls_duration;
std::wstring texDuration = L"Textures : " + std::to_wstring(m_timers.m_texture_duration) + L" us (" + std::to_wstring(100.f * texPercent) + L" %)";
float programPercent = (float)m_timers.m_program_load_duration / (float)m_timers.m_draw_calls_duration;
std::wstring programDuration = L"Program : " + std::to_wstring(m_timers.m_program_load_duration) + L" us (" + std::to_wstring(100.f * programPercent) + L" %)";
float constantsPercent = (float)m_timers.m_constants_duration / (float)m_timers.m_draw_calls_duration;
std::wstring constantDuration = L"Constants : " + std::to_wstring(m_timers.m_constants_duration) + L" us (" + std::to_wstring(100.f * constantsPercent) + L" %)";
float rttPercent = (float)m_timers.m_prepare_rtt_duration / (float)m_timers.m_draw_calls_duration;
std::wstring rttDuration = L"RTT : " + std::to_wstring(m_timers.m_prepare_rtt_duration) + L" us (" + std::to_wstring(100.f * rttPercent) + L" %)";
std::wstring flipDuration = L"Flip : " + std::to_wstring(m_timers.m_flip_duration) + L" us";
std::wstring count = L"Draw count : " + std::to_wstring(m_timers.m_drawCallCount);
draw_strings(rtSize, m_swapChain->GetCurrentBackBufferIndex(),
std::wstring count = L"Draw count : " + std::to_wstring(m_timers.m_draw_calls_count);
draw_strings(rtSize, m_swap_chain->GetCurrentBackBufferIndex(),
{
duration,
count,

View File

@ -241,7 +241,7 @@ bool D3D12GSRender::load_program()
prop.CutValue = ((rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4) == CELL_GCM_DRAW_INDEX_ARRAY_TYPE_32) ?
D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_0xFFFFFFFF : D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_0xFFFF;
m_PSO = m_cachePSO.getGraphicPipelineState(&vertex_program, &fragment_program, prop, std::make_pair(m_device.Get(), m_rootSignatures));
return m_PSO != nullptr;
m_current_pso = m_pso_cache.getGraphicPipelineState(&vertex_program, &fragment_program, prop, std::make_pair(m_device.Get(), m_root_signatures));
return m_current_pso != nullptr;
}
#endif

View File

@ -70,51 +70,51 @@ void D3D12GSRender::clear_surface(u32 arg)
std::chrono::time_point<std::chrono::system_clock> start_duration = std::chrono::system_clock::now();
std::chrono::time_point<std::chrono::system_clock> rtt_duration_start = std::chrono::system_clock::now();
prepare_render_targets(getCurrentResourceStorage().command_list.Get());
prepare_render_targets(get_current_resource_storage().command_list.Get());
std::chrono::time_point<std::chrono::system_clock> rtt_duration_end = std::chrono::system_clock::now();
m_timers.m_rttDuration += std::chrono::duration_cast<std::chrono::microseconds>(rtt_duration_end - rtt_duration_start).count();
m_timers.m_prepare_rtt_duration += std::chrono::duration_cast<std::chrono::microseconds>(rtt_duration_end - rtt_duration_start).count();
if (arg & 0x1 || arg & 0x2)
{
CD3DX12_CPU_DESCRIPTOR_HANDLE handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart())
.Offset(getCurrentResourceStorage().depth_stencil_descriptor_heap_index * g_descriptorStrideRTV);
CD3DX12_CPU_DESCRIPTOR_HANDLE handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart())
.Offset(get_current_resource_storage().depth_stencil_descriptor_heap_index * g_descriptor_stride_rtv);
m_rtts.bind_depth_stencil(m_device.Get(), m_surface.depth_format, handle);
getCurrentResourceStorage().depth_stencil_descriptor_heap_index++;
get_current_resource_storage().depth_stencil_descriptor_heap_index++;
if (arg & 0x1)
{
u32 clear_depth = rsx::method_registers[NV4097_SET_ZSTENCIL_CLEAR_VALUE] >> 8;
u32 max_depth_value = m_surface.depth_format == CELL_GCM_SURFACE_Z16 ? 0x0000ffff : 0x00ffffff;
getCurrentResourceStorage().command_list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_DEPTH, clear_depth / (float)max_depth_value, 0,
get_current_resource_storage().command_list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_DEPTH, clear_depth / (float)max_depth_value, 0,
1, &get_scissor(rsx::method_registers[NV4097_SET_SCISSOR_HORIZONTAL], rsx::method_registers[NV4097_SET_SCISSOR_VERTICAL]));
}
if (arg & 0x2)
getCurrentResourceStorage().command_list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_STENCIL, 0.f, get_clear_stencil(rsx::method_registers[NV4097_SET_ZSTENCIL_CLEAR_VALUE]),
get_current_resource_storage().command_list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_STENCIL, 0.f, get_clear_stencil(rsx::method_registers[NV4097_SET_ZSTENCIL_CLEAR_VALUE]),
1, &get_scissor(rsx::method_registers[NV4097_SET_SCISSOR_HORIZONTAL], rsx::method_registers[NV4097_SET_SCISSOR_VERTICAL]));
}
if (arg & 0xF0)
{
CD3DX12_CPU_DESCRIPTOR_HANDLE handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset(getCurrentResourceStorage().render_targets_descriptors_heap_index * g_descriptorStrideRTV);
CD3DX12_CPU_DESCRIPTOR_HANDLE handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset(get_current_resource_storage().render_targets_descriptors_heap_index * g_descriptor_stride_rtv);
size_t rtt_index = m_rtts.bind_render_targets(m_device.Get(), m_surface.color_format, handle);
getCurrentResourceStorage().render_targets_descriptors_heap_index += rtt_index;
get_current_resource_storage().render_targets_descriptors_heap_index += rtt_index;
for (unsigned i = 0; i < rtt_index; i++)
getCurrentResourceStorage().command_list->ClearRenderTargetView(handle.Offset(i, g_descriptorStrideRTV), get_clear_color(rsx::method_registers[NV4097_SET_COLOR_CLEAR_VALUE]).data(),
get_current_resource_storage().command_list->ClearRenderTargetView(handle.Offset(i, g_descriptor_stride_rtv), get_clear_color(rsx::method_registers[NV4097_SET_COLOR_CLEAR_VALUE]).data(),
1, &get_scissor(rsx::method_registers[NV4097_SET_SCISSOR_HORIZONTAL], rsx::method_registers[NV4097_SET_SCISSOR_VERTICAL]));
}
std::chrono::time_point<std::chrono::system_clock> end_duration = std::chrono::system_clock::now();
m_timers.m_drawCallDuration += std::chrono::duration_cast<std::chrono::microseconds>(end_duration - start_duration).count();
m_timers.m_drawCallCount++;
m_timers.m_draw_calls_duration += std::chrono::duration_cast<std::chrono::microseconds>(end_duration - start_duration).count();
m_timers.m_draw_calls_count++;
if (rpcs3::config.rsx.d3d12.debug_output.value())
{
ThrowIfFailed(getCurrentResourceStorage().command_list->Close());
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().command_list.GetAddressOf());
getCurrentResourceStorage().set_new_command_list();
ThrowIfFailed(get_current_resource_storage().command_list->Close());
m_command_queue->ExecuteCommandLists(1, (ID3D12CommandList**)get_current_resource_storage().command_list.GetAddressOf());
get_current_resource_storage().set_new_command_list();
}
}
@ -211,7 +211,7 @@ void D3D12GSRender::prepare_render_targets(ID3D12GraphicsCommandList *copycmdlis
ComPtr<ID3D12Resource> old_depth_stencil_resource;
ID3D12Resource *ds = m_rtts.bind_address_as_depth_stencil(m_device.Get(), copycmdlist, address_z, clip_width, clip_height, m_surface.depth_format, 1., 0, old_depth_stencil_resource);
if (old_depth_stencil_resource)
getCurrentResourceStorage().dirty_textures.push_back(old_depth_stencil_resource);
get_current_resource_storage().dirty_textures.push_back(old_depth_stencil_resource);
m_rtts.bound_depth_stencil_address = address_z;
m_rtts.bound_depth_stencil = ds;
}
@ -248,14 +248,14 @@ size_t render_targets::bind_depth_stencil(ID3D12Device *device, u32 depth_format
void D3D12GSRender::set_rtt_and_ds(ID3D12GraphicsCommandList *command_list)
{
CD3DX12_CPU_DESCRIPTOR_HANDLE handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset(getCurrentResourceStorage().render_targets_descriptors_heap_index * g_descriptorStrideRTV);
CD3DX12_CPU_DESCRIPTOR_HANDLE handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset(get_current_resource_storage().render_targets_descriptors_heap_index * g_descriptor_stride_rtv);
size_t num_rtt = m_rtts.bind_render_targets(m_device.Get(), m_surface.color_format, handle);
getCurrentResourceStorage().render_targets_descriptors_heap_index += num_rtt;
CD3DX12_CPU_DESCRIPTOR_HANDLE depth_stencil_handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart())
.Offset(getCurrentResourceStorage().depth_stencil_descriptor_heap_index * g_descriptorStrideRTV);
get_current_resource_storage().render_targets_descriptors_heap_index += num_rtt;
CD3DX12_CPU_DESCRIPTOR_HANDLE depth_stencil_handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart())
.Offset(get_current_resource_storage().depth_stencil_descriptor_heap_index * g_descriptor_stride_rtv);
size_t num_ds = m_rtts.bind_depth_stencil(m_device.Get(), m_surface.depth_format, depth_stencil_handle);
getCurrentResourceStorage().depth_stencil_descriptor_heap_index += num_ds;
get_current_resource_storage().depth_stencil_descriptor_heap_index += num_ds;
command_list->OMSetRenderTargets((UINT)num_rtt, num_rtt > 0 ? &handle : nullptr, !!num_rtt,
num_ds > 0 ? &depth_stencil_handle : nullptr);
}
@ -449,12 +449,12 @@ void D3D12GSRender::copy_render_target_to_dma_location()
if (m_context_dma_z && rpcs3::state.config.rsx.opengl.write_depth_buffer)
{
size_t uav_size = clip_w * clip_h * 2;
assert(m_UAVHeap.can_alloc(uav_size));
size_t heap_offset = m_UAVHeap.alloc(uav_size);
assert(m_uav_heap.can_alloc(uav_size));
size_t heap_offset = m_uav_heap.alloc(uav_size);
ThrowIfFailed(
m_device->CreatePlacedResource(
m_UAVHeap.m_heap,
m_uav_heap.m_heap,
heap_offset,
&CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8_UNORM, clip_w, clip_h, 1, 1, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS),
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
@ -464,12 +464,12 @@ void D3D12GSRender::copy_render_target_to_dma_location()
);
size_t buffer_size = depth_row_pitch * clip_h;
assert(m_readbackResources.can_alloc(buffer_size));
heap_offset = m_readbackResources.alloc(buffer_size);
assert(m_readback_resources.can_alloc(buffer_size));
heap_offset = m_readback_resources.alloc(buffer_size);
ThrowIfFailed(
m_device->CreatePlacedResource(
m_readbackResources.m_heap,
m_readback_resources.m_heap,
heap_offset,
&CD3DX12_RESOURCE_DESC::Buffer(buffer_size),
D3D12_RESOURCE_STATE_COPY_DEST,
@ -493,28 +493,28 @@ void D3D12GSRender::copy_render_target_to_dma_location()
uav_desc.Format = DXGI_FORMAT_R8_UNORM;
uav_desc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
m_device->CreateUnorderedAccessView(depth_format_conversion_buffer.Get(), nullptr, &uav_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(descriptor_heap->GetCPUDescriptorHandleForHeapStart()).Offset(1, g_descriptorStrideSRVCBVUAV));
CD3DX12_CPU_DESCRIPTOR_HANDLE(descriptor_heap->GetCPUDescriptorHandleForHeapStart()).Offset(1, g_descriptor_stride_srv_cbv_uav));
// Convert
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_depth_stencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ));
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_depth_stencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ));
getCurrentResourceStorage().command_list->SetPipelineState(m_convertPSO);
getCurrentResourceStorage().command_list->SetComputeRootSignature(m_convertRootSignature);
getCurrentResourceStorage().command_list->SetDescriptorHeaps(1, descriptor_heap.GetAddressOf());
getCurrentResourceStorage().command_list->SetComputeRootDescriptorTable(0, descriptor_heap->GetGPUDescriptorHandleForHeapStart());
getCurrentResourceStorage().command_list->Dispatch(clip_w / 8, clip_h / 8, 1);
get_current_resource_storage().command_list->SetPipelineState(m_convertPSO);
get_current_resource_storage().command_list->SetComputeRootSignature(m_convertRootSignature);
get_current_resource_storage().command_list->SetDescriptorHeaps(1, descriptor_heap.GetAddressOf());
get_current_resource_storage().command_list->SetComputeRootDescriptorTable(0, descriptor_heap->GetGPUDescriptorHandleForHeapStart());
get_current_resource_storage().command_list->Dispatch(clip_w / 8, clip_h / 8, 1);
D3D12_RESOURCE_BARRIER barriers[] =
{
CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_depth_stencil, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_DEPTH_WRITE),
CD3DX12_RESOURCE_BARRIER::UAV(depth_format_conversion_buffer.Get()),
};
getCurrentResourceStorage().command_list->ResourceBarrier(2, barriers);
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(depth_format_conversion_buffer.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE));
getCurrentResourceStorage().command_list->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(depth_buffer_write_dest.Get(), { 0,{ DXGI_FORMAT_R8_UNORM, (UINT)clip_w, (UINT)clip_h, 1, (UINT)depth_row_pitch } }), 0, 0, 0,
get_current_resource_storage().command_list->ResourceBarrier(2, barriers);
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(depth_format_conversion_buffer.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE));
get_current_resource_storage().command_list->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(depth_buffer_write_dest.Get(), { 0,{ DXGI_FORMAT_R8_UNORM, (UINT)clip_w, (UINT)clip_h, 1, (UINT)depth_row_pitch } }), 0, 0, 0,
&CD3DX12_TEXTURE_COPY_LOCATION(depth_buffer_write_dest.Get(), 0), nullptr);
invalidateAddress(rsx::get_address(rsx::method_registers[NV4097_SET_SURFACE_ZETA_OFFSET], m_context_dma_z - 0xfeed0000));
invalidate_address(rsx::get_address(rsx::method_registers[NV4097_SET_SURFACE_ZETA_OFFSET], m_context_dma_z - 0xfeed0000));
need_transfer = true;
}
@ -526,20 +526,20 @@ void D3D12GSRender::copy_render_target_to_dma_location()
{
if (!context_dma_color[i])
continue;
readback_buffers[i] = create_readback_buffer_and_download(m_device.Get(), getCurrentResourceStorage().command_list.Get(), m_readbackResources, m_rtts.bound_render_targets[0], m_surface.color_format);
invalidateAddress(rsx::get_address(rsx::method_registers[NV4097_SET_SURFACE_COLOR_AOFFSET], context_dma_color[i] - 0xfeed0000));
readback_buffers[i] = create_readback_buffer_and_download(m_device.Get(), get_current_resource_storage().command_list.Get(), m_readback_resources, m_rtts.bound_render_targets[0], m_surface.color_format);
invalidate_address(rsx::get_address(rsx::method_registers[NV4097_SET_SURFACE_COLOR_AOFFSET], context_dma_color[i] - 0xfeed0000));
need_transfer = true;
}
}
if (need_transfer)
{
ThrowIfFailed(getCurrentResourceStorage().command_list->Close());
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().command_list.GetAddressOf());
getCurrentResourceStorage().set_new_command_list();
ThrowIfFailed(get_current_resource_storage().command_list->Close());
m_command_queue->ExecuteCommandLists(1, (ID3D12CommandList**)get_current_resource_storage().command_list.GetAddressOf());
get_current_resource_storage().set_new_command_list();
}
//Wait for result
wait_for_command_queue(m_device.Get(), m_commandQueueGraphic.Get());
wait_for_command_queue(m_device.Get(), m_command_queue.Get());
if (m_context_dma_z && rpcs3::state.config.rsx.opengl.write_depth_buffer)
{
@ -597,14 +597,14 @@ void D3D12GSRender::copy_render_target_to_dma_location()
void D3D12GSRender::copy_render_targets_to_memory(void *buffer, u8 rtt)
{
ComPtr<ID3D12Resource> readback_buffer = create_readback_buffer_and_download(m_device.Get(), getCurrentResourceStorage().command_list.Get(), m_readbackResources, m_rtts.bound_render_targets[rtt], m_surface.color_format);
ComPtr<ID3D12Resource> readback_buffer = create_readback_buffer_and_download(m_device.Get(), get_current_resource_storage().command_list.Get(), m_readback_resources, m_rtts.bound_render_targets[rtt], m_surface.color_format);
ThrowIfFailed(getCurrentResourceStorage().command_list->Close());
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().command_list.GetAddressOf());
getCurrentResourceStorage().set_new_command_list();
ThrowIfFailed(get_current_resource_storage().command_list->Close());
m_command_queue->ExecuteCommandLists(1, (ID3D12CommandList**)get_current_resource_storage().command_list.GetAddressOf());
get_current_resource_storage().set_new_command_list();
wait_for_command_queue(m_device.Get(), m_commandQueueGraphic.Get());
m_readbackResources.m_get_pos = m_readbackResources.get_current_put_pos_minus_one();
wait_for_command_queue(m_device.Get(), m_command_queue.Get());
m_readback_resources.m_get_pos = m_readback_resources.get_current_put_pos_minus_one();
int clip_w = rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16;
int clip_h = rsx::method_registers[NV4097_SET_SURFACE_CLIP_VERTICAL] >> 16;
@ -632,11 +632,11 @@ void D3D12GSRender::copy_depth_buffer_to_memory(void *buffer)
ComPtr<ID3D12Resource> readback_buffer;
size_t buffer_size = row_pitch * clip_h;
assert(m_readbackResources.can_alloc(buffer_size));
size_t heapOffset = m_readbackResources.alloc(buffer_size);
assert(m_readback_resources.can_alloc(buffer_size));
size_t heapOffset = m_readback_resources.alloc(buffer_size);
ThrowIfFailed(
m_device->CreatePlacedResource(
m_readbackResources.m_heap,
m_readback_resources.m_heap,
heapOffset,
&CD3DX12_RESOURCE_DESC::Buffer(buffer_size),
D3D12_RESOURCE_STATE_COPY_DEST,
@ -645,18 +645,18 @@ void D3D12GSRender::copy_depth_buffer_to_memory(void *buffer)
)
);
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_depth_stencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_COPY_SOURCE));
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_depth_stencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_COPY_SOURCE));
getCurrentResourceStorage().command_list->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(readback_buffer.Get(), { 0,{ DXGI_FORMAT_R32_TYPELESS, (UINT)clip_w, (UINT)clip_h, 1, (UINT)row_pitch } }), 0, 0, 0,
get_current_resource_storage().command_list->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(readback_buffer.Get(), { 0,{ DXGI_FORMAT_R32_TYPELESS, (UINT)clip_w, (UINT)clip_h, 1, (UINT)row_pitch } }), 0, 0, 0,
&CD3DX12_TEXTURE_COPY_LOCATION(m_rtts.bound_depth_stencil, 0), nullptr);
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_depth_stencil, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_DEPTH_WRITE));
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_depth_stencil, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_DEPTH_WRITE));
ThrowIfFailed(getCurrentResourceStorage().command_list->Close());
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().command_list.GetAddressOf());
getCurrentResourceStorage().set_new_command_list();
ThrowIfFailed(get_current_resource_storage().command_list->Close());
m_command_queue->ExecuteCommandLists(1, (ID3D12CommandList**)get_current_resource_storage().command_list.GetAddressOf());
get_current_resource_storage().set_new_command_list();
wait_for_command_queue(m_device.Get(), m_commandQueueGraphic.Get());
m_readbackResources.m_get_pos = m_readbackResources.get_current_put_pos_minus_one();
wait_for_command_queue(m_device.Get(), m_command_queue.Get());
m_readback_resources.m_get_pos = m_readback_resources.get_current_put_pos_minus_one();
void *mapped_buffer;
ThrowIfFailed(readback_buffer->Map(0, nullptr, &mapped_buffer));
@ -680,11 +680,11 @@ void D3D12GSRender::copy_stencil_buffer_to_memory(void *buffer)
ComPtr<ID3D12Resource> readback_buffer;
size_t buffer_size = row_pitch * clip_h;
assert(m_readbackResources.can_alloc(buffer_size));
size_t heapOffset = m_readbackResources.alloc(buffer_size);
assert(m_readback_resources.can_alloc(buffer_size));
size_t heapOffset = m_readback_resources.alloc(buffer_size);
ThrowIfFailed(
m_device->CreatePlacedResource(
m_readbackResources.m_heap,
m_readback_resources.m_heap,
heapOffset,
&CD3DX12_RESOURCE_DESC::Buffer(buffer_size),
D3D12_RESOURCE_STATE_COPY_DEST,
@ -693,18 +693,18 @@ void D3D12GSRender::copy_stencil_buffer_to_memory(void *buffer)
)
);
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_depth_stencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_COPY_SOURCE));
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_depth_stencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_COPY_SOURCE));
getCurrentResourceStorage().command_list->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(readback_buffer.Get(), { 0,{ DXGI_FORMAT_R8_TYPELESS, (UINT)clip_w, (UINT)clip_h, 1, (UINT)row_pitch } }), 0, 0, 0,
get_current_resource_storage().command_list->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(readback_buffer.Get(), { 0,{ DXGI_FORMAT_R8_TYPELESS, (UINT)clip_w, (UINT)clip_h, 1, (UINT)row_pitch } }), 0, 0, 0,
&CD3DX12_TEXTURE_COPY_LOCATION(m_rtts.bound_depth_stencil, 1), nullptr);
getCurrentResourceStorage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_depth_stencil, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_DEPTH_WRITE));
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_rtts.bound_depth_stencil, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_DEPTH_WRITE));
ThrowIfFailed(getCurrentResourceStorage().command_list->Close());
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().command_list.GetAddressOf());
getCurrentResourceStorage().set_new_command_list();
ThrowIfFailed(get_current_resource_storage().command_list->Close());
m_command_queue->ExecuteCommandLists(1, (ID3D12CommandList**)get_current_resource_storage().command_list.GetAddressOf());
get_current_resource_storage().set_new_command_list();
wait_for_command_queue(m_device.Get(), m_commandQueueGraphic.Get());
m_readbackResources.m_get_pos = m_readbackResources.get_current_put_pos_minus_one();
wait_for_command_queue(m_device.Get(), m_command_queue.Get());
m_readback_resources.m_get_pos = m_readback_resources.get_current_put_pos_minus_one();
void *mapped_buffer;
ThrowIfFailed(readback_buffer->Map(0, nullptr, &mapped_buffer));

View File

@ -141,7 +141,7 @@ void D3D12GSRender::upload_and_bind_textures(ID3D12GraphicsCommandList *command_
ID3D12Resource *vram_texture;
std::unordered_map<u32, ComPtr<ID3D12Resource> >::const_iterator ItRTT = m_rtts.render_targets_storage.find(texaddr);
std::pair<texture_entry, ComPtr<ID3D12Resource> > *cached_texture = m_textureCache.find_data_if_available(texaddr);
std::pair<texture_entry, ComPtr<ID3D12Resource> > *cached_texture = m_texture_cache.find_data_if_available(texaddr);
bool isRenderTarget = false;
if (ItRTT != m_rtts.render_targets_storage.end())
{
@ -152,18 +152,18 @@ void D3D12GSRender::upload_and_bind_textures(ID3D12GraphicsCommandList *command_
{
if (cached_texture->first.m_is_dirty)
{
update_existing_texture(textures[i], command_list, m_textureUploadData, cached_texture->second.Get());
m_textureCache.protect_data(texaddr, texaddr, get_texture_size(textures[i]));
update_existing_texture(textures[i], command_list, m_texture_upload_data, cached_texture->second.Get());
m_texture_cache.protect_data(texaddr, texaddr, get_texture_size(textures[i]));
}
vram_texture = cached_texture->second.Get();
}
else
{
if (cached_texture != nullptr)
getCurrentResourceStorage().dirty_textures.push_back(m_textureCache.remove_from_cache(texaddr));
ComPtr<ID3D12Resource> tex = upload_single_texture(textures[i], m_device.Get(), command_list, m_textureUploadData);
get_current_resource_storage().dirty_textures.push_back(m_texture_cache.remove_from_cache(texaddr));
ComPtr<ID3D12Resource> tex = upload_single_texture(textures[i], m_device.Get(), command_list, m_texture_upload_data);
vram_texture = tex.Get();
m_textureCache.store_and_protect_data(texaddr, texaddr, get_texture_size(textures[i]), format, w, h, textures[i].mipmap(), tex);
m_texture_cache.store_and_protect_data(texaddr, texaddr, get_texture_size(textures[i]), format, w, h, textures[i].mipmap(), tex);
}
D3D12_SHADER_RESOURCE_VIEW_DESC shared_resource_view_desc = {};
@ -291,17 +291,17 @@ void D3D12GSRender::upload_and_bind_textures(ID3D12GraphicsCommandList *command_
}
m_device->CreateShaderResourceView(vram_texture, &shared_resource_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((UINT)descriptor_index + (UINT)used_texture, g_descriptorStrideSRVCBVUAV));
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((UINT)descriptor_index + (UINT)used_texture, g_descriptor_stride_srv_cbv_uav));
if (getCurrentResourceStorage().current_sampler_index + 16 > 2048)
if (get_current_resource_storage().current_sampler_index + 16 > 2048)
{
getCurrentResourceStorage().sampler_descriptors_heap_index = 1;
getCurrentResourceStorage().current_sampler_index = 0;
get_current_resource_storage().sampler_descriptors_heap_index = 1;
get_current_resource_storage().current_sampler_index = 0;
}
m_device->CreateSampler(&get_sampler_desc(textures[i]),
CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().sampler_descriptor_heap[getCurrentResourceStorage().sampler_descriptors_heap_index]->GetCPUDescriptorHandleForHeapStart())
.Offset((UINT)getCurrentResourceStorage().current_sampler_index + (UINT)used_texture, g_descriptorStrideSamplers));
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index]->GetCPUDescriptorHandleForHeapStart())
.Offset((UINT)get_current_resource_storage().current_sampler_index + (UINT)used_texture, g_descriptor_stride_samplers));
used_texture++;
}
@ -318,9 +318,9 @@ void D3D12GSRender::upload_and_bind_textures(ID3D12GraphicsCommandList *command_
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0,
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0,
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0);
m_device->CreateShaderResourceView(m_dummyTexture, &shader_resource_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptor_index + (INT)used_texture, g_descriptorStrideSRVCBVUAV)
m_device->CreateShaderResourceView(m_dummy_texture, &shader_resource_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptor_index + (INT)used_texture, g_descriptor_stride_srv_cbv_uav)
);
D3D12_SAMPLER_DESC sampler_desc = {};
@ -329,8 +329,8 @@ void D3D12GSRender::upload_and_bind_textures(ID3D12GraphicsCommandList *command_
sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
m_device->CreateSampler(&sampler_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().sampler_descriptor_heap[getCurrentResourceStorage().sampler_descriptors_heap_index]->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)getCurrentResourceStorage().current_sampler_index + (INT)used_texture, g_descriptorStrideSamplers)
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index]->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)get_current_resource_storage().current_sampler_index + (INT)used_texture, g_descriptor_stride_samplers)
);
}
}