コード例 #1
0
        public void ExecuteAll(OpenGLCommandExecutor executor)
        {
            int currentBlockIndex   = 0;
            EntryStorageBlock block = _blocks[currentBlockIndex];
            uint currentOffset      = 0;

            for (uint i = 0; i < _totalEntries; i++)
            {
                if (currentOffset == block.TotalSize)
                {
                    currentBlockIndex += 1;
                    block              = _blocks[currentBlockIndex];
                    currentOffset      = 0;
                }

                uint id = Unsafe.Read <byte>(block.BasePtr + currentOffset);
                if (id == 0)
                {
                    currentBlockIndex += 1;
                    block              = _blocks[currentBlockIndex];
                    currentOffset      = 0;
                    id = Unsafe.Read <byte>(block.BasePtr + currentOffset);
                }

                Debug.Assert(id != 0);
                currentOffset += 1;
                byte *entryBasePtr = block.BasePtr + currentOffset;
                switch (id)
                {
                case BeginEntryID:
                    executor.Begin();
                    currentOffset += BeginEntrySize;
                    break;

                case ClearColorTargetID:
                    ref NoAllocClearColorTargetEntry ccte = ref Unsafe.AsRef <NoAllocClearColorTargetEntry>(entryBasePtr);
                    executor.ClearColorTarget(ccte.Index, ccte.ClearColor);
                    currentOffset += ClearColorTargetEntrySize;
                    break;

                case ClearDepthTargetID:
                    ref NoAllocClearDepthTargetEntry cdte = ref Unsafe.AsRef <NoAllocClearDepthTargetEntry>(entryBasePtr);
                    executor.ClearDepthStencil(cdte.Depth, cdte.Stencil);
                    currentOffset += ClearDepthTargetEntrySize;
                    break;

                case DrawEntryID:
                    ref NoAllocDrawEntry de = ref Unsafe.AsRef <NoAllocDrawEntry>(entryBasePtr);
                    executor.Draw(de.VertexCount, de.InstanceCount, de.VertexStart, de.InstanceStart);
                    currentOffset += DrawEntrySize;
                    break;

                case DrawIndexedEntryID:
                    ref NoAllocDrawIndexedEntry die = ref Unsafe.AsRef <NoAllocDrawIndexedEntry>(entryBasePtr);
                    executor.DrawIndexed(die.IndexCount, die.InstanceCount, die.IndexStart, die.VertexOffset, die.InstanceCount);
                    currentOffset += DrawIndexedEntrySize;
                    break;

                case DrawIndirectEntryID:
                    ref NoAllocDrawIndirectEntry drawIndirectEntry = ref Unsafe.AsRef <NoAllocDrawIndirectEntry>(entryBasePtr);
                    executor.DrawIndirect(
                        drawIndirectEntry.IndirectBuffer.Get(_resourceList),
                        drawIndirectEntry.Offset,
                        drawIndirectEntry.DrawCount,
                        drawIndirectEntry.Stride);
                    currentOffset += DrawIndirectEntrySize;
                    break;

                case DrawIndexedIndirectEntryID:
                    ref NoAllocDrawIndexedIndirectEntry diie = ref Unsafe.AsRef <NoAllocDrawIndexedIndirectEntry>(entryBasePtr);
                    executor.DrawIndexedIndirect(diie.IndirectBuffer.Get(_resourceList), diie.Offset, diie.DrawCount, diie.Stride);
                    currentOffset += DrawIndexedIndirectEntrySize;
                    break;

                case DispatchEntryID:
                    ref NoAllocDispatchEntry dispatchEntry = ref Unsafe.AsRef <NoAllocDispatchEntry>(entryBasePtr);
                    executor.Dispatch(dispatchEntry.GroupCountX, dispatchEntry.GroupCountY, dispatchEntry.GroupCountZ);
                    currentOffset += DispatchEntrySize;
                    break;

                case DispatchIndirectEntryID:
                    ref NoAllocDispatchIndirectEntry dispatchIndir = ref Unsafe.AsRef <NoAllocDispatchIndirectEntry>(entryBasePtr);
                    executor.DispatchIndirect(dispatchIndir.IndirectBuffer.Get(_resourceList), dispatchIndir.Offset);
                    currentOffset += DispatchIndirectEntrySize;
                    break;

                case EndEntryID:
                    executor.End();
                    currentOffset += EndEntrySize;
                    break;

                case SetFramebufferEntryID:
                    ref NoAllocSetFramebufferEntry sfbe = ref Unsafe.AsRef <NoAllocSetFramebufferEntry>(entryBasePtr);
                    executor.SetFramebuffer(sfbe.Framebuffer.Get(_resourceList));
                    currentOffset += SetFramebufferEntrySize;
                    break;

                case SetIndexBufferEntryID:
                    ref NoAllocSetIndexBufferEntry sibe = ref Unsafe.AsRef <NoAllocSetIndexBufferEntry>(entryBasePtr);
                    executor.SetIndexBuffer(sibe.Buffer.Get(_resourceList), sibe.Format);
                    currentOffset += SetIndexBufferEntrySize;
                    break;

                case SetPipelineEntryID:
                    ref NoAllocSetPipelineEntry spe = ref Unsafe.AsRef <NoAllocSetPipelineEntry>(entryBasePtr);
                    executor.SetPipeline(spe.Pipeline.Get(_resourceList));
                    currentOffset += SetPipelineEntrySize;
                    break;

                case SetGraphicsResourceSetEntryID:
                    ref NoAllocSetGraphicsResourceSetEntry sgrse = ref Unsafe.AsRef <NoAllocSetGraphicsResourceSetEntry>(entryBasePtr);
                    executor.SetGraphicsResourceSet(sgrse.Slot, sgrse.ResourceSet.Get(_resourceList));
                    currentOffset += SetGraphicsResourceSetEntrySize;
                    break;

                case SetComputeResourceSetEntryID:
                    ref NoAllocSetComputeResourceSetEntry scrse = ref Unsafe.AsRef <NoAllocSetComputeResourceSetEntry>(entryBasePtr);
                    executor.SetComputeResourceSet(scrse.Slot, scrse.ResourceSet.Get(_resourceList));
                    currentOffset += SetComputeResourceSetEntrySize;
                    break;

                case SetScissorRectEntryID:
                    ref NoAllocSetScissorRectEntry ssre = ref Unsafe.AsRef <NoAllocSetScissorRectEntry>(entryBasePtr);
                    executor.SetScissorRect(ssre.Index, ssre.X, ssre.Y, ssre.Width, ssre.Height);
                    currentOffset += SetScissorRectEntrySize;
                    break;

                case SetVertexBufferEntryID:
                    ref NoAllocSetVertexBufferEntry svbe = ref Unsafe.AsRef <NoAllocSetVertexBufferEntry>(entryBasePtr);
                    executor.SetVertexBuffer(svbe.Index, svbe.Buffer.Get(_resourceList));
                    currentOffset += SetVertexBufferEntrySize;
                    break;

                case SetViewportEntryID:
                    ref NoAllocSetViewportEntry svpe = ref Unsafe.AsRef <NoAllocSetViewportEntry>(entryBasePtr);
                    executor.SetViewport(svpe.Index, ref svpe.Viewport);
                    currentOffset += SetViewportEntrySize;
                    break;

                case UpdateBufferEntryID:
                    ref NoAllocUpdateBufferEntry ube = ref Unsafe.AsRef <NoAllocUpdateBufferEntry>(entryBasePtr);
                    fixed(byte *dataPtr = &ube.StagingBlock.Get(_resourceList)[0])
                    {
                        executor.UpdateBuffer(
                            ube.Buffer.Get(_resourceList),
                            ube.BufferOffsetInBytes,
                            (IntPtr)dataPtr, ube.StagingBlockSize);
                    }

                    currentOffset += UpdateBufferEntrySize;
                    break;

                case CopyBufferEntryID:
                    ref NoAllocCopyBufferEntry cbe = ref Unsafe.AsRef <NoAllocCopyBufferEntry>(entryBasePtr);
                    executor.CopyBuffer(
                        cbe.Source.Get(_resourceList),
                        cbe.SourceOffset,
                        cbe.Destination.Get(_resourceList),
                        cbe.DestinationOffset,
                        cbe.SizeInBytes);
                    currentOffset += CopyBufferEntrySize;
                    break;

                case CopyTextureEntryID:
                    ref NoAllocCopyTextureEntry cte = ref Unsafe.AsRef <NoAllocCopyTextureEntry>(entryBasePtr);
                    executor.CopyTexture(
                        cte.Source.Get(_resourceList),
                        cte.SrcX, cte.SrcY, cte.SrcZ,
                        cte.SrcMipLevel,
                        cte.SrcBaseArrayLayer,
                        cte.Destination.Get(_resourceList),
                        cte.DstX, cte.DstY, cte.DstZ,
                        cte.DstMipLevel,
                        cte.DstBaseArrayLayer,
                        cte.Width, cte.Height, cte.Depth,
                        cte.LayerCount);
                    currentOffset += CopyTextureEntrySize;
                    break;

                case ResolveTextureEntryID:
                    ref NoAllocResolveTextureEntry rte = ref Unsafe.AsRef <NoAllocResolveTextureEntry>(entryBasePtr);
                    executor.ResolveTexture(rte.Source.Get(_resourceList), rte.Destination.Get(_resourceList));
                    currentOffset += ResolveTextureEntrySize;
                    break;

                case GenerateMipmapsEntryID:
                    ref NoAllocGenerateMipmapsEntry gme = ref Unsafe.AsRef <NoAllocGenerateMipmapsEntry>(entryBasePtr);
                    executor.GenerateMipmaps(gme.Texture.Get(_resourceList));
                    currentOffset += GenerateMipmapsEntrySize;
                    break;

                default:
                    throw new InvalidOperationException("Invalid entry ID: " + id);
                }
            }
        }
コード例 #2
0
        public void DrawIndexed(uint indexCount, uint instanceCount, uint indexStart, int vertexOffset, uint instanceStart)
        {
            NoAllocDrawIndexedEntry entry = new NoAllocDrawIndexedEntry(indexCount, instanceCount, indexStart, vertexOffset, instanceStart);

            AddEntry(DrawIndexedEntryID, ref entry);
        }