This commit is contained in:
2025-04-13 00:43:33 +02:00
parent 63b336783b
commit e7f1c877e0
13 changed files with 225 additions and 3 deletions

37
Sources/Backends/D3D11/D3D11.c git.filemode.normal_file
View File

@@ -0,0 +1,37 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#include "../../PulseInternal.h"
#include "D3D11.h"
#include "D3D11Device.h"
PulseBackendFlags PuD3D11CheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used)
{
if(candidates != PULSE_BACKEND_ANY && (candidates & PULSE_BACKEND_D3D11) == 0)
return PULSE_BACKEND_INVALID;
if((shader_formats_used & PULSE_SHADER_FORMAT_DXBC_BIT) == 0)
return PULSE_BACKEND_INVALID;
return PULSE_BACKEND_D3D11;
}
bool PuD3D11LoadBackend(PulseBackend backend, PulseDebugLevel debug_level)
{
return true;
}
void PuD3D11UnloadBackend(PulseBackend backend)
{
}
PulseBackendHandler D3D11Driver = {
.PFN_LoadBackend = PuD3D11LoadBackend,
.PFN_UnloadBackend = PuD3D11UnloadBackend,
.PFN_CreateDevice = PuD3D11CreateDevice,
.backend = PULSE_BACKEND_D3D11,
.supported_shader_formats = PULSE_SHADER_FORMAT_DXBC_BIT,
.driver_data = PULSE_NULLPTR
};

21
Sources/Backends/D3D11/D3D11.h git.filemode.normal_file
View File

@@ -0,0 +1,21 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#ifdef PULSE_ENABLE_D3D11_BACKEND
#ifndef PULSE_D3D11_H_
#define PULSE_D3D11_H_
#include <d3d11.h>
#include <dxgi.h>
#include "../../PulseInternal.h"
#define D3D11_RETRIEVE_DRIVER_DATA_AS(handle, cast) ((cast)handle->driver_data)
PulseBackendFlags PuD3D11CheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used); // Return PULSE_BACKEND_D3D11 in case of success and PULSE_BACKEND_INVALID otherwise
#endif // PULSE_D3D11_H_
#endif // PULSE_ENABLE_D3D11_BACKEND

61
Sources/Backends/D3D11/D3D11Device.c git.filemode.normal_file
View File

@@ -0,0 +1,61 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#include <stdio.h>
#include "../../PulseInternal.h"
#include "D3D11.h"
#include "D3D11Device.h"
bool PuD3D11IsDedicatedAdapter(IDXGIAdapter1* adapter)
{
DXGI_ADAPTER_DESC1 desc;
if(FAILED(adapter->lpVtbl->GetDesc1(adapter, &desc)))
return false;
bool has_dedicated_memory = desc.DedicatedVideoMemory > 0;
bool is_software_adapter = wcsstr(desc.Description, L"Microsoft Basic Render") != PULSE_NULLPTR;
// Known vendor IDs
const uint32_t NVIDIA = 0x10DE;
const uint32_t AMD = 0x1002;
bool is_known_vendor = (desc.VendorId == NVIDIA || desc.VendorId == AMD);
return has_dedicated_memory && is_known_vendor && !is_software_adapter;
}
static uint64_t PuD3D11ScoreAdapter(ID3D11Device* device, IDXGIAdapter1* adapter)
{
}
PulseDevice PuD3D11CreateDevice(PulseBackend backend, PulseDevice* forbiden_devices, uint32_t forbiden_devices_count)
{
PULSE_CHECK_HANDLE_RETVAL(backend, PULSE_NULLPTR);
PulseDevice pulse_device = (PulseDeviceHandler*)calloc(1, sizeof(PulseDeviceHandler));
PULSE_CHECK_ALLOCATION_RETVAL(pulse_device, PULSE_NULL_HANDLE);
D3D11Device* device = (D3D11Device*)calloc(1, sizeof(D3D11Device));
PULSE_CHECK_ALLOCATION_RETVAL(device, PULSE_NULL_HANDLE);
pulse_device->driver_data = device;
pulse_device->backend = backend;
CreateDXGIFactory1(&IID_IDXGIFactory, (void**)&device->factory);
for(uint32_t i = 0; device->factory->lpVtbl->EnumAdapters1(device->factory, i, &device->adapter) != DXGI_ERROR_NOT_FOUND; i++)
{
DXGI_ADAPTER_DESC1 desc;
device->adapter->lpVtbl->GetDesc1(device->adapter, &desc);
device->adapter->lpVtbl->Release(device->adapter);
}
device->factory->lpVtbl->Release(device->factory);
return pulse_device;
}
void PuD3D11DestroyDevice(PulseDevice device)
{
}

26
Sources/Backends/D3D11/D3D11Device.h git.filemode.normal_file
View File

@@ -0,0 +1,26 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#ifdef PULSE_ENABLE_D3D11_BACKEND
#ifndef PULSE_D3D11_DEVICE_H_
#define PULSE_D3D11_DEVICE_H_
#include <Pulse.h>
#include "D3D11.h"
typedef struct D3D11Device
{
ID3D11Device* device;
ID3D11DeviceContext* context;
IDXGIFactory1* factory;
IDXGIAdapter1* adapter;
} D3D11Device;
PulseDevice PuD3D11CreateDevice(PulseBackend backend, PulseDevice* forbiden_devices, uint32_t forbiden_devices_count);
void PuD3D11DestroyDevice(PulseDevice device);
#endif // PULSE_D3D11_DEVICE_H_
#endif // PULSE_ENABLE_D3D11_BACKEND