internal override bool TryGetAdapterByIndex(uint index, out Adapter adapter) { while (true) { using UniqueComPtr <IDXCoreAdapter> dxcoreAdapter = default; // Reached end of list if (_list.Ptr->GetAdapterCount() - (index + _hardwareAdapterSkip) == 0) { adapter = default; return(false); } Guard.ThrowIfFailed(_list.Ptr->GetAdapter(index, dxcoreAdapter.Iid, (void **)&dxcoreAdapter)); if (_softwareOnly) { bool isSoftware; Guard.ThrowIfFailed(dxcoreAdapter.Ptr->GetProperty(DXCoreAdapterProperty.IsHardware, sizeof(bool), &isSoftware)); if (!isSoftware) { _hardwareAdapterSkip++; continue; } } adapter = CreateAdapter(dxcoreAdapter.Move()); return(true); } }
public DxCoreDeviceFactory(DeviceType types = DeviceType.GraphicsAndCompute) { using UniqueComPtr <IDXCoreAdapterFactory> factory = default; using UniqueComPtr <IDXCoreAdapterList> list = default; Guard.ThrowIfFailed(DXCoreCreateAdapterFactory(factory.Iid, (void **)&factory)); const int MaxNumFilterAttributes = 2; Guid * filterAttributes = stackalloc Guid[MaxNumFilterAttributes]; uint i = 0; if (types.HasFlag(DeviceType.ComputeOnly)) { filterAttributes[i++] = DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE; } if (types.HasFlag(DeviceType.GraphicsAndCompute)) { filterAttributes[i++] = DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS; } Guard.ThrowIfFailed(factory.Ptr->CreateAdapterList(i, filterAttributes, list.Iid, (void **)&list)); _factory = factory.Move(); _list = list.Move(); }
internal override bool TryGetAdapterByIndex(uint index, out Adapter adapter) { // We only set this to true in TryOrderByPreference which checks we have IDXGIFactory6 so we can hard cast _factory if (_enumByPreference) { while (true) { using UniqueComPtr <IDXGIAdapter1> dxgiAdapter = default; Guard.ThrowIfFailed( _factory.Ptr->EnumAdapterByGpuPreference( index + _skipAdapterOffset, // DXGI preference doesn't allow preferring hardware/software adapters, so we do that manually after filtering out the other hardware types // We remove the hardware and software flag so DXGI doesn't complain (DXGI_GPU_PREFERENCE)(_preference & ~(DevicePreference.Hardware | DevicePreference.Software)), dxgiAdapter.Iid, (void **)&dxgiAdapter ) ); // null adapter means we have reached end of list if (!dxgiAdapter.Exists) { adapter = default; return(false); } // if it only supports hardware of software, we have to filter them out. If both or neither are set, we allow all adapters through if (_preference.HasFlag(DevicePreference.Hardware) != _preference.HasFlag(DevicePreference.Software)) { DXGI_ADAPTER_DESC1 desc; Guard.ThrowIfFailed(dxgiAdapter.Ptr->GetDesc1(&desc)); bool isHardware = (desc.Flags & (int)DXGI_ADAPTER_FLAG.DXGI_ADAPTER_FLAG_SOFTWARE) == 0; // If they want hardware but we don't have it, or they want software and we don't have it, skip this adapter if (_preference.HasFlag(DevicePreference.Hardware) != isHardware) { _skipAdapterOffset++; continue; } } adapter = CreateAdapter(dxgiAdapter.Move()); return(true); } } else { using UniqueComPtr <IDXGIAdapter1> dxgiAdapter = default; Guard.ThrowIfFailed(_factory.Ptr->EnumAdapters1(index, ComPtr.GetAddressOf(&dxgiAdapter))); adapter = CreateAdapter(dxgiAdapter.Move()); return(true); } }
public DxgiDeviceFactory() { using UniqueComPtr <IDXGIFactory6> factory = default; Guard.ThrowIfFailed(CreateDXGIFactory2(0, factory.Iid, (void **)&factory)); _factory = factory.Move(); _softwareAdapter = new(() => { using UniqueComPtr <IDXGIAdapter1> adapter = default; Guard.ThrowIfFailed(_factory.Ptr->EnumWarpAdapter(adapter.Iid, (void **)&adapter)); return(CreateAdapter(adapter.Move())); }); }
protected override UniqueComPtr <ID3D12CommandAllocator> Create(ExecutionContext context) { using UniqueComPtr <ID3D12CommandAllocator> allocator = default; _device.ThrowIfFailed(_device.DevicePointer->CreateCommandAllocator( (D3D12_COMMAND_LIST_TYPE)context, allocator.Iid, (void **)&allocator )); LogHelper.LogDebug($"New command allocator allocated (this is the #{_allocatorCount++} allocator)"); DebugHelpers.SetName(allocator.Ptr, $"Pooled allocator #{_allocatorCount}"); return(allocator.Move()); }
private protected static UniqueComPtr <IDXGIFactory2> CreateFactory() { using UniqueComPtr <IDXGIFactory2> factory = default; int hr = CreateDXGIFactory2(DXGI_CREATE_FACTORY_DEBUG, factory.Iid, (void **)&factory); if (hr == E_NOINTERFACE) { // we don't actually *need* IDXGIFactory2, we just need to do CreateSwapChain (rather than CreateSwapChainForHwnd etc) without it which is currently not implemented ThrowHelper.ThrowPlatformNotSupportedException("Platform does not support IDXGIFactory2, which is required"); } Guard.ThrowIfFailed(hr, "CreateDXGIFactory2(DXGI_CREATE_FACTORY_DEBUG, factory.Iid, (void**)&factory)"); return(factory.Move()); }
internal GpuResource( ComputeDevice device, UniqueComPtr <ID3D12Resource> resource, InternalAllocDesc *desc, ComputeAllocator?allocator, int heapIndex = -1 /* no relevant heap block */, HeapBlock block = default ) { _device = device; _value = resource.Move(); Desc = *desc; HeapIndex = heapIndex; Block = block; _allocator = allocator; }
/// <summary> /// Creates a new <see cref="RootSignature"/> from a <see cref="CompiledShader"/> /// </summary> /// <param name="device">The <see cref="ComputeDevice"/> used to create the root signature</param> /// <param name="rootSignatureShader"></param> /// <param name="deserialize"></param> /// <returns>A new <see cref="RootSignature"/></returns> internal static RootSignature Create(ComputeDevice device, CompiledShader rootSignatureShader, bool deserialize = false) { fixed(byte *pSignature = rootSignatureShader) { using UniqueComPtr <ID3D12RootSignature> rootSig = device.CreateRootSignature( 0 /* TODO: MULTI-GPU */, pSignature, (uint)rootSignatureShader.Length ); if (deserialize) { RootSignatureDeserializer.DeserializeSignature(device, pSignature, (int)rootSignatureShader.Length); } return(new RootSignature(rootSig.Move(), null, null)); } }
static unsafe ShaderManager() { UniqueComPtr <IDxcCompiler3> compiler = default; UniqueComPtr <IDxcUtils> utils = default; Guid clsid = CLSID_DxcCompiler; Guard.ThrowIfFailed(DxcCreateInstance(&clsid, compiler.Iid, (void **)&compiler)); clsid = CLSID_DxcLibrary; Guard.ThrowIfFailed(DxcCreateInstance(&clsid, utils.Iid, (void **)&utils)); Compiler = compiler.Move(); Utils = utils.Move(); DefaultDxcIncludeHandler = new DxcIncludeHandler(); DefaultDxcIncludeHandler.Init(Utils.Copy()); DefaultFxcIncludeHandler = new LegacyFxcIncludeHandler(); DefaultFxcIncludeHandler.Init(); }
protected override UniqueComPtr <ID3D12GraphicsCommandList> Create(ListCreationParams state) { using UniqueComPtr <ID3D12GraphicsCommandList> list = default; _device.ThrowIfFailed(_device.DevicePointer->CreateCommandList( 0, // TODO: MULTI-GPU state.Type, state.Allocator, state.Pso, list.Iid, (void **)&list )); LogHelper.LogDebug($"New command list allocated (this is the #{_listCount++} list)"); DebugHelpers.SetName(list.Ptr, $"Pooled list #{_listCount}"); // 'ManageRent' expects closed list _device.ThrowIfFailed(list.Ptr->Close()); return(list.Move()); }
internal PipelineStateObject(UniqueComPtr <ID3D12Object> pso) { Pointer = pso.Move(); }
internal Fence(UniqueComPtr <ID3D12Fence> fence) { _fence = fence.Move(); }