public Image(VulkanPhysicalDevice myDevice, ImageCreateInfo pCreateInfo, AllocationCallbacks pAllocator = null)
        {
            this.Device = myDevice;
            Result result;

            unsafe
            {
                fixed(UInt64 *ptrpImage = &this.m)
                {
                    result = Interop.NativeMethods.vkCreateImage(myDevice.LogicalDevice.m, pCreateInfo != null ? pCreateInfo.m : (Interop.ImageCreateInfo *) default(IntPtr), pAllocator != null ? pAllocator.m : null, ptrpImage);
                }

                if (result != Result.Success)
                {
                    throw new ResultException(result);
                }
            }

            MemoryRequirements myRequirements = GetImageMemoryRequirements();

            MemoryAllocateInfo MemInfo = new MemoryAllocateInfo();

            MemInfo.AllocationSize = myRequirements.Size;


            MemInfo.MemoryTypeIndex = myDevice.GetMemoryIndexFromProperty(myRequirements.MemoryTypeBits, MemoryPropertyFlags.DeviceLocal);



            deviceMemory = new DeviceMemory(myDevice.LogicalDevice, MemInfo);
            BindImageMemory(deviceMemory, 0);
        }
예제 #2
0
        private unsafe IntPtr SetupCopy <T>(int mySize)
        {
            if (SizeOfBuffer == 0)
            {
                SizeOfInternalStructure = mySize;
                var memoryReq = myActiveDevice.LogicalDevice.GetBufferMemoryRequirements(this);
                SizeOfBuffer = memoryReq.Size;
                allocInfo    = new MemoryAllocateInfo {
                    AllocationSize = memoryReq.Size
                };
                var  memoryProperties = myActiveDevice.GetMemoryProperties();
                bool heapIndexSet     = false;
                var  memoryTypes      = memoryProperties.MemoryTypes;

                for (uint i = 0; i < memoryProperties.MemoryTypeCount; i++)
                {
                    if (((memoryReq.MemoryTypeBits >> (int)i) & 1) == 1 &&
                        (memoryTypes[i].PropertyFlags & MemoryPropertyFlags.HostVisible) == MemoryPropertyFlags.HostVisible)
                    {
                        allocInfo.MemoryTypeIndex = i;
                        heapIndexSet = true;
                    }
                }
                if (!heapIndexSet)
                {
                    allocInfo.MemoryTypeIndex = memoryProperties.MemoryTypes[0].HeapIndex;
                }
            }

            deviceMemory = new DeviceMemory(myActiveDevice.LogicalDevice, allocInfo);
            return(myActiveDevice.LogicalDevice.MapMemory(deviceMemory, 0, mySize, 0));
        }
        //static object BindMemoryLock()
        public void BindImageMemory(DeviceMemory memory, DeviceSize memoryOffset)
        {
            Result result;

            unsafe
            {
                result = Interop.NativeMethods.vkBindImageMemory(Device.LogicalDevice.m, this.m, memory != null ? memory.m : default(UInt64), memoryOffset);
                if (result != Result.Success)
                {
                    throw new ResultException(result);
                }
            }
        }
예제 #4
0
        private void createIndexBuffer()
        {
            var size          = Marshal.SizeOf(typeof(short)) * this.indices.Count;
            var transferUsage = Vk.BufferUsageFlags.TransferSrc;
            var indexUsage    = Vk.BufferUsageFlags.IndexBuffer
                                | Vk.BufferUsageFlags.TransferDst;
            var transferMemoryProps = Vk.MemoryPropertyFlags.DeviceLocal;
            var indexMemoryProps    = Vk.MemoryPropertyFlags.HostVisible
                                      | Vk.MemoryPropertyFlags.HostCoherent;
            var sharingMode = this.GetSharingMode();

            BufferWithMemory stagingBuffer;

            try {
                stagingBuffer = VkHelper.CreateBuffer(this, size, transferUsage,
                                                      transferMemoryProps, sharingMode);
            } catch (Vk.ResultException result) {
                throw new VkException("An error occurred while creating the staging buffer.", result);
            }

            IntPtr memory     = this.Device.MapMemory(stagingBuffer.Memory, 0, size);
            var    indexArray = this.indices.ToArray();

            MemoryManagement.ArrayToPtr <short>(indexArray, memory, false);
            this.Device.UnmapMemory(stagingBuffer.Memory);

            try {
                BufferWithMemory indexBuffer = VkHelper.CreateBuffer(this, size, indexUsage,
                                                                     indexMemoryProps, sharingMode);
                this.vkIndexBuffer       = indexBuffer.Buffer;
                this.vkIndexBufferMemory = indexBuffer.Memory;
            } catch (Vk.ResultException result) {
                throw new VkException("An error occurred while creating the index buffer.", result);
            }

            VkHelper.CopyBuffer(stagingBuffer.Buffer, this.vkIndexBuffer, size, this);

            stagingBuffer.Destroy(this.Device);
        }