UraniumCompute 0.1.0
A GPU accelerated parallel task scheduler
IDeviceFactory.h
1#pragma once
2#include <UnCompute/Acceleration/AdapterInfo.h>
3#include <UnCompute/Memory/Object.h>
4#include <UnCompute/Utils/DynamicLibrary.h>
5#include <UnCompute/Containers/ArraySlice.h>
6
7namespace UN
8{
10 enum class BackendKind
11 {
12 Cpu,
13 Vulkan
15 };
16
19 {
20 const char* ApplicationName;
21
22 inline explicit DeviceFactoryDesc(const char* applicationName)
23 : ApplicationName(applicationName)
24 {
25 }
26 };
27
28 class IKernelCompiler;
29 class IComputeDevice;
30 struct ComputeDeviceDesc;
31
33 class IDeviceFactory : public IObject
34 {
35 public:
41 virtual ResultCode Init(const DeviceFactoryDesc& desc) = 0;
42
44 virtual void Reset() = 0;
45
47 [[nodiscard]] virtual BackendKind GetBackendKind() const = 0;
48
51
57 virtual ResultCode CreateDevice(IComputeDevice** ppDevice) = 0;
58
64 virtual ResultCode CreateKernelCompiler(IKernelCompiler** ppCompiler) = 0;
65 };
66
67 inline constexpr const char* CreateDeviceFactoryProcName = "CreateDeviceFactoryImpl";
68 inline constexpr const char* UraniumComputeDllName = "UnCompute";
69
70 extern "C"
71 {
72 typedef ResultCode (*CreateDeviceFactoryProc)(BackendKind backendKind, IDeviceFactory** ppDeviceFactory);
73 }
74
80 inline ResultCode LoadCreateDeviceFactoryProc(DynamicLibrary** ppLibrary, CreateDeviceFactoryProc* pCreateDeviceFactoryProc)
81 {
82 // TODO: this function requires us to add DynamicLibrary.h include here which requires to include windows.h
83 // and it's not desired. We can possibly create another STATIC library in the future dedicated for
84 // DynamicLibrary class to avoid including platform headers.
85
86 auto resultCode = DynamicLibrary::Create(ppLibrary);
87 if (Failed(resultCode))
88 {
89 return resultCode;
90 }
91
92 resultCode = (*ppLibrary)->Init(UraniumComputeDllName);
93 if (Failed(resultCode))
94 {
95 UN_Error(false, "Couldn't load {} library", UraniumComputeDllName);
96 return resultCode;
97 }
98
99 resultCode = (*ppLibrary)->GetFunction(CreateDeviceFactoryProcName, pCreateDeviceFactoryProc);
100 if (Failed(resultCode))
101 {
102 UN_Error(false,
103 "Couldn't get the entry point named \"{}\" in \"{}\" library",
104 CreateDeviceFactoryProcName,
105 UraniumComputeDllName);
106 return resultCode;
107 }
108
109 return resultCode;
110 }
111} // namespace UN
This class represents a non-owning slice of contiguously stored elements.
Definition: ArraySlice.h:12
Interface for all backend-specific compute devices.
Definition: IComputeDevice.h:38
This class is used to create backend-specific compute devices and related objects.
Definition: IDeviceFactory.h:34
virtual BackendKind GetBackendKind() const =0
Get kind of backend for the compute devices created by this factory.
virtual ArraySlice< const AdapterInfo > EnumerateAdapters()=0
Get all adapters supported by the specified backend.
virtual ResultCode CreateDevice(IComputeDevice **ppDevice)=0
Create a compute device.
virtual ResultCode Init(const DeviceFactoryDesc &desc)=0
Initialize the compute device factory.
virtual ResultCode CreateKernelCompiler(IKernelCompiler **ppCompiler)=0
Create a kernel compiler.
virtual void Reset()=0
Reset the compute device factory.
An interface for kernel compiler that is used for compiling compute shader source into backend's nati...
Definition: IKernelCompiler.h:74
Base interface for dynamic reference counted objects.
Definition: Object.h:8
IDeviceFactory descriptor.
Definition: IDeviceFactory.h:19
const char * ApplicationName
Name of the application.
Definition: IDeviceFactory.h:20