Exemplo n.º 1
0
void MaterialResource::SetSRVInternal(ColorBuffer& buffer, bool immediate)
{
	// Validate type
	if (m_type != ShaderResourceType::Unsupported)
	{
		assert_msg(IsSRVType(m_type),
			"MaterialResource is bound to a UAV, but an SRV is being assigned.");
	}

	m_cpuHandle = buffer.GetSRV();

	_ReadWriteBarrier();

	DispatchToRenderThread(m_cpuHandle, immediate);
}
Exemplo n.º 2
0
void MotionBlur::RenderObjectBlur( CommandContext& BaseContext, ColorBuffer& velocityBuffer )
{
	ScopedTimer _prof(L"MotionBlur", BaseContext);

	if (!Enable)
		return;

	uint32_t Width = g_SceneColorBuffer.GetWidth();
	uint32_t Height = g_SceneColorBuffer.GetHeight();

	ComputeContext& Context = BaseContext.GetComputeContext();

	Context.SetRootSignature(s_RootSignature);

	Context.TransitionResource(g_MotionPrepBuffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
	Context.TransitionResource(g_SceneColorBuffer, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
	Context.TransitionResource(velocityBuffer, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);

	Context.SetDynamicDescriptor(2, 0, g_MotionPrepBuffer.GetUAV());
	Context.SetDynamicDescriptor(3, 0, g_SceneColorBuffer.GetSRV());
	Context.SetDynamicDescriptor(3, 1, velocityBuffer.GetSRV());

	Context.SetPipelineState(s_MotionBlurPrePassCS);
	Context.Dispatch2D(g_MotionPrepBuffer.GetWidth(), g_MotionPrepBuffer.GetHeight());

	if (g_bTypedUAVLoadSupport_R11G11B10_FLOAT)
	{
		Context.SetPipelineState(s_MotionBlurFinalPassCS);

		Context.TransitionResource(g_SceneColorBuffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		Context.TransitionResource(velocityBuffer, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
		Context.TransitionResource(g_MotionPrepBuffer, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);

		Context.SetDynamicDescriptor(2, 0, g_SceneColorBuffer.GetUAV());
		Context.SetDynamicDescriptor(3, 0, velocityBuffer.GetSRV());
		Context.SetDynamicDescriptor(3, 1, g_MotionPrepBuffer.GetSRV());
		Context.SetConstants(0, 1.0f / Width, 1.0f / Height);

		Context.Dispatch2D(Width, Height);

		Context.InsertUAVBarrier(g_SceneColorBuffer);
	}
	else
	{
		GraphicsContext& GrContext = BaseContext.GetGraphicsContext();
		GrContext.SetRootSignature(s_RootSignature);
		GrContext.SetPipelineState(s_MotionBlurFinalPassPS);

		GrContext.TransitionResource(g_SceneColorBuffer, D3D12_RESOURCE_STATE_RENDER_TARGET);
		GrContext.TransitionResource(g_VelocityBuffer, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
		GrContext.TransitionResource(g_MotionPrepBuffer, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);

		GrContext.SetDynamicDescriptor(3, 0, g_VelocityBuffer.GetSRV());
		GrContext.SetDynamicDescriptor(3, 1, g_MotionPrepBuffer.GetSRV());
		GrContext.SetConstants(0, 1.0f / Width, 1.0f / Height);
		GrContext.SetRenderTarget(g_SceneColorBuffer.GetRTV());
		GrContext.SetViewportAndScissor(0, 0, Width, Height);

		GrContext.Draw(3);
	}
}