public unsafe void Update(GraphicsDevice graphicsDevice, ResourceGroupAllocator resourceGroupAllocator, ParameterCollection parameters)
        {
            // Instantiate descriptor sets
            for (int i = 0; i < resourceGroups.Length; ++i)
            {
                var resourceGroupLayout = updaterLayout.ResourceGroupLayouts[i];
                if (resourceGroupLayout != null)
                    resourceGroupAllocator.PrepareResourceGroup(resourceGroupLayout, BufferPoolAllocationType.UsedOnce, resourceGroups[i]);
            }

            // Set resources
            var layouts = updaterLayout.Layouts;
            var descriptorStartSlot = 0;
            var bufferStartOffset = 0;
            for (int layoutIndex = 0; layoutIndex < layouts.Length; layoutIndex++)
            {
                var resourceGroup = resourceGroups[layoutIndex];
                var descriptorSet = resourceGroup.DescriptorSet;
                var layout = layouts[layoutIndex];
                if (layout == null)
                    continue;

                if (parameters.ObjectValues != null)
                {
                    for (int resourceSlot = 0; resourceSlot < layout.ElementCount; ++resourceSlot)
                    {
                        descriptorSet.SetValue(resourceSlot, parameters.ObjectValues[descriptorStartSlot + resourceSlot]);
                    }
                }

                descriptorStartSlot += layout.ElementCount;

                if (parameters.DataValues != null && resourceGroup.ConstantBuffer.Size > 0)
                {
                    fixed (byte* dataValues = parameters.DataValues)
                        Utilities.CopyMemory(resourceGroup.ConstantBuffer.Data, (IntPtr)dataValues + bufferStartOffset, resourceGroup.ConstantBuffer.Size);
                    bufferStartOffset += resourceGroup.ConstantBuffer.Size;
                }
            }
        }
示例#2
0
 public GraphicsContext(GraphicsDevice graphicsDevice, GraphicsResourceAllocator allocator = null, CommandList commandList = null)
 {
     CommandList            = commandList ?? graphicsDevice.InternalMainCommandList ?? CommandList.New(graphicsDevice).DisposeBy(graphicsDevice);
     Allocator              = allocator ?? new GraphicsResourceAllocator(graphicsDevice).DisposeBy(graphicsDevice);
     ResourceGroupAllocator = new ResourceGroupAllocator(Allocator, CommandList).DisposeBy(graphicsDevice);
 }
 public GraphicsContext(GraphicsDevice graphicsDevice, GraphicsResourceAllocator allocator = null, CommandList commandList = null)
 {
     CommandList = commandList ?? graphicsDevice.InternalMainCommandList ?? CommandList.New(graphicsDevice);
     Allocator = allocator ?? new GraphicsResourceAllocator(graphicsDevice).DisposeBy(graphicsDevice);
     ResourceGroupAllocator = new ResourceGroupAllocator(Allocator, CommandList);
 }