wren
Vulkan-based game engine
Loading...
Searching...
No Matches
parser.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <cstdint>
4
#include <map>
5
#include <optional>
6
#include <span>
7
#include <spirv/1.2/spirv.hpp>
8
#include <string>
9
#include <vector>
10
11
namespace
wren::reflect
{
12
13
struct
SpvType
{
14
uint32_t
id
;
15
spv::Op
type
;
16
uint32_t
parent_type
;
17
18
std::optional<spv::StorageClass>
storage_class
;
19
};
20
21
struct
EntryPoint
{
22
spv::ExecutionModel
exeuction_model
;
23
std::string
name
;
24
};
25
26
using
spirv_t
= std::vector<uint32_t>;
27
28
class
Parser
{
29
public
:
30
Parser
(
spirv_t
spirv);
31
32
[[nodiscard]]
auto
entry_points
()
const
{
return
entry_points_; }
33
[[nodiscard]]
auto
op_names
()
const
{
return
op_names_; }
34
[[nodiscard]]
auto
types
()
const
{
return
types_; }
35
36
private
:
37
void
load_reflection_info();
38
39
auto
peek(spirv_t::iterator it) {
return
*(it + 1); }
40
41
static
auto
string_literal(
42
std::span<uint32_t>
const
& string_literal) -> std::string;
43
44
spirv_t
spirv;
45
46
uint32_t version = 0;
47
uint32_t generator_magic_number = 0;
48
uint32_t bound = 0;
49
50
std::vector<EntryPoint> entry_points_;
51
std::map<uint32_t, uint32_t> inputs;
52
std::map<uint32_t, std::string> op_names_;
53
std::vector<SpvType> types_;
54
};
55
56
inline
auto
to_string
(spv::ExecutionModel model) {
57
switch
(model) {
58
case
spv::ExecutionModelVertex:
59
return
"vertex"
;
60
case
spv::ExecutionModelTessellationControl:
61
return
"tessellation control"
;
62
case
spv::ExecutionModelTessellationEvaluation:
63
return
"tessellation evaluation"
;
64
case
spv::ExecutionModelGeometry:
65
return
"geometry"
;
66
case
spv::ExecutionModelFragment:
67
return
"fragment"
;
68
case
spv::ExecutionModelGLCompute:
69
return
"gl_compute"
;
70
case
spv::ExecutionModelKernel:
71
return
"kernel"
;
72
case
spv::ExecutionModelMax:
73
return
"unknown_max"
;
74
default
:
75
return
"unknown"
;
76
}
77
}
78
79
}
// namespace wren::reflect
wren::reflect::Parser
Definition
parser.hpp:28
wren::reflect::Parser::Parser
Parser(spirv_t spirv)
Definition
parser.cpp:15
wren::reflect::Parser::op_names
auto op_names() const
Definition
parser.hpp:33
wren::reflect::Parser::types
auto types() const
Definition
parser.hpp:34
wren::reflect::Parser::entry_points
auto entry_points() const
Definition
parser.hpp:32
wren::reflect
Definition
parser.hpp:11
wren::reflect::spirv_t
std::vector< uint32_t > spirv_t
Definition
parser.hpp:26
wren::reflect::to_string
auto to_string(spv::ExecutionModel model)
Definition
parser.hpp:56
wren::reflect::EntryPoint
Definition
parser.hpp:21
wren::reflect::EntryPoint::exeuction_model
spv::ExecutionModel exeuction_model
Definition
parser.hpp:22
wren::reflect::EntryPoint::name
std::string name
Definition
parser.hpp:23
wren::reflect::SpvType
Definition
parser.hpp:13
wren::reflect::SpvType::type
spv::Op type
Definition
parser.hpp:15
wren::reflect::SpvType::parent_type
uint32_t parent_type
Definition
parser.hpp:16
wren::reflect::SpvType::id
uint32_t id
Definition
parser.hpp:14
wren::reflect::SpvType::storage_class
std::optional< spv::StorageClass > storage_class
Definition
parser.hpp:18
wren_reflect
include
wren_reflect
parser.hpp
Generated by
1.10.0