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


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

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


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

示例1: FillLightGrid

void Lighting::FillLightGrid(GraphicsContext& gfxContext, const Camera& camera)
{
	ScopedTimer _prof(L"FillLightGrid", gfxContext);

	ComputeContext& Context = gfxContext.GetComputeContext();

	Context.SetRootSignature(m_FillLightRootSig);

	switch ((int)LightGridDim)
	{
	case  8: Context.SetPipelineState(m_FillLightGridCS_8 ); break;
	case 16: Context.SetPipelineState(m_FillLightGridCS_16); break;
	case 24: Context.SetPipelineState(m_FillLightGridCS_24); break;
	case 32: Context.SetPipelineState(m_FillLightGridCS_32); break;
	default: ASSERT(false); break;
	}

	Context.TransitionResource(m_LightBuffer, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
	Context.TransitionResource(g_LinearDepth, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
	Context.TransitionResource(g_SceneDepthBuffer, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
	Context.TransitionResource(m_LightGrid, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
	Context.TransitionResource(m_LightGridBitMask, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);

	Context.SetDynamicDescriptor(1, 0, m_LightBuffer.GetSRV());
	Context.SetDynamicDescriptor(1, 1, g_LinearDepth.GetSRV());
	//Context.SetDynamicDescriptor(1, 1, g_SceneDepthBuffer.GetDepthSRV());
	Context.SetDynamicDescriptor(2, 0, m_LightGrid.GetUAV());
	Context.SetDynamicDescriptor(2, 1, m_LightGridBitMask.GetUAV());

	// todo: assumes 1920x1080 resolution
	uint32_t tileCountX = Math::DivideByMultiple(g_SceneColorBuffer.GetWidth(), LightGridDim);
	uint32_t tileCountY = Math::DivideByMultiple(g_SceneColorBuffer.GetHeight(), LightGridDim);

	float FarClipDist = camera.GetFarClip();
	float NearClipDist = camera.GetNearClip();
	const float RcpZMagic = NearClipDist / (FarClipDist - NearClipDist);

	struct CSConstants
	{
		uint32_t ViewportWidth, ViewportHeight;
		float InvTileDim;
		float RcpZMagic;
		uint32_t TileCount;
		Matrix4 ViewProjMatrix;
	} csConstants;
	// todo: assumes 1920x1080 resolution
	csConstants.ViewportWidth = g_SceneColorBuffer.GetWidth();
	csConstants.ViewportHeight = g_SceneColorBuffer.GetHeight();
	csConstants.InvTileDim = 1.0f / LightGridDim;
	csConstants.RcpZMagic = RcpZMagic;
	csConstants.TileCount = tileCountX;
	csConstants.ViewProjMatrix = camera.GetViewProjMatrix();
	Context.SetDynamicConstantBufferView(0, sizeof(CSConstants), &csConstants);

	Context.Dispatch(tileCountX, tileCountY, 1);

	Context.TransitionResource(m_LightGrid, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
	Context.TransitionResource(m_LightGridBitMask, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
}
开发者ID:Anklor,项目名称:DirectX-Graphics-Samples,代码行数:59,代码来源:ForwardPlusLighting.cpp


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