Grindstone Game Engine
v0.2.0
An open source game engine and toolkit.
Toggle main menu visibility
Loading...
Searching...
No Matches
RenderGraphResourceRef.hpp
1
#pragma once
2
3
#include <vector>
4
#include <stdint.h>
5
6
namespace
Grindstone::Renderer {
7
using
PassId = uint16_t;
8
using
ResourceId = uint16_t;
9
const
PassId invalidPassId = std::numeric_limits<PassId>().max();
10
const
ResourceId invalidResourceId = std::numeric_limits<ResourceId>().max();
11
12
struct
RenderGraphResourceRef
{
13
uint16_t isBuffer : 1;
14
uint16_t resourceIndex : 15;
15
16
static_assert
(
sizeof
(uint16_t) == 2);
17
18
static
RenderGraphResourceRef
Buffer(uint16_t resourceIndex) {
19
return
{
20
.isBuffer = 1,
21
.resourceIndex = resourceIndex
22
};
23
}
24
25
static
RenderGraphResourceRef
Image(uint16_t resourceIndex) {
26
return
{
27
.isBuffer = 0,
28
.resourceIndex = resourceIndex
29
};
30
}
31
32
bool
IsBuffer()
const
{
33
return
isBuffer == 1;
34
}
35
36
bool
IsImage()
const
{
37
return
isBuffer == 0;
38
}
39
40
uint16_t GetResourceIndex()
const
{
41
return
resourceIndex;
42
}
43
44
bool
operator==(
const
RenderGraphResourceRef
& o)
const
{
45
return
46
(isBuffer == o.isBuffer) &&
47
(resourceIndex == o.resourceIndex);
48
}
49
};
50
51
struct
RenderGraphBuilderResourceRef
{
52
ResourceId isBuffer : 1;
53
ResourceId resourceIndex : 15;
54
PassId passIndex;
55
56
static_assert
(
sizeof
(ResourceId) == 2);
57
58
static
RenderGraphBuilderResourceRef
Invalid() {
59
return
{
60
.isBuffer = 0,
61
.resourceIndex =
static_cast<
uint16_t
>
(0xffff),
62
.passIndex = 0xffff
63
};
64
}
65
66
static
RenderGraphBuilderResourceRef
Buffer(ResourceId resourceIndex, PassId passIndex) {
67
return
{
68
.isBuffer = 1,
69
.resourceIndex = resourceIndex,
70
.passIndex = passIndex
71
};
72
}
73
74
static
RenderGraphBuilderResourceRef
Image(ResourceId resourceIndex, PassId passIndex) {
75
return
{
76
.isBuffer = 0,
77
.resourceIndex = resourceIndex,
78
.passIndex = passIndex
79
};
80
}
81
82
bool
IsInvalid()
const
{
83
return
resourceIndex >= 32767;
84
}
85
86
bool
IsBuffer()
const
{
87
return
isBuffer == 1;
88
}
89
90
bool
IsImage()
const
{
91
return
isBuffer == 0;
92
}
93
94
ResourceId GetResourceIndex()
const
{
95
return
resourceIndex;
96
}
97
98
PassId GetPassIndex()
const
{
99
return
passIndex;
100
}
101
102
RenderGraphBuilderResourceRef
FromPass(PassId newPassIndex)
const
{
103
return
{
104
.isBuffer = isBuffer,
105
.resourceIndex = resourceIndex,
106
.passIndex = newPassIndex
107
};
108
}
109
110
bool
IsSameResource(
const
RenderGraphBuilderResourceRef
& other)
const
{
111
return
112
isBuffer == other.isBuffer &&
113
resourceIndex == other.resourceIndex;
114
}
115
116
bool
operator==(
const
RenderGraphBuilderResourceRef
& o)
const
{
117
return
118
(isBuffer == o.isBuffer) &&
119
(resourceIndex == o.resourceIndex) &&
120
(passIndex == o.passIndex);
121
}
122
};
123
124
enum class
AccessType {
125
Read,
126
Write,
127
ReadWrite
128
};
129
130
struct
PassBufferDesc
{
131
RenderGraphBuilderResourceRef
ref;
132
AccessType accessType;
133
};
134
}
135
136
template
<>
137
struct
std::hash<Grindstone::Renderer::RenderGraphBuilderResourceRef> {
138
size_t
operator()(
const
Grindstone::Renderer::RenderGraphBuilderResourceRef
& h)
const
{
139
// Pack the bitfields + passIndex into a single integer to hash
140
uint32_t packed = (h.isBuffer << 15) | h.resourceIndex;
141
142
return
std::hash<uint64_t>{}(
143
(
static_cast<
uint64_t
>
(packed) << 16) | h.passIndex
144
);
145
}
146
};
Grindstone::Renderer::PassBufferDesc
Definition
RenderGraphResourceRef.hpp:130
Grindstone::Renderer::RenderGraphBuilderResourceRef
Definition
RenderGraphResourceRef.hpp:51
Grindstone::Renderer::RenderGraphResourceRef
Definition
RenderGraphResourceRef.hpp:12
sources
code
Common
Rendering
RenderGraphResourceRef.hpp
Generated by
1.17.0