/// <summary>
            /// Submit the encoded batches as indirect draw calls
            /// </summary>
            /// <param name="cl"></param>
            public unsafe void SubmitBatches(CommandList cl, SceneRenderPipeline pipeline)
            {
                // If renderset is -1, no work has actually been uploaded to the gpu yet
                if (_renderSet == -1)
                {
                    return;
                }

                // Dispatch indirect calls for each batch
                uint c = _batchCount[_renderSet] > 0 ? _batchCount[_renderSet] - 1 : 0;

                for (int i = 0; i < _batchCount[_renderSet]; i++)
                {
                    cl.SetPipeline(_batches[MAX_BATCH * _renderSet + i]._pipeline);
                    pipeline.BindResources(cl);
                    cl.SetGraphicsResourceSet(1, _batches[MAX_BATCH * _renderSet + i]._objectRS);
                    GlobalTexturePool.BindTexturePool(cl, 2);
                    GlobalCubeTexturePool.BindTexturePool(cl, 3);
                    MaterialBufferAllocator.BindAsResourceSet(cl, 4);
                    cl.SetGraphicsResourceSet(5, SamplerSet.SamplersSet);

                    if (!GeometryBufferAllocator.BindAsVertexBuffer(cl, _batches[MAX_BATCH * _renderSet + i]._bufferIndex))
                    {
                        continue;
                    }
                    if (!GeometryBufferAllocator.BindAsIndexBuffer(cl, _batches[MAX_BATCH * _renderSet + i]._bufferIndex, _batches[MAX_BATCH * _renderSet + i]._indexFormat))
                    {
                        continue;
                    }
                    uint count = _indirectDrawCount[_renderSet] - _batches[MAX_BATCH * _renderSet + i]._batchStart;
                    if (i < _batchCount[_renderSet] - 1)
                    {
                        count = _batches[MAX_BATCH * _renderSet + i + 1]._batchStart - _batches[MAX_BATCH * _renderSet + i]._batchStart;
                    }

                    if (UseDirect)
                    {
                        uint start = _batches[MAX_BATCH * _renderSet + i]._batchStart;
                        for (uint d = start; d < start + count; d++)
                        {
                            cl.DrawIndexed(_directBuffer[d].IndexCount, _directBuffer[d].InstanceCount, _directBuffer[d].FirstIndex,
                                           _directBuffer[d].VertexOffset, _directBuffer[d].FirstInstance);
                        }
                    }
                    else
                    {
                        cl.DrawIndexedIndirect(_indirectBuffer, _batches[MAX_BATCH * _renderSet + i]._batchStart * 20, count, 20);
                    }
                }
            }
Exemple #2
0
 public void DrawIndexed(CommandList commandList, uint offset, uint count, uint stride)
 {
     if (UseFallback)
     {
         var offs = offset / ArgSize;
         for (var i = 0; i < count; i++)
         {
             var arg = _arguments[i + offs];
             commandList.DrawIndexed(arg.IndexCount, arg.InstanceCount, arg.FirstIndex, arg.VertexOffset, arg.FirstInstance);
         }
     }
     else
     {
         commandList.DrawIndexedIndirect(_deviceBuffer, offset, count, stride);
     }
 }