Beispiel #1
0
        internal VkResult BindMemory(SoftwareDeviceMemory memory, int memoryOffset)
        {
            // TODO: SoftwareImage.BindMemory()

            this.m_memory       = memory;
            this.m_memoryOffset = memoryOffset;
            return(VkResult.VK_SUCCESS);
        }
Beispiel #2
0
        public void BindMemory(SoftwareDeviceMemory memory, int memoryOffset)
        {
            this.m_deviceMemory = memory;
            this.m_memoryOffset = memoryOffset;

            if (createInfo.usage.HasFlag(VkBufferUsageFlagBits.VK_BUFFER_USAGE_VERTEX_BUFFER_BIT))
            {
                m_VertexBufferCache = new VertexBufferCache(memory.m_bytes, memoryOffset);
            }
        }
Beispiel #3
0
        public override void FreeMemory(VkDeviceMemory memory)
        {
            SoftwareDeviceMemory mem = (SoftwareDeviceMemory)memory;

            if (mem != null)
            {
                m_DeviceMemory.Remove(mem);
                mem.Destroy();
            }
        }
Beispiel #4
0
        public override VkResult AllocateMemory(VkMemoryAllocateInfo pAllocateInfo, out VkDeviceMemory pMemory)
        {
            VkPreconditions.CheckRange(pAllocateInfo.allocationSize, 1, int.MaxValue, nameof(pAllocateInfo.allocationSize));
            VkPreconditions.CheckRange(pAllocateInfo.memoryTypeIndex != 0, nameof(pAllocateInfo.memoryTypeIndex));

            var ret = new SoftwareDeviceMemory(this, pAllocateInfo);

            m_DeviceMemory.Add(ret);
            pMemory = ret;
            return(VkResult.VK_SUCCESS);
        }
Beispiel #5
0
        internal void CopyBufferToImage(VkBuffer srcBuffer, VkImageLayout dstImageLayout, int regionCount, VkBufferImageCopy[] pRegions)
        {
            int                  dstPixelSize   = 4;
            SoftwareBuffer       softwareBuffer = (SoftwareBuffer)srcBuffer;
            SoftwareDeviceMemory sdm            = softwareBuffer.m_deviceMemory;

            int dstLineStride  = m_imageExtent.width * dstPixelSize;
            int dstDepthStride = m_imageExtent.width * m_imageExtent.height * dstPixelSize;

            for (int nRegion = 0; nRegion < regionCount; nRegion++)
            {
                var region        = pRegions[nRegion];
                int regLineStride = region.imageExtent.width * dstPixelSize;

                for (int z = 0; z < region.imageExtent.depth; z++)
                {
                    int bufferOffset      = region.bufferOffset;
                    int bufferImageHeight = region.bufferImageHeight;
                    int bufferRowLength   = region.bufferRowLength;
                    if (bufferImageHeight == 0 || bufferRowLength == 0)
                    {
                        bufferImageHeight = m_imageExtent.height;
                        bufferRowLength   = m_imageExtent.width * dstPixelSize;
                    }

                    int srcLineStride  = bufferRowLength;
                    int srcDepthStride = bufferImageHeight * bufferRowLength;

                    int srcOffset = (z * srcDepthStride) + bufferOffset + softwareBuffer.m_memoryOffset;
                    int dstOffset = ((region.imageOffset.z + z) * dstDepthStride) + (region.imageOffset.y * dstLineStride) + (region.imageOffset.x * dstPixelSize);

                    for (int y = 0; y < region.imageExtent.height; y++)
                    {
                        int imgOffs = dstOffset + (y * dstLineStride);
                        int bufOffs = srcOffset + (y * srcLineStride);
                        Buffer.BlockCopy(sdm.m_bytes, bufOffs, m_imageData, imgOffs, regLineStride);
                    }
                }
            }
        }
Beispiel #6
0
        public override void UnmapMemory(VkDeviceMemory memory)
        {
            SoftwareDeviceMemory mem = (SoftwareDeviceMemory)memory;

            mem.UnmapMemory();
        }
Beispiel #7
0
        public override VkResult MapMemory(VkDeviceMemory memory, int offset, int size, int memoryMapFlags, out byte[] ppData)
        {
            SoftwareDeviceMemory mem = (SoftwareDeviceMemory)memory;

            return(mem.MapMemory(offset, size, memoryMapFlags, out ppData));
        }