Exemplo n.º 1
0
        /// <summary>
        /// Set the vertex buffers
        /// </summary>
        /// <param name="vertexBuffers">The vertex buffers to set</param>
        /// <param name="startSlot">The slot on the device array to start setting vertex buffers to</param>
        /// <typeparam name="T">The type of the vertex in <see cref="VertexBuffer{TVertex}"/></typeparam>
        public void SetVertexBuffers <T>(ReadOnlySpan <VertexBuffer <T> > vertexBuffers, uint startSlot = 0)
            where T : unmanaged
        {
            Debug.Assert(StackSentinel.SafeToStackalloc <D3D12_VERTEX_BUFFER_VIEW>(vertexBuffers.Length));

            D3D12_VERTEX_BUFFER_VIEW *views = stackalloc D3D12_VERTEX_BUFFER_VIEW[vertexBuffers.Length];

            for (int i = 0; i < vertexBuffers.Length; i++)
            {
                views[i] = vertexBuffers[i].BufferView;
            }

            _list.Get()->IASetVertexBuffers(startSlot, (uint)vertexBuffers.Length, views);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="commandList"></param>
        /// <param name="color"></param>
        /// <param name="message"></param>
        public static void BeginEventOnCommandList(
            ID3D12GraphicsCommandList *commandList,
            Argb32 color,
            ReadOnlySpan <char> message
            )
        {
            var length = Utf8Length(message);
            var buff   = StackSentinel.SafeToStackalloc <byte>(length) ? stackalloc byte[length] : new byte[length];

            Encoding.UTF8.GetBytes(message, buff);

            var hr = _PIXBeginEventOnCommandList(commandList, Argb32.GetAs32BitArgb(color),
                                                 (byte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(buff)));

            Guard.ThrowIfFailed(hr);
        }
Exemplo n.º 3
0
        public override bool TryEnablePreferentialOrdering(DevicePreference preference)
        {
            DXCoreAdapterPreference *pPreferences = stackalloc DXCoreAdapterPreference[4];
            int i = 0;

            _softwareOnly = preference.HasFlag(DevicePreference.Software) && !preference.HasFlag(DevicePreference.Hardware);

            if (!TryAdd(DevicePreference.Hardware, DXCoreAdapterPreference.Hardware))
            {
                return(false);
            }
            if (!TryAdd(DevicePreference.LowPower, DXCoreAdapterPreference.MinimumPower))
            {
                return(false);
            }
            if (!TryAdd(DevicePreference.HighPerformance, DXCoreAdapterPreference.HighPerformance))
            {
                return(false);
            }

            Guard.ThrowIfFailed(_list.Ptr->Sort((uint)i, pPreferences));

            return(true);

            bool TryAdd(DevicePreference devicePref, DXCoreAdapterPreference dxCorePref)
            {
                if (!preference.HasFlag(devicePref))
                {
                    return(true);
                }

                if (!_list.Ptr->IsAdapterPreferenceSupported(dxCorePref))
                {
                    return(false);
                }

                StackSentinel.StackAssert(i < 4);
                pPreferences[i++] = dxCorePref;
                return(true);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Asynchronously makes <paramref name="evicted"/> resident on the device
        /// </summary>
        /// <typeparam name="T">The type of the evicted resourcse</typeparam>
        /// <param name="evicted">The <typeparamref name="T"/>s to make resident</param>
        /// <returns>A <see cref="GpuTask"/> that can be used to work out when the resource is resident</returns>
        public GpuTask MakeResidentAsync <T>(ReadOnlySpan <T> evicted) where T : IEvictable
        {
            if (DeviceLevel < SupportedDevice.Device3)
            {
                ThrowHelper.ThrowNotSupportedException(Error_CantMakeResidentAsync);
            }

            var newValue = Interlocked.Increment(ref _lastFenceSignal);

            // classes will never be blittable to pointer, so this handles that
            if (default(T)?.IsBlittableToPointer ?? false)
            {
                fixed(void *pEvictables = &Unsafe.As <T, byte>(ref MemoryMarshal.GetReference(evicted)))
                {
                    ThrowIfFailed(As <ID3D12Device3>()->EnqueueMakeResident(
                                      D3D12_RESIDENCY_FLAGS.D3D12_RESIDENCY_FLAG_DENY_OVERBUDGET,
                                      (uint)evicted.Length,
                                      (ID3D12Pageable **)pEvictables,
                                      _residencyFence.Ptr,
                                      newValue
                                      ));
                }
            }
            else
            {
                if (StackSentinel.SafeToStackallocPointers(evicted.Length))
                {
                    ID3D12Pageable **pEvictables = stackalloc ID3D12Pageable *[evicted.Length];
                    for (int i = 0; i < evicted.Length; i++)
                    {
                        pEvictables[i] = evicted[i].GetPageable();
                    }

                    ThrowIfFailed(As <ID3D12Device3>()->EnqueueMakeResident(
                                      D3D12_RESIDENCY_FLAGS.D3D12_RESIDENCY_FLAG_DENY_OVERBUDGET,
                                      (uint)evicted.Length,
                                      pEvictables,
                                      _residencyFence.Ptr,
                                      newValue
                                      ));
                }
                else
                {
                    using var pool = RentedArray <nuint> .Create(evicted.Length, PinnedArrayPool <nuint> .Default);

                    for (int i = 0; i < evicted.Length; i++)
                    {
                        pool.Value[i] = (nuint)evicted[i].GetPageable();
                    }

                    ThrowIfFailed(As <ID3D12Device3>()->EnqueueMakeResident(
                                      D3D12_RESIDENCY_FLAGS.D3D12_RESIDENCY_FLAG_DENY_OVERBUDGET,
                                      (uint)evicted.Length,
                                      (ID3D12Pageable **)Unsafe.AsPointer(ref MemoryMarshal.GetArrayDataReference(pool.Value)),
                                      _residencyFence.Ptr,
                                      newValue
                                      ));
                }
            }

            return(new GpuTask(this, _residencyFence, newValue));
        }