Пример #1
0
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(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.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();

	size_t currentDescriptorIndex = get_current_resource_storage().descriptors_heap_index;

	size_t vertex_count;
	bool indexed_draw;
	std::vector<D3D12_SHADER_RESOURCE_VIEW_DESC> vertex_buffer_views;
	std::tie(indexed_draw, vertex_count, vertex_buffer_views) = upload_and_set_vertex_index_data(get_current_resource_storage().command_list.Get());

	size_t vertex_buffer_count = vertex_buffer_views.size();

	std::chrono::time_point<std::chrono::system_clock> vertex_index_duration_end = std::chrono::system_clock::now();
	m_timers.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();
	load_program();
	std::chrono::time_point<std::chrono::system_clock> program_load_end = std::chrono::system_clock::now();
	m_timers.program_load_duration += std::chrono::duration_cast<std::chrono::microseconds>(program_load_end - program_load_start).count();

	get_current_resource_storage().command_list->SetGraphicsRootSignature(m_root_signatures[std::get<2>(m_current_pso)][vertex_buffer_count].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();

	INT offset = 0;
	for (const auto view : vertex_buffer_views)
	{
		m_device->CreateShaderResourceView(m_vertex_buffer_data.Get(), &view,
			CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
				.Offset((INT)currentDescriptorIndex + offset++, m_descriptor_stride_srv_cbv_uav));
	}

	// Constants
	upload_and_bind_scale_offset_matrix(currentDescriptorIndex + vertex_buffer_count);
	upload_and_bind_vertex_shader_constants(currentDescriptorIndex + 1 + vertex_buffer_count);
	upload_and_bind_fragment_shader_constants(currentDescriptorIndex + 2 + vertex_buffer_count);

	std::chrono::time_point<std::chrono::system_clock> constants_duration_end = std::chrono::system_clock::now();
	m_timers.constants_duration += std::chrono::duration_cast<std::chrono::microseconds>(constants_duration_end - constants_duration_start).count();

	get_current_resource_storage().command_list->SetPipelineState(std::get<0>(m_current_pso).Get());

	std::chrono::time_point<std::chrono::system_clock> texture_duration_start = std::chrono::system_clock::now();
	size_t texture_count = std::get<2>(m_current_pso);
	if (texture_count > 0)
	{
		upload_and_bind_textures(get_current_resource_storage().command_list.Get(), texture_count);

		for (unsigned i = 0; i < texture_count; i++)
		{
			ID3D12Resource *tex_resource;
			D3D12_SHADER_RESOURCE_VIEW_DESC srv;
			std::tie(tex_resource, srv) = m_current_shader_resources[i];
			m_device->CreateShaderResourceView(tex_resource, &srv,
				CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
				.Offset((INT)currentDescriptorIndex + 3 + (INT)vertex_buffer_count + (INT)i, m_descriptor_stride_srv_cbv_uav)
				);
			m_device->CreateSampler(&m_current_samplers[i],
				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)i, m_descriptor_stride_samplers));
		}

		get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(0,
			CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetGPUDescriptorHandleForHeapStart())
			.Offset((INT)currentDescriptorIndex, m_descriptor_stride_srv_cbv_uav)
			);
		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, m_descriptor_stride_samplers)
			);

		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 + vertex_buffer_count;
	}
	else
	{
		get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(0,
			CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetGPUDescriptorHandleForHeapStart())
			.Offset((INT)currentDescriptorIndex, m_descriptor_stride_srv_cbv_uav)
			);
		get_current_resource_storage().descriptors_heap_index += 3 + vertex_buffer_count;
	}

	std::chrono::time_point<std::chrono::system_clock> texture_duration_end = std::chrono::system_clock::now();
	m_timers.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;

	D3D12_VIEWPORT viewport =
	{
		0.f,
		0.f,
		(float)clip_w,
		(float)clip_h,
		(f32&)rsx::method_registers[NV4097_SET_CLIP_MIN],
		(f32&)rsx::method_registers[NV4097_SET_CLIP_MAX]
	};
	get_current_resource_storage().command_list->RSSetViewports(1, &viewport);

	get_current_resource_storage().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->IASetPrimitiveTopology(get_primitive_topology(draw_mode));

	if (indexed_draw)
		get_current_resource_storage().command_list->DrawIndexedInstanced((UINT)vertex_count, 1, 0, 0, 0);
	else
		get_current_resource_storage().command_list->DrawInstanced((UINT)vertex_count, 1, 0, 0);

	std::chrono::time_point<std::chrono::system_clock> end_duration = std::chrono::system_clock::now();
	m_timers.draw_calls_duration += std::chrono::duration_cast<std::chrono::microseconds>(end_duration - start_duration).count();
	m_timers.draw_calls_count++;

	if (rpcs3::config.rsx.d3d12.debug_output.value())
	{
		CHECK_HRESULT(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();
	}
	thread::end();
}
Пример #2
0
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());

	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();

	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());

	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();

	std::chrono::time_point<std::chrono::system_clock> program_load_start = std::chrono::system_clock::now();
	if (!load_program())
	{
		LOG_ERROR(RSX, "LoadProgram failed.");
		Emu.Pause();
		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();

	getCurrentResourceStorage().command_list->SetGraphicsRootSignature(m_rootSignatures[std::get<2>(*m_PSO)].Get());
	getCurrentResourceStorage().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;
	// 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();

	getCurrentResourceStorage().command_list->SetPipelineState(std::get<0>(*m_PSO));

	std::chrono::time_point<std::chrono::system_clock> texture_duration_start = std::chrono::system_clock::now();
	if (std::get<2>(*m_PSO) > 0)
	{
		upload_and_bind_textures(getCurrentResourceStorage().command_list.Get(), currentDescriptorIndex + 3, std::get<2>(*m_PSO) > 0);

		ID3D12DescriptorHeap *descriptors[] =
		{
			getCurrentResourceStorage().descriptors_heap.Get(),
			getCurrentResourceStorage().sampler_descriptor_heap[getCurrentResourceStorage().sampler_descriptors_heap_index].Get(),
		};
		getCurrentResourceStorage().command_list->SetDescriptorHeaps(2, descriptors);

		getCurrentResourceStorage().command_list->SetGraphicsRootDescriptorTable(0,
			CD3DX12_GPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().descriptors_heap->GetGPUDescriptorHandleForHeapStart())
			.Offset((INT)currentDescriptorIndex, g_descriptorStrideSRVCBVUAV)
			);
		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)
			);

		getCurrentResourceStorage().current_sampler_index += std::get<2>(*m_PSO);
		getCurrentResourceStorage().descriptors_heap_index += std::get<2>(*m_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)
			);
		getCurrentResourceStorage().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());

	int clip_w = rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16;
	int clip_h = rsx::method_registers[NV4097_SET_SURFACE_CLIP_VERTICAL] >> 16;

	D3D12_VIEWPORT viewport =
	{
		0.f,
		0.f,
		(float)clip_w,
		(float)clip_h,
		-1.f,
		1.f
	};
	getCurrentResourceStorage().command_list->RSSetViewports(1, &viewport);

	D3D12_RECT box =
	{
		0,
		0,
		(LONG)clip_w,
		(LONG)clip_h,
	};
	getCurrentResourceStorage().command_list->RSSetScissorRects(1, &box);

	getCurrentResourceStorage().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);
	else
		getCurrentResourceStorage().command_list->DrawInstanced((UINT)m_renderingInfo.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++;

	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();
	}
	m_first_count_pairs.clear();
	m_renderingInfo.m_indexed = false;
	thread::end();
}