Example #1
0
        public VKBuffer(
            string name, Graphics graphics, long count, BufferUsages usages, MemoryProperties memoryProperties,
            BufferCreateFlags flags  = BufferCreateFlags.None, SharingMode sharingMode = SharingMode.Exclusive,
            int[] queueFamilyIndices = null
            )
        {
            Name     = name;
            Graphics = graphics;
            Count    = count;
            Size     = count * Interop.SizeOf <T>();
            Usages   = usages;
            Buffer   = Graphics.Device.CreateBuffer(new BufferCreateInfo(
                                                        size: Size,
                                                        usages: usages,
                                                        flags: flags,
                                                        sharingMode: sharingMode,
                                                        queueFamilyIndices: queueFamilyIndices
                                                        ));
            var reqs = Buffer.GetMemoryRequirements();

            DeviceMemory = Graphics.Device.AllocateMemory(new MemoryAllocateInfo(
                                                              reqs.Size,
                                                              graphics.GetMemoryTypeIndex(reqs.MemoryTypeBits, memoryProperties)
                                                              ));
            Buffer.BindMemory(DeviceMemory);
        }
        /**
         * Get the index of a memory type that has all the requested property bits set
         *
         * @param typeBits Bitmask with bits set for each memory type supported by the resource to request for (from VkMemoryRequirements)
         * @param properties Bitmask of properties for the memory type to request
         * @param (Optional) memTypeFound Pointer to a bool that is set to true if a matching memory type has been found
         *
         * @return Index of the requested memory type
         *
         * @throw Throws an exception if memTypeFound is null and no memory type could be found that supports the requested properties
         */
        public uint getMemoryType(uint typeBits, VkMemoryPropertyFlagBits properties, uint *memTypeFound = null)
        {
            for (uint i = 0; i < MemoryProperties.memoryTypeCount; i++)
            {
                if ((typeBits & 1) == 1)
                {
                    if ((MemoryProperties.GetMemoryType(i).propertyFlags & properties) == properties)
                    {
                        if (memTypeFound != null)
                        {
                            *memTypeFound = True;
                        }
                        return(i);
                    }
                }
                typeBits >>= 1;
            }

            if (memTypeFound != null)
            {
                *memTypeFound = False;
                return(0);
            }
            else
            {
                throw new InvalidOperationException("Could not find a matching memory type");
            }
        }
Example #3
0
    public void Upload()
    {
        string           s         = input.text;
        MemoryProperties newMemory = new MemoryProperties(ProgramManager.currentUser, s);

        ProgramManager.memories.Add(newMemory);
        input.text = "";

        SceneManager.LoadScene(1);
    }
 internal int GetMemoryType(MemoryProperties properties, int supportedTypesFilter = ~0)
 {
     for (int i = 0; i < deviceMemoryProperties.MemoryTypes.Length; i++)
     {
         if (supportedTypesFilter.HasBitSet(i) &&
             (deviceMemoryProperties.MemoryTypes[i].PropertyFlags & properties) == properties)
         {
             return(i);
         }
     }
     throw new Exception(
               $"[{nameof(HostDevice)}] Device {Name} has no memory-type that fits requirements");
 }
Example #5
0
        public static uint GetMemoryType(uint typeBits, VkMemoryPropertyFlags properties)
        {
            for (uint i = 0; i < MemoryProperties.memoryTypeCount; i++)
            {
                if ((typeBits & 1) == 1)
                {
                    if ((MemoryProperties.GetMemoryType(i).propertyFlags & properties) == properties)
                    {
                        return(i);
                    }
                }
                typeBits >>= 1;
            }

            return(0);
        }
Example #6
0
 public InstructionNode(Instruction instruction, MethodDefinition method)
 {
     Instruction = instruction;
     Method      = method;
     // TODO rework, this must precede StackPopCount for now, yuck
     DataFlowBackRelated       = new DataFlowBackArgList(this);
     StackPushCount            = GetStackPushCount(instruction);
     StackPopCount             = GetStackPopCount(instruction);
     MemoryReadCount           = MemoryProperties.GetMemReadCount(instruction.OpCode.Code);
     MemoryStoreCount          = MemoryProperties.GetMemStoreCount(instruction.OpCode.Code);
     ProgramFlowBackRoutes     = new ProgramFlowBackRoutes(this);
     ProgramFlowForwardRoutes  = new ProgramFlowForwardRoutes(this);
     DataFlowForwardRelated    = new DataFlowForwardArgList(this);
     SingleUnitBackRelated     = new SingleUnitBackRelated(this);
     SingleUnitForwardRelated  = new SingleUnitForwardRelated(this);
     SingleUnitNodes           = new List <InstructionNode>();
     MethodNameForSerilization = method.Name;
     MyGuid            = Guid.NewGuid();
     _BranchProperties = new BranchProperties(this);
     BranchProperties.BaseBranch.AddTwoWay(this);
 }
Example #7
0
        public void CreateBufferMemory <T>(string bufName, MemoryProperties props)
        {
            if (mDeviceMems.ContainsKey(bufName))
            {
                Misc.SafeInvoke(eErrorSpam, "Buffer " + bufName + " already has a chunk of mem allocated...");
                return;
            }
            Buffer buf = mBuffers[bufName];

            DeviceMemory       dm;
            MemoryRequirements mr = buf.GetMemoryRequirements();

            MemoryAllocateInfo mai = new MemoryAllocateInfo();

            mai.AllocationSize  = mr.Size;
            mai.MemoryTypeIndex = FindMemoryType(mr.MemoryTypeBits, props);

            dm = mLogical.AllocateMemory(mai);

            mDeviceMems.Add(bufName, dm);
        }
Example #8
0
        public Response Get()
        {
            MemoryProperties Properties = Core.Instance.Memory.RepopulateAndGetProperties();

            if (Utils.Hardware.isRunningRaspberryPi)
            {
                return(new Response
                {
                    Model = Properties,
                    Template = Templates.Memory
                });
            }
            else
            {
                return(new Response
                {
                    StatusCode = System.Net.HttpStatusCode.Redirect,
                    Location = new Uri(Context.Paths.Base + Context.Paths.Home)
                });
            }
        }
Example #9
0
 public static int GetMemReadCount(Code code)
 {
     return(MemoryProperties.GetMemReadCount(code));
 }
Example #10
0
 /// <summary>
 /// Get the memory type index for the required memory type
 /// </summary>
 /// <param name="memoryTypeBits"></param>
 /// <param name="properties"></param>
 /// <returns></returns>
 public int GetMemoryTypeIndex(int memoryTypeBits, MemoryProperties properties)
 {
     return(MemoryProperties.MemoryTypes.IndexOf(memoryTypeBits, properties));
 }
Example #11
0
        private MemoryInformation[][] GetRegions()
        {
            var addy = new IntPtr();
            IList <MemoryInformation> regions
                = new List <MemoryInformation>();

            while (true)
            {
                var memInf  = new MemoryInformation();
                int memDump = Pinvoke.VirtualQueryEx(_access.Handle, addy,
                                                     out memInf, Marshal.SizeOf(memInf));

                if (memDump == 0)
                {
                    return(DivideRegions(regions));
                }

                var memProps = MemoryProperties.Parse(memInf);

                if (!memProps.State.IsCommited &&
                    !memProps.Protect.IsGuard &&
                    memProps.Protect.IsReadOnly)
                {
                    goto ADDY;
                }

                if (!Settings.MemPrivate)
                {
                    if (memProps.Type.IsPrivate)
                    {
                        goto ADDY;
                    }
                }

                if (!Settings.MemImage)
                {
                    if (memProps.Type.IsImageMapped)
                    {
                        goto ADDY;
                    }
                }
                if (!Settings.MemMapped)
                {
                    if (memProps.Type.IsMapped)
                    {
                        goto ADDY;
                    }
                }

                if (Settings.Writable != ScanType.BOTH)
                {
                    if (Settings.Writable == ScanType.ONLY)
                    {
                        if (!memProps.Protect.IsWritable)
                        {
                            goto ADDY;
                        }
                    }
                    else if (memProps.Protect.IsWritable)
                    {
                        goto ADDY;
                    }
                }
                if (Settings.CopyOnWrite != ScanType.BOTH)
                {
                    if (Settings.CopyOnWrite == ScanType.ONLY)
                    {
                        if (!memProps.Protect.IsCopyOnWrite)
                        {
                            goto ADDY;
                        }
                    }
                    else if (memProps.Protect.IsCopyOnWrite)
                    {
                        goto ADDY;
                    }
                }
                if (Settings.Executable != ScanType.BOTH)
                {
                    if (Settings.Executable == ScanType.ONLY)
                    {
                        if (!memProps.Protect.IsExecutable)
                        {
                            goto ADDY;
                        }
                    }
                    else if (memProps.Protect.IsExecutable)
                    {
                        goto ADDY;
                    }
                }

                regions.Add(memInf);

ADDY:
                addy = new IntPtr(memInf.BaseAddress.ToInt32()
                                  + (int)memInf.RegionSize);
            }
        }
Example #12
0
        /// <summary>
        /// Gets the index of the <see cref="MemoryType"/> that has all the requested <paramref
        /// name="properties"/> set or <c>-1</c> if not found.
        /// </summary>
        /// <param name="memoryTypes">
        /// Structures describing the memory types that can be used to access memory allocated from
        /// the heaps specified by <see cref="PhysicalDeviceMemoryProperties.MemoryHeaps"/>.
        /// </param>
        /// <param name="memoryTypeBits">
        /// A bitmask of <see cref="MemoryRequirements.MemoryTypeBits"/> that contains one bit set
        /// for every memory type supported by the resource.
        /// </param>
        /// <param name="properties">A bitmask of properties to request.</param>
        /// <returns>Index of the requested <see cref="MemoryType"/> or <c>-1</c> if not found.</returns>
        /// ///
        /// <exception cref="ArgumentNullException"><paramref name="memoryTypes"/> is <c>null</c>.</exception>
        public static int IndexOf(this IList <MemoryType> memoryTypes, int memoryTypeBits, MemoryProperties properties)
        {
            if (memoryTypes == null)
            {
                throw new ArgumentNullException(nameof(memoryTypes));
            }

            int count = memoryTypes?.Count ?? 0;

            for (int i = 0; i < count; i++)
            {
                if ((memoryTypeBits & 1) == 1 &&
                    (memoryTypes[i].PropertyFlags & properties) == properties)
                {
                    return(i);
                }
                memoryTypeBits >>= 1;
            }
            return(-1);
        }
Example #13
0
        //from the vulkan tutorial
        int     FindMemoryType(int typeFilter, MemoryProperties memProps)
        {
            PhysicalDeviceMemoryProperties pdmp = mLogical.Parent.GetMemoryProperties();

            return(pdmp.MemoryTypes.IndexOf(typeFilter, memProps));
        }
        // find memory type with desired properties.
        int FindMemoryType(int memoryTypeBits, MemoryProperties properties)
        {
            PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.GetMemoryProperties();

            return(memoryProperties.MemoryTypes.IndexOf(memoryTypeBits, properties));
        }