Toast Engine
Loading...
Searching...
No Matches
shader_reflection.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
7#include <cstdint>
8#include <nlohmann/json.hpp>
9#include <optional>
10#include <slang.h>
11#include <string>
12#include <toast/export.hpp>
13#include <vector>
14
15namespace renderer {
16
17enum class ShaderMemberType : uint8_t {
18 unknown,
19 bool_t,
20 int_t,
21 uint_t,
22 float_t,
23 vec2,
24 vec3,
25 vec4,
26 mat3,
27 mat4,
28};
29
30enum class ShaderBindingKind : uint8_t {
31 uniform_buffer,
32 storage_buffer,
33 combined_image_sampler,
34 sampled_image,
35 sampler,
36 storage_image,
37 acceleration_structure,
38};
39
41 bool reflected = false;
42 std::optional<float> range_min;
43 std::optional<float> range_max;
44 bool is_color = false;
45 std::string display_name;
46 std::string group;
47 std::string subgroup;
48 std::string unit;
49 std::string default_fallback; // "white" "black" or "flat_normal"
50 bool linear_data = false;
51};
52
54 std::string name;
55 ShaderMemberType type = ShaderMemberType::unknown;
56 uint32_t offset = 0;
57 uint32_t size = 0;
58 uint32_t element_count = 0;
59 uint32_t element_stride = 0;
60 std::string engine_semantic;
61 ShaderInspectorMeta inspector;
62};
63
65 uint32_t set = 0;
66 uint32_t binding = 0;
67 std::string name;
68 ShaderBindingKind kind = ShaderBindingKind::uniform_buffer;
69 uint32_t count = 1;
70 uint32_t size = 0;
71 std::vector<ShaderBlockMember> members;
72 std::string engine_semantic; // "frame" for engine reserved set 0
73 ShaderInspectorMeta inspector;
74};
75
77 std::string name;
78 uint32_t size = 0;
79 std::vector<ShaderBlockMember> members;
80};
81
83 std::string name;
84 std::string stage; // "vertex" "fragment" or "compute"
85};
86
88 std::vector<ShaderEntryPoint> entry_points;
89 std::vector<ShaderBinding> bindings;
90 std::vector<ShaderPushConstants> push_constants;
91 std::vector<std::string> layout_order;
92
93 [[nodiscard]]
94 auto TOAST_API toJson() const -> nlohmann::json;
95
96 static auto TOAST_API fromJson(const nlohmann::json& json) -> std::optional<ShaderReflection>;
97};
98
99auto extractReflection(slang::ProgramLayout* layout) -> ShaderReflection;
100
102void extractModuleEntryPoints(slang::IModule* module, ShaderReflection& reflection);
103
104auto toString(ShaderMemberType type) -> std::string_view;
105auto toString(ShaderBindingKind kind) -> std::string_view;
106auto memberTypeFromString(std::string_view str) -> ShaderMemberType;
107auto bindingKindFromString(std::string_view str) -> ShaderBindingKind;
108
109}
void extractModuleEntryPoints(slang::IModule *module, ShaderReflection &reflection)
Must come from the IModule since ProgramLayout reports 0 entry points for a module only composite.
Definition shader_reflection.cpp:224
Definition shader_reflection.hpp:64
Definition shader_reflection.hpp:53
Definition shader_reflection.hpp:82
Definition shader_reflection.hpp:40
Definition shader_reflection.hpp:76
Definition shader_reflection.hpp:87