Skip to content

Commit 3556404

Browse files
committed
rework bindings
1 parent 16550d4 commit 3556404

File tree

9 files changed

+260
-277
lines changed

9 files changed

+260
-277
lines changed

sources/include/cage-core/assetContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ namespace cage
2929
Holder<PointerRange<char>> compressedData;
3030
Holder<PointerRange<char>> originalData;
3131
Holder<void> assetHolder;
32+
const AssetsManager *const assetsManager = nullptr;
3233
const uint32 assetId = 0;
3334
uint32 scheme = m;
3435

35-
AssetContext(uint32 assetId) : assetId(assetId) {}
36+
AssetContext(AssetsManager *assetsManager, uint32 assetId) : assetsManager(assetsManager), assetId(assetId) {}
3637
};
3738
}
3839

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef guard_graphicsBindings_esdr41ttzu
2+
#define guard_graphicsBindings_esdr41ttzu
3+
4+
#include <webgpu/webgpu_cpp.h>
5+
6+
#include <cage-engine/core.h>
7+
8+
namespace cage
9+
{
10+
class GraphicsDevice;
11+
class Texture;
12+
class GpuBuffer;
13+
class Model;
14+
15+
struct CAGE_ENGINE_API GpuBindings
16+
{
17+
wgpu::BindGroupLayout layout = {};
18+
wgpu::BindGroup group = {};
19+
20+
operator bool() const
21+
{
22+
CAGE_ASSERT(!!layout == !!group);
23+
return !!layout;
24+
}
25+
};
26+
27+
struct CAGE_ENGINE_API BindingsCreateConfig
28+
{
29+
struct TextureConfig
30+
{
31+
Texture *texture = nullptr;
32+
uint32 binding = m;
33+
};
34+
std::vector<TextureConfig> textures;
35+
36+
struct BufferConfig
37+
{
38+
GpuBuffer *buffer = nullptr;
39+
uint32 binding = m;
40+
uint32 offset = 0;
41+
uint32 size = m;
42+
};
43+
std::vector<BufferConfig> buffers;
44+
};
45+
46+
CAGE_ENGINE_API GpuBindings newGpuBindings(GraphicsDevice *device, const BindingsCreateConfig &config);
47+
48+
CAGE_ENGINE_API void prepareModelBindings(GraphicsDevice *device, const AssetsManager *assets, Model *model);
49+
}
50+
51+
#endif

sources/include/cage-engine/graphicsEncoder.h

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
#include <optional>
66
#include <vector>
77

8-
#include <cage-engine/core.h>
8+
#include <cage-engine/graphicsBindings.h>
99

10+
/*
1011
namespace wgpu
1112
{
1213
class CommandEncoder;
1314
class RenderPassEncoder;
1415
}
16+
*/
1517

1618
namespace cage
1719
{
@@ -21,28 +23,7 @@ namespace cage
2123
class Shader;
2224
class Model;
2325

24-
struct CAGE_ENGINE_API BindingsConfig
25-
{
26-
struct TextureConfig
27-
{
28-
Texture *texture = nullptr;
29-
uint32 shaderSet = m;
30-
uint32 shaderBinding = m;
31-
};
32-
std::vector<TextureConfig> textures;
33-
34-
struct BufferConfig
35-
{
36-
GpuBuffer *buffer = nullptr;
37-
uint32 shaderSet = m;
38-
uint32 shaderBinding = m;
39-
uint32 offset = 0;
40-
uint32 size = m;
41-
};
42-
std::vector<BufferConfig> buffers;
43-
};
44-
45-
struct CAGE_ENGINE_API PassConfig : public BindingsConfig
26+
struct CAGE_ENGINE_API PassConfig
4627
{
4728
struct ColorTargetConfig
4829
{
@@ -60,20 +41,19 @@ namespace cage
6041
};
6142
std::optional<DepthTargetConfig> depthTarget;
6243

63-
const char *label = nullptr;
44+
GpuBindings bindings; // binds to set = 0
45+
46+
char *label = nullptr;
6447
};
6548

66-
struct CAGE_ENGINE_API DrawConfig : public BindingsConfig
49+
struct CAGE_ENGINE_API DrawConfig
6750
{
6851
Shader *shader = nullptr;
69-
Model *model = nullptr;
70-
52+
Model *model = nullptr; // material binds to set = 1
53+
GpuBindings bindings; // binds to set = 2
7154
uint32 instances = 1;
7255
};
7356

74-
// fills in all textures and material buffer from the model, using shader set = 1, and also fills in the shader
75-
CAGE_ENGINE_API DrawConfig prepareDrawConfig(const AssetsManager *assets, Model *model, uint32 shaderKeywords = 0);
76-
7757
class CAGE_ENGINE_API GraphicsEncoder : private Immovable
7858
{
7959
public:

sources/include/cage-engine/model.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace cage
1818
class GraphicsDevice;
1919
class GpuBuffer;
2020
enum class MeshRenderFlags : uint32;
21+
struct GpuBindings;
2122

2223
enum class MeshComponentsFlags : uint32
2324
{
@@ -39,6 +40,7 @@ namespace cage
3940

4041
void updateLayout();
4142
const wgpu::VertexBufferLayout &getLayout() const;
43+
GpuBindings &bindings();
4244

4345
// general
4446
Mat4 importTransform;

0 commit comments

Comments
 (0)