UraniumCompute 0.1.0
A GPU accelerated parallel task scheduler
IKernelCompiler.h
1#pragma once
2#include <UnCompute/Base/Byte.h>
3#include <UnCompute/Containers/HeapArray.h>
4#include <UnCompute/Memory/Object.h>
5
6namespace UN
7{
9 enum class KernelSourceLang
10 {
11 Hlsl
12 };
13
15 enum class KernelTargetLang
16 {
17 SpirV
18 };
19
22 {
23 const char* Name = nullptr;
24 KernelSourceLang SourceLang = KernelSourceLang::Hlsl;
25 KernelTargetLang TargetLang = KernelTargetLang::SpirV;
26
27 inline KernelCompilerDesc() = default;
28
29 inline explicit KernelCompilerDesc(const char* name, KernelSourceLang sourceLang = KernelSourceLang::Hlsl,
30 KernelTargetLang targetLang = KernelTargetLang::SpirV)
31 : Name(name)
32 , SourceLang(sourceLang)
33 , TargetLang(targetLang)
34 {
35 }
36 };
37
39 enum class CompilerOptimizationLevel
40 {
41 None,
42 O1,
43 O2,
44 O3,
45 Max = O3
46 };
47
50 {
51 const char* Name = nullptr;
52 const char* Value = nullptr;
53
54 CompilerDefinition() = default;
55
56 inline explicit CompilerDefinition(const char* name, const char* value = nullptr)
57 : Name(name)
58 , Value(value)
59 {
60 }
61 };
62
65 {
67 CompilerOptimizationLevel OptimizationLevel = CompilerOptimizationLevel::Max;
68 const char* EntryPoint = "main";
70 };
71
73 class IKernelCompiler : public IObject
74 {
75 public:
77
78 [[nodiscard]] virtual const DescriptorType& GetDesc() const = 0;
79
85 virtual ResultCode Init(const DescriptorType& desc) = 0;
86
93 virtual ResultCode Compile(const KernelCompilerArgs& args, HeapArray<Byte>* pResult) = 0;
94 };
95} // namespace UN
Fixed-size heap-allocated array.
Definition: HeapArray.h:14
An interface for kernel compiler that is used for compiling compute shader source into backend's nati...
Definition: IKernelCompiler.h:74
virtual ResultCode Init(const DescriptorType &desc)=0
Creates and initializes a kernel compiler.
virtual ResultCode Compile(const KernelCompilerArgs &args, HeapArray< Byte > *pResult)=0
Compile a compute kernel into target language.
Base interface for dynamic reference counted objects.
Definition: Object.h:8
Compiler #define descriptor.
Definition: IKernelCompiler.h:50
const char * Value
Value in #define NAME VALUE.
Definition: IKernelCompiler.h:52
const char * Name
Name in #define NAME VALUE.
Definition: IKernelCompiler.h:51
Kernel compiler arguments that define a single compilation.
Definition: IKernelCompiler.h:65
ArraySlice< const Byte > SourceCode
Compute shader source code in a high-level language, e.g. HLSL.
Definition: IKernelCompiler.h:66
const char * EntryPoint
Compute shader entry point.
Definition: IKernelCompiler.h:68
ArraySlice< CompilerDefinition > Definitions
Compiler definitions.
Definition: IKernelCompiler.h:69
CompilerOptimizationLevel OptimizationLevel
Compiler optimization level.
Definition: IKernelCompiler.h:67
Kernel compiler descriptor.
Definition: IKernelCompiler.h:22
const char * Name
Compiler debug name.
Definition: IKernelCompiler.h:23
KernelSourceLang SourceLang
Source code language.
Definition: IKernelCompiler.h:24
KernelTargetLang TargetLang
Target code language.
Definition: IKernelCompiler.h:25