本文整理汇总了C++中CommandContext::GetGraphicsContext方法的典型用法代码示例。如果您正苦于以下问题:C++ CommandContext::GetGraphicsContext方法的具体用法?C++ CommandContext::GetGraphicsContext怎么用?C++ CommandContext::GetGraphicsContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandContext
的用法示例。
在下文中一共展示了CommandContext::GetGraphicsContext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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();
}
示例5: 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);
}
}
示例6: 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), ¶ms);
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]);
//.........这里部分代码省略.........