Ejemplo n.º 1
0
 void ReleaseUnmanagedResources()
 {
     if (mFramebuffers != null)
     {
         foreach (var fb in mFramebuffers)
         {
             fb.DestroyFramebuffer(mPartition.Device, null);
         }
         mFramebuffers = null;
     }
     if (mRenderpass != null)
     {
         mRenderpass.DestroyRenderPass(mPartition.Device, null);
         mRenderpass = null;
     }
     if (mView != null)
     {
         mView.DestroyImageView(mPartition.Device, null);
         mView = null;
     }
     if (mImage != null)
     {
         mImage.DestroyImage(mPartition.Device, null);
         mImage = null;
     }
     if (mDeviceMemory != null)
     {
         mDeviceMemory.FreeMemory(mPartition.Device, null);
         mDeviceMemory = null;
     }
 }
Ejemplo n.º 2
0
        public BufferInfo(IMgThreadPartition partition, MgBufferUsageFlagBits usage, MgMemoryPropertyFlagBits propertyFlags, uint bufferSize)
        {
            Debug.Assert(partition != null);

            mDevice = partition.Device;
            Debug.Assert(mDevice != null);

            mUsageFlags = usage;

            mMemoryPropertyFlags = propertyFlags;

            var bufferCreateInfo = new MgBufferCreateInfo
            {
                Usage = usage,
                Size  = bufferSize,
            };

            IMgBuffer buffer;

            var device = partition.Device;

            var result = device.CreateBuffer(bufferCreateInfo, null, out buffer);

            Debug.Assert(result == Result.SUCCESS);

            MgMemoryRequirements memReqs;

            device.GetBufferMemoryRequirements(buffer, out memReqs);
            mAlignment  = memReqs.Alignment;
            mBufferSize = memReqs.Size;

            uint memoryTypeIndex;

            partition.GetMemoryType(memReqs.MemoryTypeBits, mMemoryPropertyFlags, out memoryTypeIndex);

            var memAlloc = new MgMemoryAllocateInfo
            {
                MemoryTypeIndex = memoryTypeIndex,
                AllocationSize  = memReqs.Size,
            };

            IMgDeviceMemory deviceMemory;

            result = device.AllocateMemory(memAlloc, null, out deviceMemory);
            Debug.Assert(result == Result.SUCCESS);

            buffer.BindBufferMemory(device, deviceMemory, 0);


            mBuffer       = buffer;
            mDeviceMemory = deviceMemory;

            mDescriptor = new MgDescriptorBufferInfo
            {
                Buffer = mBuffer,
                Offset = 0,
                Range  = mBufferSize,
            };
        }
Ejemplo n.º 3
0
        public Result BindImageMemory(IMgDevice device, IMgDeviceMemory memory, ulong memoryOffset)
        {
            var deviceMemory = memory as IGLDeviceMemory;

            if (deviceMemory != null)
            {
                mMemory = IntPtr.Add(deviceMemory.Handle, (int)memoryOffset);
            }
            return(Result.SUCCESS);
        }
Ejemplo n.º 4
0
        public Result BindBufferMemory(IMgDevice device, IMgDeviceMemory memory, UInt64 memoryOffset)
        {
            Debug.Assert(!mIsDisposed);

            var bDevice = (VkDevice)device;

            Debug.Assert(bDevice != null);             // RIGHT TYPE

            var bMemory = (VkDeviceMemory)memory;

            Debug.Assert(bMemory != null);             // RIGHT TYPE

            return(Interops.vkBindBufferMemory(bDevice.Handle, this.Handle, bMemory.Handle, memoryOffset));
        }
Ejemplo n.º 5
0
        public Result BindBufferMemory(IMgDevice device, IMgDeviceMemory memory, ulong memoryOffset)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            if (memory == null)
            {
                throw new ArgumentNullException(nameof(memory));
            }

            var bDeviceMemory = (AmtDeviceMemory)memory;

            VertexBuffer = bDeviceMemory.InternalBuffer;
            // TODO : not sure where this comes into play
            BoundMemoryOffset = memoryOffset;

            return(Result.SUCCESS);
        }
Ejemplo n.º 6
0
 void ReleaseUnmanagedResources()
 {
     mFramebuffers.Clear();
     if (mRenderpass != null)
     {
         mRenderpass.DestroyRenderPass(mGraphicsConfiguration.Partition.Device, null);
         mRenderpass = null;
     }
     if (mDepthStencilImageView != null)
     {
         mDepthStencilImageView.DestroyImageView(mGraphicsConfiguration.Partition.Device, null);
         mDepthStencilImageView = null;
     }
     if (mImage != null)
     {
         mImage.DestroyImage(mGraphicsConfiguration.Partition.Device, null);
         mImage = null;
     }
     if (mDeviceMemory != null)
     {
         mDeviceMemory.FreeMemory(mGraphicsConfiguration.Partition.Device, null);
         mDeviceMemory = null;
     }
 }
Ejemplo n.º 7
0
        public Result BindBufferMemory(IMgDevice device, IMgDeviceMemory memory, ulong memoryOffset)
        {
            var internalMemory = memory as GLDeviceMemory;

            if (internalMemory == null)
            {
                throw new ArgumentException("memory");
            }

            if (memoryOffset >= (ulong)Int32.MaxValue)
            {
                throw new InvalidCastException("memoryOffset >= Int32.MaxValue");
            }
            var offset = (Int32)memoryOffset;

            this.Source = IntPtr.Add(internalMemory.Handle, offset);

            if (IsBufferType)
            {
                this.BufferId = internalMemory.BufferId;
            }

            return(Result.SUCCESS);
        }
Ejemplo n.º 8
0
        void CreateDepthStencil(IMgCommandBuffer setupCmdBuffer, MgGraphicsDeviceCreateInfo createInfo)
        {
            var image = new MgImageCreateInfo {
                ImageType = MgImageType.TYPE_2D,
                Format    = createInfo.DepthStencil,
                Extent    = new MgExtent3D {
                    Width  = createInfo.Width,
                    Height = createInfo.Height,
                    Depth  = 1
                },
                MipLevels   = 1,
                ArrayLayers = 1,
                Samples     = createInfo.Samples,
                Tiling      = MgImageTiling.OPTIMAL,
                // TODO : multisampled uses MgImageUsageFlagBits.TRANSIENT_ATTACHMENT_BIT | MgImageUsageFlagBits.DEPTH_STENCIL_ATTACHMENT_BIT;
                Usage = MgImageUsageFlagBits.DEPTH_STENCIL_ATTACHMENT_BIT | MgImageUsageFlagBits.TRANSFER_SRC_BIT,
                Flags = 0,
            };
            var mem_alloc = new MgMemoryAllocateInfo {
                AllocationSize  = 0,
                MemoryTypeIndex = 0,
            };
            MgMemoryRequirements memReqs;

            Debug.Assert(mGraphicsConfiguration.Partition != null);

            Result err;

            {
                IMgImage dsImage;
                err = mGraphicsConfiguration.Partition.Device.CreateImage(image, null, out dsImage);
                Debug.Assert(err == Result.SUCCESS, err + " != Result.SUCCESS");
                mImage = dsImage;
            }
            mGraphicsConfiguration.Partition.Device.GetImageMemoryRequirements(mImage, out memReqs);
            mem_alloc.AllocationSize = memReqs.Size;
            uint memTypeIndex;
            bool memoryTypeFound = mGraphicsConfiguration.Partition.GetMemoryType(memReqs.MemoryTypeBits, MgMemoryPropertyFlagBits.DEVICE_LOCAL_BIT, out memTypeIndex);

            Debug.Assert(memoryTypeFound);
            mem_alloc.MemoryTypeIndex = memTypeIndex;
            {
                IMgDeviceMemory dsDeviceMemory;
                err = mGraphicsConfiguration.Partition.Device.AllocateMemory(mem_alloc, null, out dsDeviceMemory);
                Debug.Assert(err == Result.SUCCESS, err + " != Result.SUCCESS");
                mDeviceMemory = dsDeviceMemory;
            }
            err = mImage.BindImageMemory(mGraphicsConfiguration.Partition.Device, mDeviceMemory, 0);
            Debug.Assert(err == Result.SUCCESS, err + " != Result.SUCCESS");
            mImageTools.SetImageLayout(setupCmdBuffer, mImage, MgImageAspectFlagBits.DEPTH_BIT | MgImageAspectFlagBits.STENCIL_BIT, MgImageLayout.UNDEFINED, MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
            var depthStencilView = new MgImageViewCreateInfo {
                Image            = mImage,
                ViewType         = MgImageViewType.TYPE_2D,
                Format           = createInfo.DepthStencil,
                Flags            = 0,
                SubresourceRange = new MgImageSubresourceRange {
                    AspectMask     = MgImageAspectFlagBits.DEPTH_BIT | MgImageAspectFlagBits.STENCIL_BIT,
                    BaseMipLevel   = 0,
                    LevelCount     = 1,
                    BaseArrayLayer = 0,
                    LayerCount     = 1,
                },
            };
            {
                IMgImageView dsView;
                err = mGraphicsConfiguration.Partition.Device.CreateImageView(depthStencilView, null, out dsView);
                Debug.Assert(err == Result.SUCCESS, err + " != Result.SUCCESS");
                mDepthStencilImageView = dsView;
            }
        }
Ejemplo n.º 9
0
 public void GetDeviceMemoryCommitment(IMgDeviceMemory memory, ref ulong pCommittedMemoryInBytes)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 10
0
 public Result AllocateMemory(MgMemoryAllocateInfo pAllocateInfo, IMgAllocationCallbacks allocator, out IMgDeviceMemory pMemory)
 {
     pMemory = new AmtDeviceMemory(mDevice, pAllocateInfo);
     return(Result.SUCCESS);
 }
Ejemplo n.º 11
0
 public Result AllocateMemory(MgMemoryAllocateInfo pAllocateInfo, IMgAllocationCallbacks allocator, out IMgDeviceMemory pMemory)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
 public Result AllocateMemory(MgMemoryAllocateInfo pAllocateInfo, IMgAllocationCallbacks allocator, out IMgDeviceMemory pMemory)
 {
     pMemory = mEntrypoint.DeviceMemory.CreateDeviceMemory(pAllocateInfo);
     return(Result.SUCCESS);
 }
Ejemplo n.º 13
0
 public Result BindBufferMemory(IMgDevice device, IMgDeviceMemory memory, ulong memoryOffset)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 14
0
 public Result BindBufferMemory(IMgDevice device, IMgDeviceMemory memory, ulong memoryOffset)
 {
     return(Result.SUCCESS);
 }