MCPcopy Create free account
hub / github.com/carbonengine/trinity / Commit

Method Commit

trinityal/dx12/util/DescriptorStateCacheDx12.cpp:189–251  ·  view source on GitHub ↗

Apply state */

Source from the content-addressed store, hash-verified

187
188/** Apply state */
189void DescriptorStateCache::Commit( ID3D12GraphicsCommandList* commandList, ID3D12DescriptorHeap* globalSrvUavHeap, ID3D12DescriptorHeap* globalSamplerHeap, const TrinityALImpl::Tr2RootSignatureAL* rootSignature )
190{
191 bool rootSignatureChanged = rootSignature->m_rootSignature != m_rootSignature;
192
193 // If we are changing the root signature or rebinding heaps, we must rebind everything
194 bool forceSet = rootSignatureChanged || m_heapsDirty || m_globalSrvUavHeap != globalSrvUavHeap || m_globalSamplerHeap != globalSamplerHeap;
195
196 SetHeaps( commandList, globalSrvUavHeap, globalSamplerHeap );
197
198 bool mustBindSrvUav = m_srvUavDirty || forceSet;
199 bool mustBindSampler = m_samplerDirty || forceSet;
200
201 auto setRootDescriptorTable = rootSignature->m_isCompute ? &ID3D12GraphicsCommandList::SetComputeRootDescriptorTable : &ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable;
202
203 // Check if the SRV/UAV table *can* be bound, *must* be bound and isn't already bound
204 if( mustBindSrvUav )
205 {
206 for( uint32_t i = 0; i < rootSignature->m_srvUavParameterCount; ++i )
207 {
208 uint32_t index = rootSignature->m_srvUavParameterOffset + i;
209 auto handle = m_srvUav[index]->GetHandleGPU();
210 if( forceSet || !m_parameterSlots[index].IsValidSRV( handle ) )
211 {
212 m_parameterSlots[index].SetSRV( handle );
213 ( commandList->*setRootDescriptorTable )( index, handle );
214 }
215 }
216 }
217
218 if( mustBindSampler )
219 {
220 for( uint32_t i = 0; i < rootSignature->m_samplerParameterCount; ++i )
221 {
222 uint32_t index = rootSignature->m_samplerParameterOffset + i;
223 auto handle = m_sampler[index]->GetHandleGPU();
224 if( forceSet || !m_parameterSlots[index].IsValidSampler( handle ) )
225 {
226 m_parameterSlots[index].SetSampler( handle );
227 ( commandList->*setRootDescriptorTable )( index, handle );
228 }
229 }
230 }
231
232 D3D12_GPU_VIRTUAL_ADDRESS nullCbv = m_primaryContext->m_nullCB.GetGpuView();
233 auto setConstantBufferView = rootSignature->m_isCompute ? &ID3D12GraphicsCommandList::SetComputeRootConstantBufferView : &ID3D12GraphicsCommandList::SetGraphicsRootConstantBufferView;
234 for( auto it = begin( rootSignature->m_cbRegisters ); it != end( rootSignature->m_cbRegisters ); ++it )
235 {
236 D3D12_GPU_VIRTUAL_ADDRESS address = m_cbv[it->stage][it->index];
237 if( rootSignatureChanged || !m_parameterSlots[it->parameter].IsValidCBV( address ) )
238 {
239 m_parameterSlots[it->parameter].SetCBV( address );
240 ( commandList->*setConstantBufferView )( it->parameter, address != 0 ? address : nullCbv );
241 }
242 }
243
244 // Clear dirty flags
245 m_srvUavDirty = false;
246 m_samplerDirty = false;

Callers 15

GetBatchesMethod · 0.45
GetBatchImplMethod · 0.45
GetBatchesImplMethod · 0.45
GetBatchesForAreaMethod · 0.45
GetBatchesMethod · 0.45
GetBatchesImplMethod · 0.45
GetBatchesFromMeshMethod · 0.45
GetBatchesMethod · 0.45
GetBatchesImplMethod · 0.45
GetBatchesMethod · 0.45
GetBatchesMethod · 0.45
GetPickingBatchesMethod · 0.45

Calls 10

IsValidSRVMethod · 0.80
SetSRVMethod · 0.80
IsValidSamplerMethod · 0.80
IsValidCBVMethod · 0.80
SetCBVMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
GetHandleGPUMethod · 0.45
SetSamplerMethod · 0.45
GetGpuViewMethod · 0.45

Tested by

no test coverage detected