Пример #1
0
        private void CreateDescriptorSet()
        {
            this.descriptorSet = this.device.AllocateDescriptorSets(new DescriptorSetAllocateInfo
            {
                DescriptorPool = this.descriptorPool,
                SetLayouts     = new[]
                {
                    this.descriptorSetLayout
                }
            }).Single();

            this.device.UpdateDescriptorSets(
                new WriteDescriptorSet
            {
                BufferInfo = new[]
                {
                    new DescriptorBufferInfo
                    {
                        Buffer = this.uniformBuffer,
                        Offset = 0,
                        Range  = MemUtil.SizeOf <UniformBufferObject>()
                    }
                },
                DestinationSet          = this.descriptorSet,
                DestinationBinding      = 0,
                DestinationArrayElement = 0,
                DescriptorType          = DescriptorType.UniformBuffer
            }, null);
        }
Пример #2
0
        private void CreateUniformBuffer()
        {
            uint bufferSize = MemUtil.SizeOf <UniformBufferObject>();

            this.CreateBuffer(bufferSize, BufferUsageFlags.TransferSource, MemoryPropertyFlags.HostVisible | MemoryPropertyFlags.HostCoherent, out this.uniformStagingBuffer, out this.uniformStagingBufferMemory);
            this.CreateBuffer(bufferSize, BufferUsageFlags.TransferDestination | BufferUsageFlags.UniformBuffer, MemoryPropertyFlags.DeviceLocal, out this.uniformBuffer, out this.uniformBufferMemory);
        }
Пример #3
0
        private void UpdateUniformBuffer()
        {
            long currentTimestamp = Stopwatch.GetTimestamp();

            float totalTime = (currentTimestamp - this.initialTimestamp) / (float)Stopwatch.Frequency;

            UniformBufferObject ubo = new UniformBufferObject
            {
                Model = mat4.Rotate((float)Math.Sin(totalTime) * (float)Math.PI, vec3.UnitZ),
                View  = mat4.LookAt(new vec3(1), vec3.Zero, vec3.UnitZ),
                Proj  = mat4.Perspective((float)Math.PI / 4f, this.swapChainExtent.Width / (float)this.swapChainExtent.Height, 0.1f, 10)
            };

            ubo.Proj[1, 1] *= -1;

            uint uboSize = MemUtil.SizeOf <UniformBufferObject>();

            IntPtr memoryBuffer = IntPtr.Zero;

            this.uniformStagingBufferMemory.MapMemory(0, uboSize, MemoryMapFlags.None, ref memoryBuffer);

            Marshal.StructureToPtr(ubo, memoryBuffer, false);

            this.uniformStagingBufferMemory.UnmapMemory();

            this.CopyBuffer(this.uniformStagingBuffer, this.uniformBuffer, uboSize);
        }
Пример #4
0
        private void CreateIndexBuffer()
        {
            ulong        bufferSize = MemUtil.SizeOf <ushort>() * (uint)this.indices.Length;
            Buffer       stagingBuffer;
            DeviceMemory stagingBufferMemory;

            this.CreateBuffer(bufferSize, BufferUsageFlags.TransferSource, MemoryPropertyFlags.HostVisible | MemoryPropertyFlags.HostCoherent, out stagingBuffer, out stagingBufferMemory);

            IntPtr memoryBuffer = IntPtr.Zero;

            stagingBufferMemory.MapMemory(0, bufferSize, MemoryMapFlags.None, ref memoryBuffer);

            MemUtil.WriteToPtr(memoryBuffer, indices, 0, indices.Length);

            stagingBufferMemory.UnmapMemory();

            this.CreateBuffer(bufferSize, BufferUsageFlags.TransferDestination | BufferUsageFlags.IndexBuffer, MemoryPropertyFlags.DeviceLocal, out this.indexBuffer, out this.indexBufferMemory);

            this.CopyBuffer(stagingBuffer, this.indexBuffer, bufferSize);

            stagingBuffer.Dispose();
            this.device.FreeMemory(stagingBufferMemory);
        }
Пример #5
0
 /// <summary>
 /// -
 /// </summary>
 public void RegisterObjects(ArrayProxy <ObjectTableEntry> objectTableEntries, ArrayProxy <uint> objectIndices)
 {
     unsafe
     {
         try
         {
             var                commandDelegate = this.commandCache.GetCommandDelegate <Interop.vkRegisterObjectsNVX>("vkRegisterObjectsNVX", "device");
             Result             commandResult;
             GCHandle           objectTableEntriesHandle           = default(GCHandle);
             ObjectTableEntry * marshalledObjectTableEntries       = null;
             ObjectTableEntry **doubleMarshalledObjectTableEntries = null;
             if (objectTableEntries.Contents != ProxyContents.Null)
             {
                 if (objectTableEntries.Contents == ProxyContents.Single)
                 {
                     ObjectTableEntry *dataPointer = stackalloc ObjectTableEntry[1];
                     *dataPointer = objectTableEntries.GetSingleValue();
                     marshalledObjectTableEntries       = dataPointer;
                     doubleMarshalledObjectTableEntries = &marshalledObjectTableEntries;
                 }
                 else
                 {
                     var arrayValue = objectTableEntries.GetArrayValue();
                     objectTableEntriesHandle     = GCHandle.Alloc(arrayValue.Array, GCHandleType.Pinned);
                     marshalledObjectTableEntries = (ObjectTableEntry *)(objectTableEntriesHandle.AddrOfPinnedObject() + (int)(MemUtil.SizeOf <ObjectTableEntry>() * arrayValue.Offset)).ToPointer();
                     ObjectTableEntry **dataPointer = stackalloc ObjectTableEntry *[objectTableEntries.Length];
                     doubleMarshalledObjectTableEntries = dataPointer;
                     for (int marshalIndex = 0; marshalIndex < objectTableEntries.Length; marshalIndex++)
                     {
                         doubleMarshalledObjectTableEntries[marshalIndex] = &marshalledObjectTableEntries[marshalIndex];
                     }
                 }
             }
             else
             {
                 marshalledObjectTableEntries = null;
             }
             GCHandle objectIndicesHandle     = default(GCHandle);
             uint *   marshalledObjectIndices = null;
             if (objectIndices.Contents != ProxyContents.Null)
             {
                 if (objectIndices.Contents == ProxyContents.Single)
                 {
                     uint *dataPointer = stackalloc uint[1];
                     *     dataPointer = objectIndices.GetSingleValue();
                     marshalledObjectIndices = dataPointer;
                 }
                 else
                 {
                     var arrayValue = objectIndices.GetArrayValue();
                     objectIndicesHandle     = GCHandle.Alloc(arrayValue.Array, GCHandleType.Pinned);
                     marshalledObjectIndices = (uint *)(objectIndicesHandle.AddrOfPinnedObject() + (int)(MemUtil.SizeOf <uint>() * arrayValue.Offset)).ToPointer();
                 }
             }
             else
             {
                 marshalledObjectIndices = null;
             }
             commandResult = commandDelegate(this.parent.handle, this.handle, (uint)(objectIndices.Length), doubleMarshalledObjectTableEntries, marshalledObjectIndices);
             if (SharpVkException.IsError(commandResult))
             {
                 throw SharpVkException.Create(commandResult);
             }
             if (objectTableEntriesHandle.IsAllocated)
             {
                 objectTableEntriesHandle.Free();
             }
             if (objectIndicesHandle.IsAllocated)
             {
                 objectIndicesHandle.Free();
             }
         }
         finally
         {
             Interop.HeapUtil.FreeLog();
         }
     }
 }
Пример #6
0
 /// <summary>
 /// Copy results of queries in a query pool to a host memory region.
 /// </summary>
 public Result GetResults(uint firstQuery, uint queryCount, ArrayProxy <byte> data, DeviceSize stride, QueryResultFlags flags)
 {
     unsafe
     {
         try
         {
             Result   result         = default(Result);
             GCHandle dataHandle     = default(GCHandle);
             byte *   marshalledData = null;
             if (data.Contents != ProxyContents.Null)
             {
                 if (data.Contents == ProxyContents.Single)
                 {
                     byte *dataPointer = stackalloc byte[1];
                     *     dataPointer = data.GetSingleValue();
                     marshalledData = dataPointer;
                 }
                 else
                 {
                     var arrayValue = data.GetArrayValue();
                     dataHandle     = GCHandle.Alloc(arrayValue.Array, GCHandleType.Pinned);
                     marshalledData = (byte *)(dataHandle.AddrOfPinnedObject() + (int)(MemUtil.SizeOf <byte>() * arrayValue.Offset)).ToPointer();
                 }
             }
             else
             {
                 marshalledData = null;
             }
             result = Interop.Commands.vkGetQueryPoolResults(this.parent.handle, this.handle, firstQuery, queryCount, (Size)(data.Length), marshalledData, stride, flags);
             if (SharpVkException.IsError(result))
             {
                 throw SharpVkException.Create(result);
             }
             if (dataHandle.IsAllocated)
             {
                 dataHandle.Free();
             }
             return(result);
         }
         finally
         {
             Interop.HeapUtil.FreeLog();
         }
     }
 }