public void Clear()
        {
            Span <object> span = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetArrayDataReference(_objs), Length);

            span.Clear();
        }
Exemplo n.º 2
0
 public Span <D3D12MA_StatInfo> AsSpan() => MemoryMarshal.CreateSpan(ref e0, (int)D3D12MA_HEAP_TYPE_COUNT);
Exemplo n.º 3
0
 public Span <LARGE_INTEGER> AsSpan() => MemoryMarshal.CreateSpan(ref e0, 9);
Exemplo n.º 4
0
 public Span <IP_ADAPTER_INDEX_MAP> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
Exemplo n.º 5
0
 /// <summary>Gets a <see cref="ReadOnlySpan{T}"/> containing the bytes of the provided value.</summary>
 /// <typeparam name="T">The type of the value whose bytes to get.</typeparam>
 /// <param name="value">The value whose bytes to get.</param>
 /// <returns>The bytes of the value.</returns>
 public static ReadOnlySpan <byte> GetBytes <T>(this ref T value)
     where T : unmanaged
 {
     return(MemoryMarshal.AsBytes(MemoryMarshal.CreateSpan(ref value, 1)));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UInt256"/> class.
        /// Passed hex string must be a valid hex string with 64 char length, or 66 if prefix 0x is used, otherwise an exception is thrown.
        /// Input data is considered in big endian.
        /// </summary>
        public UInt256(string hexString)
        {
            if (hexString is null)
            {
                ThrowHelper.ThrowArgumentNullException(nameof(hexString));
            }

            //account for 0x prefix
            if (hexString.Length < EXPECTED_SIZE * 2)
            {
                ThrowHelper.ThrowFormatException($"the hex string should be {EXPECTED_SIZE * 2} chars long or {(EXPECTED_SIZE * 2) + 4} if prefixed with 0x.");
            }

            ReadOnlySpan <char> hexAsSpan = (hexString[0] == '0' && (hexString[1] == 'X' || hexString[1] == 'x')) ? hexString.AsSpan(2) : hexString.AsSpan();

            if (hexAsSpan.Length != EXPECTED_SIZE * 2)
            {
                ThrowHelper.ThrowFormatException($"the hex string should be {EXPECTED_SIZE * 2} chars long or {(EXPECTED_SIZE * 2) + 4} if prefixed with 0x.");
            }

            Span <byte> dst = MemoryMarshal.AsBytes(MemoryMarshal.CreateSpan(ref part1, EXPECTED_SIZE / sizeof(ulong)));

            int i = hexAsSpan.Length - 1;
            int j = 0;

            while (i > 0)
            {
                char c = hexAsSpan[i--];
                if (c >= '0' && c <= '9')
                {
                    dst[j] = (byte)(c - '0');
                }
                else if (c >= 'a' && c <= 'f')
                {
                    dst[j] = (byte)(c - ('a' - 10));
                }
                else if (c >= 'A' && c <= 'F')
                {
                    dst[j] = (byte)(c - ('A' - 10));
                }
                else
                {
                    ThrowHelper.ThrowArgumentException("Invalid nibble: " + c);
                }

                c = hexAsSpan[i--];
                if (c >= '0' && c <= '9')
                {
                    dst[j] |= (byte)((c - '0') << 4);
                }
                else if (c >= 'a' && c <= 'f')
                {
                    dst[j] |= (byte)((c - ('a' - 10)) << 4);
                }
                else if (c >= 'A' && c <= 'F')
                {
                    dst[j] |= (byte)((c - ('A' - 10)) << 4);
                }
                else
                {
                    ThrowHelper.ThrowArgumentException("Invalid nibble: " + c);
                }

                j++;
            }
        }
 public Span <SOCKADDR_STORAGE> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
Exemplo n.º 8
0
 public Span <DXGI_FORMAT> AsSpan() => MemoryMarshal.CreateSpan(ref e0, 8);
Exemplo n.º 9
0
 /// <summary>
 /// Writes data to GPU mapped memory.
 /// </summary>
 /// <typeparam name="T">Type of the data</typeparam>
 /// <param name="va">GPU virtual address to write the value into</param>
 /// <param name="value">The value to be written</param>
 public void Write <T>(ulong va, T value) where T : unmanaged
 {
     Write(va, MemoryMarshal.Cast <T, byte>(MemoryMarshal.CreateSpan(ref value, 1)));
 }
Exemplo n.º 10
0
            public bool IsHeaderValid()
            {
                Span <OuterHeader> spanHeader = MemoryMarshal.CreateSpan(ref this, 1);

                return(XXHash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader).Slice(0, Unsafe.SizeOf <OuterHeader>() - Unsafe.SizeOf <Hash128>())) == HeaderHash);
            }
 public Span <DEVICE_POWER_STATE> AsSpan() => MemoryMarshal.CreateSpan(ref e0, 7);
Exemplo n.º 12
0
            public void SetHeaderHash()
            {
                Span <OuterHeader> spanHeader = MemoryMarshal.CreateSpan(ref this, 1);

                HeaderHash = XXHash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader).Slice(0, Unsafe.SizeOf <OuterHeader>() - Unsafe.SizeOf <Hash128>()));
            }
Exemplo n.º 13
0
 public Span <MIB_IFROW> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
Exemplo n.º 14
0
 public Item(ref T value, int index)
 {
     this.span = MemoryMarshal.CreateSpan(ref value, index);
 }
 public Span <KERB_TICKET_CACHE_INFO_EX2> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
Exemplo n.º 16
0
 public Span <RenderTargetBlendDesc> AsSpan()
 => MemoryMarshal.CreateSpan(ref Element0, 8);
 public Span <LUID_AND_ATTRIBUTES> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
 public Span <DEVICE_STORAGE_ADDRESS_RANGE> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
Exemplo n.º 19
0
 public Span <nint> AsSpan() => MemoryMarshal.CreateSpan(ref e0, 24);
Exemplo n.º 20
0
 public unsafe Span <byte> AsSpan() => MemoryMarshal.CreateSpan(ref Unsafe.AsRef <byte>(bytePtr), length);
Exemplo n.º 21
0
 public Span <DEVICEDUMP_STORAGESTACK_PUBLIC_STATE_RECORD> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
 public Span <SCM_LOGICAL_DEVICE_INSTANCE> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
Exemplo n.º 23
0
        /// <summary>
        /// Updates host shaders based on the guest GPU state.
        /// </summary>
        /// <param name="state">Current GPU state</param>
        private void UpdateShaderState(GpuState state)
        {
            ShaderAddresses addresses = new ShaderAddresses();

            Span <ShaderAddresses> addressesSpan = MemoryMarshal.CreateSpan(ref addresses, 1);

            Span <ulong> addressesArray = MemoryMarshal.Cast <ShaderAddresses, ulong>(addressesSpan);

            ulong baseAddress = state.Get <GpuVa>(MethodOffset.ShaderBaseAddress).Pack();

            for (int index = 0; index < 6; index++)
            {
                var shader = state.Get <ShaderState>(MethodOffset.ShaderState, index);

                if (!shader.UnpackEnable() && index != 1)
                {
                    continue;
                }

                addressesArray[index] = baseAddress + shader.Offset;
            }

            GraphicsShader gs = ShaderCache.GetGraphicsShader(state, addresses);

            _vsUsesInstanceId = gs.Shaders[0]?.Program.Info.UsesInstanceId ?? false;

            for (int stage = 0; stage < Constants.ShaderStages; stage++)
            {
                ShaderProgramInfo info = gs.Shaders[stage]?.Program.Info;

                _currentProgramInfo[stage] = info;

                if (info == null)
                {
                    continue;
                }

                var textureBindings = new TextureBindingInfo[info.Textures.Count];

                for (int index = 0; index < info.Textures.Count; index++)
                {
                    var descriptor = info.Textures[index];

                    Target target = GetTarget(descriptor.Type);

                    if (descriptor.IsBindless)
                    {
                        textureBindings[index] = new TextureBindingInfo(target, descriptor.CbufSlot, descriptor.CbufOffset);
                    }
                    else
                    {
                        textureBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex);
                    }
                }

                TextureManager.SetGraphicsTextures(stage, textureBindings);

                var imageBindings = new TextureBindingInfo[info.Images.Count];

                for (int index = 0; index < info.Images.Count; index++)
                {
                    var descriptor = info.Images[index];

                    Target target = GetTarget(descriptor.Type);

                    imageBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex);
                }

                TextureManager.SetGraphicsImages(stage, imageBindings);

                uint sbEnableMask = 0;
                uint ubEnableMask = 0;

                for (int index = 0; index < info.SBuffers.Count; index++)
                {
                    sbEnableMask |= 1u << info.SBuffers[index].Slot;
                }

                for (int index = 0; index < info.CBuffers.Count; index++)
                {
                    ubEnableMask |= 1u << info.CBuffers[index].Slot;
                }

                BufferManager.SetGraphicsStorageBufferEnableMask(stage, sbEnableMask);
                BufferManager.SetGraphicsUniformBufferEnableMask(stage, ubEnableMask);
            }

            _context.Renderer.Pipeline.SetProgram(gs.HostProgram);
        }
Exemplo n.º 24
0
 public static Span <T> CreateSpan <T>(ref T reference, int length)
 {
     return(MemoryMarshal.CreateSpan(ref reference, length));
 }
 public Span <RGBQUAD> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
Exemplo n.º 26
0
        /// <summary>
        /// Updates host shaders based on the guest GPU state.
        /// </summary>
        /// <param name="state">Current GPU state</param>
        private void UpdateShaderState(GpuState state)
        {
            ShaderAddresses addresses = new ShaderAddresses();

            Span <ShaderAddresses> addressesSpan = MemoryMarshal.CreateSpan(ref addresses, 1);

            Span <ulong> addressesArray = MemoryMarshal.Cast <ShaderAddresses, ulong>(addressesSpan);

            ulong baseAddress = state.Get <GpuVa>(MethodOffset.ShaderBaseAddress).Pack();

            for (int index = 0; index < 6; index++)
            {
                var shader = state.Get <ShaderState>(MethodOffset.ShaderState, index);

                if (!shader.UnpackEnable() && index != 1)
                {
                    continue;
                }

                addressesArray[index] = baseAddress + shader.Offset;
            }

            ShaderBundle gs = ShaderCache.GetGraphicsShader(state, addresses);

            _vsUsesInstanceId = gs.Shaders[0]?.Program.Info.UsesInstanceId ?? false;

            int storageBufferBindingsCount = 0;
            int uniformBufferBindingsCount = 0;

            for (int stage = 0; stage < Constants.ShaderStages; stage++)
            {
                ShaderProgramInfo info = gs.Shaders[stage]?.Program.Info;

                _currentProgramInfo[stage] = info;

                if (info == null)
                {
                    TextureManager.SetGraphicsTextures(stage, Array.Empty <TextureBindingInfo>());
                    TextureManager.SetGraphicsImages(stage, Array.Empty <TextureBindingInfo>());
                    BufferManager.SetGraphicsStorageBufferBindings(stage, null);
                    BufferManager.SetGraphicsUniformBufferBindings(stage, null);
                    continue;
                }

                var textureBindings = new TextureBindingInfo[info.Textures.Count];

                for (int index = 0; index < info.Textures.Count; index++)
                {
                    var descriptor = info.Textures[index];

                    Target target = ShaderTexture.GetTarget(descriptor.Type);

                    textureBindings[index] = new TextureBindingInfo(
                        target,
                        descriptor.Binding,
                        descriptor.CbufSlot,
                        descriptor.HandleIndex,
                        descriptor.Flags);
                }

                TextureManager.SetGraphicsTextures(stage, textureBindings);

                var imageBindings = new TextureBindingInfo[info.Images.Count];

                for (int index = 0; index < info.Images.Count; index++)
                {
                    var descriptor = info.Images[index];

                    Target target = ShaderTexture.GetTarget(descriptor.Type);
                    Format format = ShaderTexture.GetFormat(descriptor.Format);

                    imageBindings[index] = new TextureBindingInfo(
                        target,
                        format,
                        descriptor.Binding,
                        descriptor.CbufSlot,
                        descriptor.HandleIndex,
                        descriptor.Flags);
                }

                TextureManager.SetGraphicsImages(stage, imageBindings);

                BufferManager.SetGraphicsStorageBufferBindings(stage, info.SBuffers);
                BufferManager.SetGraphicsUniformBufferBindings(stage, info.CBuffers);

                if (info.SBuffers.Count != 0)
                {
                    storageBufferBindingsCount = Math.Max(storageBufferBindingsCount, info.SBuffers.Max(x => x.Binding) + 1);
                }

                if (info.CBuffers.Count != 0)
                {
                    uniformBufferBindingsCount = Math.Max(uniformBufferBindingsCount, info.CBuffers.Max(x => x.Binding) + 1);
                }
            }

            BufferManager.SetGraphicsStorageBufferBindingsCount(storageBufferBindingsCount);
            BufferManager.SetGraphicsUniformBufferBindingsCount(uniformBufferBindingsCount);

            _context.Renderer.Pipeline.SetProgram(gs.HostProgram);
        }
Exemplo n.º 27
0
 public Span <Silk.NET.DXGI.Format> AsSpan()
 => MemoryMarshal.CreateSpan(ref Element0, 8);
 public Span <HARDWARE_COUNTER_DATA> AsSpan() => MemoryMarshal.CreateSpan(ref e0, 16);
Exemplo n.º 29
0
 public Span <T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 59);
Exemplo n.º 30
0
        /// <summary>
        /// Updates host shaders based on the guest GPU state.
        /// </summary>
        private void UpdateShaderState()
        {
            ShaderAddresses addresses = new ShaderAddresses();

            Span <ShaderAddresses> addressesSpan = MemoryMarshal.CreateSpan(ref addresses, 1);

            Span <ulong> addressesArray = MemoryMarshal.Cast <ShaderAddresses, ulong>(addressesSpan);

            ulong baseAddress = _state.State.ShaderBaseAddress.Pack();

            for (int index = 0; index < 6; index++)
            {
                var shader = _state.State.ShaderState[index];

                if (!shader.UnpackEnable() && index != 1)
                {
                    continue;
                }

                addressesArray[index] = baseAddress + shader.Offset;
            }

            GpuAccessorState gas = new GpuAccessorState(
                _state.State.TexturePoolState.Address.Pack(),
                _state.State.TexturePoolState.MaximumId,
                (int)_state.State.TextureBufferIndex,
                _state.State.EarlyZForce,
                _drawState.Topology);

            ShaderBundle gs = _channel.MemoryManager.Physical.ShaderCache.GetGraphicsShader(ref _state.State, _channel, gas, addresses);

            byte oldVsClipDistancesWritten = _vsClipDistancesWritten;

            _drawState.VsUsesInstanceId = gs.Shaders[0]?.Info.UsesInstanceId ?? false;
            _vsClipDistancesWritten     = gs.Shaders[0]?.Info.ClipDistancesWritten ?? 0;

            if (oldVsClipDistancesWritten != _vsClipDistancesWritten)
            {
                UpdateUserClipState();
            }

            int storageBufferBindingsCount = 0;
            int uniformBufferBindingsCount = 0;

            for (int stage = 0; stage < Constants.ShaderStages; stage++)
            {
                ShaderProgramInfo info = gs.Shaders[stage]?.Info;

                _currentProgramInfo[stage] = info;

                if (info == null)
                {
                    _channel.TextureManager.SetGraphicsTextures(stage, Array.Empty <TextureBindingInfo>());
                    _channel.TextureManager.SetGraphicsImages(stage, Array.Empty <TextureBindingInfo>());
                    _channel.BufferManager.SetGraphicsStorageBufferBindings(stage, null);
                    _channel.BufferManager.SetGraphicsUniformBufferBindings(stage, null);
                    continue;
                }

                var textureBindings = new TextureBindingInfo[info.Textures.Count];

                for (int index = 0; index < info.Textures.Count; index++)
                {
                    var descriptor = info.Textures[index];

                    Target target = ShaderTexture.GetTarget(descriptor.Type);

                    textureBindings[index] = new TextureBindingInfo(
                        target,
                        descriptor.Binding,
                        descriptor.CbufSlot,
                        descriptor.HandleIndex,
                        descriptor.Flags);
                }

                _channel.TextureManager.SetGraphicsTextures(stage, textureBindings);

                var imageBindings = new TextureBindingInfo[info.Images.Count];

                for (int index = 0; index < info.Images.Count; index++)
                {
                    var descriptor = info.Images[index];

                    Target target = ShaderTexture.GetTarget(descriptor.Type);
                    Format format = ShaderTexture.GetFormat(descriptor.Format);

                    imageBindings[index] = new TextureBindingInfo(
                        target,
                        format,
                        descriptor.Binding,
                        descriptor.CbufSlot,
                        descriptor.HandleIndex,
                        descriptor.Flags);
                }

                _channel.TextureManager.SetGraphicsImages(stage, imageBindings);

                _channel.BufferManager.SetGraphicsStorageBufferBindings(stage, info.SBuffers);
                _channel.BufferManager.SetGraphicsUniformBufferBindings(stage, info.CBuffers);

                if (info.SBuffers.Count != 0)
                {
                    storageBufferBindingsCount = Math.Max(storageBufferBindingsCount, info.SBuffers.Max(x => x.Binding) + 1);
                }

                if (info.CBuffers.Count != 0)
                {
                    uniformBufferBindingsCount = Math.Max(uniformBufferBindingsCount, info.CBuffers.Max(x => x.Binding) + 1);
                }
            }

            _channel.BufferManager.SetGraphicsStorageBufferBindingsCount(storageBufferBindingsCount);
            _channel.BufferManager.SetGraphicsUniformBufferBindingsCount(uniformBufferBindingsCount);

            _context.Renderer.Pipeline.SetProgram(gs.HostProgram);
        }