当前位置: 首页>>代码示例>>C++>>正文


C++ CommandContext::GetComputeContext方法代码示例

本文整理汇总了C++中CommandContext::GetComputeContext方法的典型用法代码示例。如果您正苦于以下问题:C++ CommandContext::GetComputeContext方法的具体用法?C++ CommandContext::GetComputeContext怎么用?C++ CommandContext::GetComputeContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandContext的用法示例。


在下文中一共展示了CommandContext::GetComputeContext方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GenerateMipMaps

void ColorBuffer::GenerateMipMaps(CommandContext& BaseContext)
{
	if (m_NumMipMaps == 0)
		return;

	ComputeContext& Context = BaseContext.GetComputeContext();

	Context.SetRootSignature(Graphics::g_GenerateMipsRS);

	Context.TransitionResource(*this, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
	Context.SetDynamicDescriptor(1, 0, m_SRVHandle);

	for (uint32_t TopMip = 0; TopMip < m_NumMipMaps; )
	{
		uint32_t SrcWidth = m_Width >> TopMip;
		uint32_t SrcHeight = m_Height >> TopMip;
		uint32_t DstWidth = SrcWidth >> 1;
		uint32_t DstHeight = SrcHeight >> 1;

		// Determine if the first downsample is more than 2:1.  This happens whenever
		// the source width or height is odd.
		uint32_t NonPowerOfTwo = (SrcWidth & 1) | (SrcHeight & 1) << 1;
		if (m_Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB)
			Context.SetPipelineState(Graphics::g_GenerateMipsGammaPSO[NonPowerOfTwo]);
		else
			Context.SetPipelineState(Graphics::g_GenerateMipsLinearPSO[NonPowerOfTwo]);

		// We can downsample up to four times, but if the ratio between levels is not
		// exactly 2:1, we have to shift our blend weights, which gets complicated or
		// expensive.  Maybe we can update the code later to compute sample weights for
		// each successive downsample.  We use _BitScanForward to count number of zeros
		// in the low bits.  Zeros indicate we can divide by two without truncating.
		uint32_t AdditionalMips;
		_BitScanForward((unsigned long*)&AdditionalMips, DstWidth | DstHeight);
		uint32_t NumMips = 1 + (AdditionalMips > 3 ? 3 : AdditionalMips);
		if (TopMip + NumMips > m_NumMipMaps)
			NumMips = m_NumMipMaps - TopMip;

		// These are clamped to 1 after computing additional mips because clamped
		// dimensions should not limit us from downsampling multiple times.  (E.g.
		// 16x1 -> 8x1 -> 4x1 -> 2x1 -> 1x1.)
		if (DstWidth == 0)
			DstWidth = 1;
		if (DstHeight == 0)
			DstHeight = 1;

		Context.SetConstants(0, TopMip, NumMips, 1.0f / DstWidth, 1.0f / DstHeight);
		Context.SetDynamicDescriptors(2, 0, NumMips, m_UAVHandle + TopMip + 1);
		Context.Dispatch2D(DstWidth, DstHeight);

		Context.InsertUAVBarrier(*this);

		TopMip += NumMips;
	}

	Context.TransitionResource(*this, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE |
		D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
}
开发者ID:GeorgeKps,项目名称:nBodyD3D12,代码行数:58,代码来源:ColorBuffer.cpp

示例2: Render

void ParticleEffects::Render( CommandContext& Context, const Camera& Camera, ColorBuffer& ColorTarget, DepthBuffer& DepthTarget, ColorBuffer& LinearDepth)
{
	if (!Enable || !s_InitComplete || ParticleEffectsActive.size() == 0)
		return;

	ScopedTimer _prof(L"Particle Render", Context);

	uint32_t Width = (uint32_t)ColorTarget.GetWidth();
	uint32_t Height = (uint32_t)ColorTarget.GetHeight();
	uint32_t BinsPerRow = 4 * DivideByMultiple(Width, 4 * BIN_SIZE_X);

	s_ChangesPerView.gViewProj = Camera.GetViewProjMatrix();  
	s_ChangesPerView.gInvView = Invert(Camera.GetViewMatrix());
	float HCot = Camera.GetProjMatrix().GetX().GetX();
	float VCot = Camera.GetProjMatrix().GetY().GetY();
	s_ChangesPerView.gVertCotangent = VCot;
	s_ChangesPerView.gAspectRatio = HCot / VCot;
	s_ChangesPerView.gRcpFarZ = 1.0f / Camera.GetFarClip();
	s_ChangesPerView.gInvertZ = Camera.GetNearClip() / (Camera.GetFarClip() - Camera.GetNearClip());
	s_ChangesPerView.gBufferWidth = (float)ColorTarget.GetWidth();
	s_ChangesPerView.gBufferHeight = (float)ColorTarget.GetHeight();
	s_ChangesPerView.gRcpBufferWidth = 1.0f / ColorTarget.GetWidth();
	s_ChangesPerView.gRcpBufferHeight = 1.0f / ColorTarget.GetHeight();
	s_ChangesPerView.gBinsPerRow = BinsPerRow;
	s_ChangesPerView.gTileRowPitch = BinsPerRow * TILES_PER_BIN_X;
	s_ChangesPerView.gTilesPerRow = DivideByMultiple(Width, TILE_SIZE);
	s_ChangesPerView.gTilesPerCol = DivideByMultiple(Height, TILE_SIZE);


	if (EnableTiledRendering)
	{
		ComputeContext& CompContext = Context.GetComputeContext();
		CompContext.ClearUAV(BinCounters[0]);
		CompContext.ClearUAV(BinCounters[1]);
		CompContext.SetRootSignature(RootSig);
		CompContext.SetDynamicConstantBufferView(1, sizeof(CBChangesPerView), &s_ChangesPerView);	
		RenderTiles(CompContext, ColorTarget, LinearDepth);
	}
	else
	{
		GraphicsContext& GrContext = Context.GetGraphicsContext();
		GrContext.SetRootSignature(RootSig);
		GrContext.SetDynamicConstantBufferView(1, sizeof(CBChangesPerView), &s_ChangesPerView);	
		RenderSprites(GrContext, ColorTarget, DepthTarget, LinearDepth);
	}

}
开发者ID:AhmedSaid,项目名称:DirectX-Graphics-Samples,代码行数:47,代码来源:ParticleEffectManager.cpp

示例3: ApplyTemporalAA

void TemporalAA::ApplyTemporalAA(CommandContext& BaseContext)
{
	ScopedTimer _prof(L"TAA", BaseContext);

	ComputeContext& Context = BaseContext.GetComputeContext();

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

	Context.SetRootSignature(MotionBlur::s_RootSignature);
	Context.SetConstants(0, 1.0f / Width, 1.0f / Height, (float)TemporalMaxLerp);

	uint32_t thisFrame = Graphics::GetFrameCount() & 1;
	uint32_t lastFrame = thisFrame ^ 1;

	if (!Enable)
	{
		BaseContext.TransitionResource(g_TemporalBuffer[thisFrame], D3D12_RESOURCE_STATE_RENDER_TARGET);
		BaseContext.TransitionResource(g_TemporalBuffer[lastFrame], D3D12_RESOURCE_STATE_RENDER_TARGET, true);
		BaseContext.GetGraphicsContext().ClearColor(g_TemporalBuffer[thisFrame]);
		BaseContext.GetGraphicsContext().ClearColor(g_TemporalBuffer[lastFrame]);
	}
	else
	{
		ColorBuffer& Dest = g_bTypedUAVLoadSupport_R11G11B10_FLOAT ? g_SceneColorBuffer : g_PostEffectsBuffer;

		Context.TransitionResource(Dest, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		Context.TransitionResource(g_ReprojectionBuffer, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
		Context.TransitionResource(g_TemporalBuffer[lastFrame], D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
		Context.TransitionResource(g_TemporalBuffer[thisFrame], D3D12_RESOURCE_STATE_UNORDERED_ACCESS);

		D3D12_CPU_DESCRIPTOR_HANDLE SRVs[] = { g_ReprojectionBuffer.GetSRV(), g_TemporalBuffer[lastFrame].GetSRV() };
		D3D12_CPU_DESCRIPTOR_HANDLE UAVs[] = { Dest.GetUAV(), g_TemporalBuffer[thisFrame].GetUAV() };

		Context.SetDynamicDescriptors(2, 0, _countof(UAVs), UAVs);
		Context.SetDynamicDescriptors(3, 0, _countof(SRVs), SRVs);
		Context.SetPipelineState(s_TemporalBlendCS);
		Context.Dispatch2D(Width, Height);

		Context.InsertUAVBarrier(Dest);
	}
}
开发者ID:derglas,项目名称:DX12,代码行数:42,代码来源:MotionBlur.cpp

示例4: Render

void ParticleEffects::Render( CommandContext& Context, const Camera& Camera, ColorBuffer& ColorTarget, DepthBuffer& DepthTarget, ColorBuffer& LinearDepth)
{
	if (!Enable || !s_InitComplete || ParticleEffectsActive.size() == 0)
		return;

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

	ASSERT(
		Width == DepthTarget.GetWidth() &&
		Height == DepthTarget.GetHeight() &&
		Width == LinearDepth.GetWidth() &&
		Height == LinearDepth.GetHeight(),
		"There is a mismatch in buffer dimensions for rendering particles"
	);

	ScopedTimer _prof(L"Particle Render", Context);

	uint32_t BinsPerRow = 4 * DivideByMultiple(Width, 4 * BIN_SIZE_X);

	s_ChangesPerView.gViewProj = Camera.GetViewProjMatrix();  
	s_ChangesPerView.gInvView = Invert(Camera.GetViewMatrix());
	float HCot = Camera.GetProjMatrix().GetX().GetX();
	float VCot = Camera.GetProjMatrix().GetY().GetY();
	s_ChangesPerView.gVertCotangent = VCot;
	s_ChangesPerView.gAspectRatio = HCot / VCot;
	s_ChangesPerView.gRcpFarZ = 1.0f / Camera.GetFarClip();
	s_ChangesPerView.gInvertZ = Camera.GetNearClip() / (Camera.GetFarClip() - Camera.GetNearClip());
	s_ChangesPerView.gBufferWidth = (float)Width;
	s_ChangesPerView.gBufferHeight = (float)Height;
	s_ChangesPerView.gRcpBufferWidth = 1.0f / Width;
	s_ChangesPerView.gRcpBufferHeight = 1.0f / Height;
	s_ChangesPerView.gBinsPerRow = BinsPerRow;
	s_ChangesPerView.gTileRowPitch = BinsPerRow * TILES_PER_BIN_X;
	s_ChangesPerView.gTilesPerRow = DivideByMultiple(Width, TILE_SIZE);
	s_ChangesPerView.gTilesPerCol = DivideByMultiple(Height, TILE_SIZE);

	// For now, UAV load support for R11G11B10 is required to read-modify-write the color buffer, but
	// the compositing could be deferred.
	WARN_ONCE_IF(EnableTiledRendering && !g_bTypedUAVLoadSupport_R11G11B10_FLOAT,
		"Unable to composite tiled particles without support for R11G11B10F UAV loads");
	EnableTiledRendering = EnableTiledRendering && g_bTypedUAVLoadSupport_R11G11B10_FLOAT;

	if (EnableTiledRendering)
	{
		ComputeContext& CompContext = Context.GetComputeContext();
		CompContext.TransitionResource(ColorTarget, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		CompContext.TransitionResource(BinCounters[0], D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		CompContext.TransitionResource(BinCounters[1], D3D12_RESOURCE_STATE_UNORDERED_ACCESS, true);

		CompContext.ClearUAV(BinCounters[0]);
		CompContext.ClearUAV(BinCounters[1]);
		CompContext.SetRootSignature(RootSig);
		CompContext.SetDynamicConstantBufferView(1, sizeof(CBChangesPerView), &s_ChangesPerView);

		RenderTiles(CompContext, ColorTarget, LinearDepth);

		CompContext.InsertUAVBarrier(ColorTarget);
	}
	else
	{
		GraphicsContext& GrContext = Context.GetGraphicsContext();
		GrContext.SetRootSignature(RootSig);
		GrContext.SetDynamicConstantBufferView(1, sizeof(CBChangesPerView), &s_ChangesPerView);	
		RenderSprites(GrContext, ColorTarget, DepthTarget, LinearDepth);
	}

}
开发者ID:Cynica1,项目名称:DirectX-Graphics-Samples,代码行数:68,代码来源:ParticleEffectManager.cpp

示例5: Render

void DepthOfField::Render( CommandContext& BaseContext, float NearClipDist, float FarClipDist )
{
	ScopedTimer _prof(L"Depth of Field", BaseContext);

	if (!g_bTypedUAVLoadSupport_R11G11B10_FLOAT)
	{
		WARN_ONCE_IF(!g_bTypedUAVLoadSupport_R11G11B10_FLOAT, "Unable to perform final pass of DoF without support for R11G11B10F UAV loads");
		Enable = false;
	}

	ComputeContext& Context = BaseContext.GetComputeContext();
	Context.SetRootSignature(s_RootSignature);

	uint32_t BufferWidth = (uint32_t)g_LinearDepth.GetWidth();
	uint32_t BufferHeight = (uint32_t)g_LinearDepth.GetHeight();
	uint32_t TiledWidth = (uint32_t)g_DoFTileClass[0].GetWidth();
	uint32_t TiledHeight = (uint32_t)g_DoFTileClass[0].GetHeight();

	__declspec(align(16)) struct DoFConstantBuffer
	{
		float FocalCenter, FocalSpread;
		float FocalMinZ, FocalMaxZ;
		float RcpBufferWidth, RcpBufferHeight;
		uint32_t BufferWidth, BufferHeight;
		int32_t HalfWidth, HalfHeight;
		uint32_t TiledWidth, TiledHeight;
		float RcpTiledWidth, RcpTiledHeight;
		uint32_t DebugState, DisablePreFilter;
		float FGRange, RcpFGRange, AntiSparkleFilterStrength;
	};
	DoFConstantBuffer cbuffer =
	{
		(float)FocalDepth, 1.0f / (float)FocalRange,
		(float)FocalDepth - (float)FocalRange, (float)FocalDepth + (float)FocalRange,
		1.0f / BufferWidth, 1.0f / BufferHeight,
		BufferWidth, BufferHeight,
		(int32_t)Math::DivideByMultiple(BufferWidth, 2), (int32_t)Math::DivideByMultiple(BufferHeight, 2),
		TiledWidth, TiledHeight,
		1.0f / TiledWidth, 1.0f / TiledHeight,
		(uint32_t)DebugMode, EnablePreFilter ? 0u : 1u,
		ForegroundRange / FarClipDist, FarClipDist / ForegroundRange, (float)AntiSparkleWeight
	};
	Context.SetDynamicConstantBufferView(0, sizeof(cbuffer), &cbuffer);

	{
		ScopedTimer _prof(L"DoF Tiling", Context);

		// Initial pass to discover max CoC and closest depth in 16x16 tiles
		Context.TransitionResource(g_LinearDepth, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
		Context.TransitionResource(g_DoFTileClass[0], D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		Context.SetPipelineState(s_DoFPass1CS);
		Context.SetDynamicDescriptor(1, 0, g_LinearDepth.GetSRV());
		Context.SetDynamicDescriptor(2, 0, g_DoFTileClass[0].GetUAV());
		Context.Dispatch2D(BufferWidth, BufferHeight, 16, 16);

		Context.ResetCounter(g_DoFWorkQueue);
		Context.ResetCounter(g_DoFFastQueue);
		Context.ResetCounter(g_DoFFixupQueue);

		// 3x3 filter to spread max CoC and closest depth to neighboring tiles
		Context.TransitionResource(g_DoFTileClass[0], D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
		Context.TransitionResource(g_DoFTileClass[1], D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		Context.TransitionResource(g_DoFWorkQueue, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		Context.TransitionResource(g_DoFFastQueue, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		Context.SetPipelineState(s_DoFTilePassCS);
		Context.SetDynamicDescriptor(1, 0, g_DoFTileClass[0].GetSRV());
		Context.SetDynamicDescriptor(2, 0, g_DoFTileClass[1].GetUAV());
		Context.SetDynamicDescriptor(2, 1, g_DoFWorkQueue.GetUAV());
		Context.SetDynamicDescriptor(2, 2, g_DoFFastQueue.GetUAV());
		Context.Dispatch2D(TiledWidth, TiledHeight);

		Context.TransitionResource(g_DoFTileClass[1], D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
		Context.TransitionResource(g_DoFFixupQueue, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		Context.SetPipelineState(s_DoFTilePassFixupCS);
		Context.SetDynamicDescriptor(1, 0, g_DoFTileClass[1].GetSRV());
		Context.SetDynamicDescriptor(2, 0, g_DoFFixupQueue.GetUAV());
		Context.Dispatch2D(TiledWidth, TiledHeight);

		Context.TransitionResource(g_DoFWorkQueue, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
		Context.CopyCounter(s_IndirectParameters, 0, g_DoFWorkQueue);

		Context.TransitionResource(g_DoFFastQueue, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
		Context.CopyCounter(s_IndirectParameters, 12, g_DoFFastQueue);

		Context.TransitionResource(g_DoFFixupQueue, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
		Context.CopyCounter(s_IndirectParameters, 24, g_DoFFixupQueue);

		Context.TransitionResource(s_IndirectParameters, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT);
	}

	{
		ScopedTimer _prof(L"DoF PreFilter", Context);

		if (ForceFast && !DebugMode)
			Context.SetPipelineState(s_DoFPreFilterFastCS);
		else
			Context.SetPipelineState(s_DoFPreFilterCS);
		Context.TransitionResource(g_SceneColorBuffer, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
		Context.TransitionResource(g_DoFPresortBuffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		Context.TransitionResource(g_DoFPrefilter, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
//.........这里部分代码省略.........
开发者ID:derglas,项目名称:DX12,代码行数:101,代码来源:DepthOfField.cpp

示例6: OnRender

// Render the scene.
void BoidsSimulation::OnRender( CommandContext& EngineContext )
{
	float deltaTime = Core::g_deltaTime > m_SimulationMaxDelta ? m_SimulationMaxDelta : (float)Core::g_deltaTime;
	m_SimulationTimer += deltaTime;
	uint16_t SimulationCnt = (uint16_t)(m_SimulationTimer/m_SimulationDelta);
	m_SimulationTimer -= SimulationCnt * m_SimulationDelta;

	if (m_ForcePerFrameSimulation) 
	{
		SimulationCnt = 1;
		m_SimulationCB.fDeltaT = deltaTime<=0? m_SimulationDelta : deltaTime;
		m_NeedUpdate = true;
	}
	else if( m_SimulationCB.fDeltaT != m_SimulationDelta)
	{
		m_SimulationCB.fDeltaT = m_SimulationDelta;
		m_NeedUpdate = true;
	}

	wchar_t timerName[32];
	if (m_PauseSimulation) SimulationCnt = 0;
	for (int i = 0; i < SimulationCnt; ++i)
	{
		swprintf( timerName, L"Simulation %d", i );
		ComputeContext& cptContext = m_SeperateContext? ComputeContext::Begin(L"Simulating"): EngineContext.GetComputeContext();
		{
			GPU_PROFILE( cptContext, timerName );
			cptContext.SetRootSignature( m_RootSignature );
			cptContext.SetPipelineState( m_ComputePSO );
			cptContext.TransitionResource( m_BoidsPosVelBuffer[m_OnStageBufIdx], D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE );
			cptContext.TransitionResource( m_BoidsPosVelBuffer[1 - m_OnStageBufIdx], D3D12_RESOURCE_STATE_UNORDERED_ACCESS );
			if (m_NeedUpdate)
			{
				m_NeedUpdate = false;
				memcpy( m_pConstantBuffer->DataPtr, &m_SimulationCB, sizeof( SimulationCB ) );
			}
			cptContext.SetConstantBuffer( 1, m_pConstantBuffer->GpuAddress );
			cptContext.SetBufferSRV( 2, m_BoidsPosVelBuffer[m_OnStageBufIdx] );
			cptContext.SetBufferUAV( 3, m_BoidsPosVelBuffer[1 - m_OnStageBufIdx] );
			cptContext.Dispatch1D( m_SimulationCB.uNumInstance, BLOCK_SIZE );
			m_OnStageBufIdx = 1 - m_OnStageBufIdx;
			cptContext.BeginResourceTransition( m_BoidsPosVelBuffer[1-m_OnStageBufIdx], D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE );
			cptContext.BeginResourceTransition( m_BoidsPosVelBuffer[m_OnStageBufIdx], D3D12_RESOURCE_STATE_UNORDERED_ACCESS );
		}
		if (m_SeperateContext) cptContext.Finish();
	}

	// Record all the commands we need to render the scene into the command list.
	XMMATRIX view = m_camera.View();
	XMMATRIX proj = m_camera.Projection();

	// [NOTE]: vectors matrix in shader is column major in default, but on CPU side they are in row major as default. 
	// So for saving cpu cycles to do transpose, we change the order of matrix multiplication here. Otherwise, 
	// We should do m_renderCB.mWorldViewProj = XMMatrixTranspose(XMMatricMultiply(proj,view))
	m_RenderCB.mWorldViewProj = XMMatrixMultiply( view, proj );

	GraphicsContext& gfxContext = m_SeperateContext? GraphicsContext::Begin(L"Rendering") : EngineContext.GetGraphicsContext();
	{
		GPU_PROFILE( gfxContext, L"Render" );
		gfxContext.TransitionResource( m_BoidsPosVelBuffer[m_OnStageBufIdx], D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE );
		gfxContext.ClearColor( Graphics::g_SceneColorBuffer );
		gfxContext.ClearDepth( Graphics::g_SceneDepthBuffer );
		gfxContext.SetRootSignature( m_RootSignature );
		gfxContext.SetPipelineState( m_GraphicsPSO );
		gfxContext.SetPrimitiveTopology( D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );
		if (m_NeedUpdate)
		{
			m_NeedUpdate = false;
			memcpy( m_pConstantBuffer->DataPtr, &m_SimulationCB, sizeof( SimulationCB ) );
		}
		gfxContext.SetConstantBuffer( 1, m_pConstantBuffer->GpuAddress );
		gfxContext.SetDynamicConstantBufferView( 0, sizeof( RenderCB ), (void*)(&m_RenderCB) );
		gfxContext.SetBufferSRV( 2, m_BoidsPosVelBuffer[m_OnStageBufIdx] );
		gfxContext.SetDynamicDescriptors( 4, 0, 1, &m_ColorMapTex.GetSRV() );
		gfxContext.SetRenderTargets( 1, &Graphics::g_SceneColorBuffer, &Graphics::g_SceneDepthBuffer );
		gfxContext.SetViewport( Graphics::g_DisplayPlaneViewPort );
		gfxContext.SetScisor( Graphics::g_DisplayPlaneScissorRect );
		gfxContext.SetVertexBuffer( 0, m_VertexBuffer.VertexBufferView() );
		gfxContext.DrawInstanced( _countof( FishMesh ), m_SimulationCB.uNumInstance );
		gfxContext.BeginResourceTransition( m_BoidsPosVelBuffer[m_OnStageBufIdx], D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE );
		gfxContext.BeginResourceTransition( m_BoidsPosVelBuffer[1 - m_OnStageBufIdx], D3D12_RESOURCE_STATE_UNORDERED_ACCESS );
	}
	if (m_SeperateContext) gfxContext.Finish();
}
开发者ID:pengliu916,项目名称:DX12Projects,代码行数:85,代码来源:BoidsSimulation.cpp

示例7: RenderObjectBlur

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);
	}
}
开发者ID:derglas,项目名称:DX12,代码行数:61,代码来源:MotionBlur.cpp

示例8: RenderCameraBlur

void MotionBlur::RenderCameraBlur( CommandContext& BaseContext, const Matrix4& reprojectionMatrix, float nearClip, float farClip, bool UseLinearZ)
{
	ScopedTimer _prof(L"MotionBlur", BaseContext);

	if (!Enable && !TemporalAA::Enable)
		return;

	ComputeContext& Context = BaseContext.GetComputeContext();

	Context.SetRootSignature(s_RootSignature);

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

	float RcpHalfDimX = 2.0f / Width;
	float RcpHalfDimY = 2.0f / Height;
	float RcpZMagic = nearClip / (farClip - nearClip);

	Matrix4 preMult = Matrix4(
		Vector4( RcpHalfDimX, 0.0f, 0.0f, 0.0f ),
		Vector4( 0.0f, -RcpHalfDimY, 0.0f, 0.0f),
		Vector4( 0.0f, 0.0f, UseLinearZ ? RcpZMagic : 1.0f, 0.0f ),
		Vector4( -1.0f, 1.0f, UseLinearZ ? -RcpZMagic : 0.0f, 1.0f )
	);

	Matrix4 postMult = Matrix4(
		Vector4( 1.0f / RcpHalfDimX, 0.0f, 0.0f, 0.0f ),
		Vector4( 0.0f, -1.0f / RcpHalfDimY, 0.0f, 0.0f ),
		Vector4( 0.0f, 0.0f, 1.0f, 0.0f ),
		Vector4( 1.0f / RcpHalfDimX, 1.0f / RcpHalfDimY, 0.0f, 1.0f ) );

	struct PrePassCB
	{
		Matrix4 CurToPrevXForm;
		float RcpBufferWidth;
		float RcpBufferHeight;
		float MaxTemporalBlend;
	} params;

	params.CurToPrevXForm = postMult * reprojectionMatrix * preMult;
	params.RcpBufferWidth = 1.0f / Width;
	params.RcpBufferHeight = 1.0f / Height;
	params.MaxTemporalBlend = TemporalMaxLerp;

	Context.SetDynamicConstantBufferView(1, sizeof(PrePassCB), &params);
	Context.TransitionResource(g_VelocityBuffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);

	if (UseLinearZ)
		Context.TransitionResource(g_LinearDepth, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
	else
		Context.TransitionResource(g_SceneDepthBuffer, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);

	if (Enable)
	{
		Context.TransitionResource(g_MotionPrepBuffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
		Context.TransitionResource(g_SceneColorBuffer, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);

		Context.SetPipelineState(s_CameraMotionBlurPrePassCS[UseLinearZ ? 1 : 0]);
		Context.SetDynamicDescriptor(3, 0, g_SceneColorBuffer.GetSRV());
		Context.SetDynamicDescriptor(3, 1, UseLinearZ ? g_LinearDepth.GetSRV() : g_SceneDepthBuffer.GetDepthSRV());
		Context.SetDynamicDescriptor(2, 0, g_MotionPrepBuffer.GetUAV());
		Context.SetDynamicDescriptor(2, 1, g_VelocityBuffer.GetUAV());
		Context.SetDynamicDescriptor(2, 2, g_ReprojectionBuffer.GetUAV());
		Context.Dispatch2D(g_MotionPrepBuffer.GetWidth(), g_MotionPrepBuffer.GetHeight());

		if (g_bTypedUAVLoadSupport_R11G11B10_FLOAT)
		{
			Context.SetPipelineState(s_MotionBlurFinalPassCS);
			Context.SetConstants(0, 1.0f / Width, 1.0f / Height);

			Context.TransitionResource(g_SceneColorBuffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
			Context.TransitionResource(g_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, g_VelocityBuffer.GetSRV());
			Context.SetDynamicDescriptor(3, 1, g_MotionPrepBuffer.GetSRV());

			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);
		}
	}
	else
	{
		Context.SetPipelineState(s_CameraVelocityCS[UseLinearZ ? 1 : 0]);
//.........这里部分代码省略.........
开发者ID:derglas,项目名称:DX12,代码行数:101,代码来源:MotionBlur.cpp


注:本文中的CommandContext::GetComputeContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。