Skip to content

Commit 68c0e22

Browse files
mucbucmucbuc
andauthored
Dev bindgroup set (#22)
* rm dawn again * add dawn * dawn/.gitignore * rm dawn * add dawn without .gitignore * add lib dawn without gitignore file * rm fucking dawn * dawn without .gitignore * fetch dawn * invoke fetch_dawn * fix up fetch_dawn with cmake * ignore lib/dawn * try cache build folder * try cache dawn instead * try to cache dawn build folder * dont remove build folder * move bindgroup factory method into bindgroup layout * try vendoring dawn code * try to fetch deps * disable fetch from cmake * vendor dawn code * update dawn fetch script * cleanup --------- Co-authored-by: mucbuc <mucbuc@mucbucs-Mac-mini-2.local>
1 parent 3273716 commit 68c0e22

13 files changed

Lines changed: 51 additions & 36 deletions

‎.github/workflows/build.yml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ jobs:
1616
- name: Checkout repository
1717
uses: actions/checkout@v4
1818

19+
- name: Cache Build Folder
20+
uses: actions/cache@v4
21+
with:
22+
path: |
23+
lib/dawn
24+
test/build/lib/dawn_wrapper/lib/dawn
25+
key: ${{ runner.os }}-build-${{ hashFiles('lib/fetch_dawn.sh') }}
26+
restore-keys: |
27+
${{ runner.os }}-build-
28+
1929
- name: Build and run
2030
run: |
2131
cd test
22-
rm -rf build
2332
./build_and_run
2433

‎lib/fetch_dawn.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22

3+
#version bumper1
34

45
if [ ! -d "dawn" ]; then
56
git clone --depth 1 --branch chromium/7780 https://dawn.googlesource.com/dawn

‎src/bindgroup_layout_wrapper.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <memory>
44

55
#include "bindgroup_layout_wrapper_impl.hpp"
6+
#include "bindgroup_wrapper_impl.hpp"
67

78
struct GLFWwindow;
89

@@ -54,4 +55,9 @@ bindgroup_layout_wrapper& bindgroup_layout_wrapper::add_sampler(unsigned binding
5455
return *this;
5556
}
5657

58+
bindgroup_wrapper bindgroup_layout_wrapper::make_bindgroup()
59+
{
60+
return std::make_shared<bindgroup_wrapper::pimpl>(* this, m_pimpl->m_context_name);
61+
}
62+
5763
} // dawn_wrapper

‎src/bindgroup_layout_wrapper_impl.hpp‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ using namespace wgpu;
77
namespace dawn_wrapper {
88

99
struct bindgroup_layout_wrapper::pimpl {
10-
pimpl(ShaderStage stage)
10+
pimpl(ShaderStage stage, std::string context_name)
1111
: m_stage(stage)
12+
, m_layoutEntries()
13+
, m_bindGroupLayout()
14+
, m_context_name(context_name)
1215
{
1316
}
1417

@@ -61,6 +64,15 @@ struct bindgroup_layout_wrapper::pimpl {
6164
}
6265
}
6366

67+
BindGroupLayout make_bindGroupLayout(Device device, std::string label)
68+
{
69+
if (!m_bindGroupLayout) {
70+
m_bindGroupLayout = dawn_utils::make_bindGroupLayout(device, m_layoutEntries, label.c_str());
71+
}
72+
return m_bindGroupLayout;
73+
}
74+
75+
6476
BindGroupLayoutEntry make_texture_layout_entry(unsigned binding, TextureSampleType type = TextureSampleType::Float, TextureViewDimension dimension = TextureViewDimension::e1D)
6577
{
6678

@@ -96,6 +108,8 @@ struct bindgroup_layout_wrapper::pimpl {
96108

97109
ShaderStage m_stage;
98110
std::vector<BindGroupLayoutEntry> m_layoutEntries;
111+
BindGroupLayout m_bindGroupLayout;
112+
std::string m_context_name;
99113
};
100114

101115
}

‎src/bindgroup_wrapper_impl.hpp‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "buffer_wrapper_impl.hpp"
44
#include "texture_output_wrapper_impl.hpp"
55
#include "texture_wrapper_impl.hpp"
6+
#include "bindgroup_layout_wrapper_impl.hpp"
67

78
using namespace wgpu;
89

@@ -54,25 +55,28 @@ struct bindgroup_wrapper::pimpl {
5455
}
5556
}
5657

57-
BindGroup make_bindgroup(Device device, BindGroupLayout layout)
58+
BindGroup make_bindgroup(Device device)
5859
{
5960
if (!m_bindgroup) {
61+
auto layout = m_layout.m_pimpl->make_bindGroupLayout(device, m_context_name.c_str());
6062
m_bindgroup = dawn_utils::make_bindGroup(device, layout, m_bindgroup_entries, m_context_name.c_str());
6163
}
6264
return m_bindgroup;
6365
}
6466

65-
pimpl(std::string context_name)
67+
pimpl(bindgroup_layout_wrapper layout, std::string context_name)
6668
: m_bindgroup_entries()
6769
, m_context_name(context_name)
6870
, m_bindgroup()
71+
, m_layout(layout)
6972
{
7073
}
7174

7275
private:
7376
std::vector<BindGroupEntry> m_bindgroup_entries;
7477
std::string m_context_name;
7578
BindGroup m_bindgroup;
79+
bindgroup_layout_wrapper m_layout;
7680
};
7781

7882
}

‎src/compute_wrapper.cpp‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ bindgroup_layout_wrapper compute_wrapper::make_bindgroup_layout()
3232
return m_pimpl->make_bindgroup_layout();
3333
}
3434

35-
bindgroup_wrapper compute_wrapper::make_bindgroup()
36-
{
37-
return m_pimpl->make_bindgroup();
38-
}
39-
4035
bool compute_wrapper::is_valid() const
4136
{
4237
return m_pimpl ? true : false;

‎src/compute_wrapper_impl.hpp‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct compute_wrapper::pimpl : private shader_base {
3232

3333
void init_pipeline(bindgroup_layout_wrapper layout)
3434
{
35-
m_bindGroupLayout = dawn_utils::make_bindGroupLayout(m_device, layout.m_pimpl->m_layoutEntries, m_entryPoint.c_str());
35+
m_bindGroupLayout = layout.m_pimpl->make_bindGroupLayout(m_device, m_entryPoint.c_str());
3636
m_pipeline = dawn_utils::make_compute_pipeline(m_device, m_shader, m_bindGroupLayout, m_entryPoint.c_str());
3737
}
3838

@@ -44,7 +44,7 @@ struct compute_wrapper::pimpl : private shader_base {
4444

4545
auto computePass = dawn_utils::begin_compute_pass(encoder.m_pimpl->m_encoder);
4646
computePass.SetPipeline(get_pipeline());
47-
computePass.SetBindGroup(0, bindGroup.m_pimpl->make_bindgroup(m_device, m_bindGroupLayout), 0, nullptr);
47+
computePass.SetBindGroup(0, bindGroup.m_pimpl->make_bindgroup(m_device), 0, nullptr);
4848
computePass.DispatchWorkgroups(width, height, 1);
4949
computePass.End();
5050

@@ -63,12 +63,7 @@ struct compute_wrapper::pimpl : private shader_base {
6363

6464
bindgroup_layout_wrapper make_bindgroup_layout()
6565
{
66-
return std::make_shared<bindgroup_layout_wrapper::pimpl>(ShaderStage::Compute);
67-
}
68-
69-
bindgroup_wrapper make_bindgroup()
70-
{
71-
return std::make_shared<bindgroup_wrapper::pimpl>(m_entryPoint);
66+
return std::make_shared<bindgroup_layout_wrapper::pimpl>(ShaderStage::Compute, m_entryPoint);
7267
}
7368

7469
Device m_device;

‎src/dawn_wrapper.hpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct texture_output_wrapper {
6060
DAWN_WRAPPER_PIMPL_DEC(texture_output_wrapper);
6161
};
6262

63+
struct bindgroup_wrapper;
6364
struct bindgroup_layout_wrapper {
6465
bindgroup_layout_wrapper() = default;
6566
bindgroup_layout_wrapper& add_buffer(unsigned binding, bool enable = true);
@@ -69,11 +70,13 @@ struct bindgroup_layout_wrapper {
6970
bindgroup_layout_wrapper& add_texture_2d(unsigned binding, bool enable = true);
7071
bindgroup_layout_wrapper& add_storage_texture_2d(unsigned binding, bool enable = true);
7172
bindgroup_layout_wrapper& add_sampler(unsigned binding, bool enable = true);
73+
bindgroup_wrapper make_bindgroup();
7274
DAWN_WRAPPER_PIMPL_DEC(bindgroup_layout_wrapper);
7375
};
7476

7577
struct bindgroup_wrapper {
76-
bindgroup_wrapper() = default;
78+
bindgroup_wrapper() = delete;//default;
79+
bindgroup_wrapper(bindgroup_layout_wrapper);
7780
bindgroup_wrapper& add_buffer(unsigned binding, buffer_wrapper);
7881
bindgroup_wrapper& add_texture(unsigned binding, texture_wrapper);
7982
bindgroup_wrapper& add_texture(unsigned binding, texture_output_wrapper);
@@ -91,7 +94,6 @@ struct compute_wrapper {
9194
bool compute(bindgroup_wrapper, unsigned width, unsigned height, encoder_wrapper encoder);
9295
void setup_compute(unsigned width, unsigned height);
9396
bindgroup_layout_wrapper make_bindgroup_layout();
94-
bindgroup_wrapper make_bindgroup();
9597
bool is_valid() const;
9698
DAWN_WRAPPER_PIMPL_DEC(compute_wrapper);
9799
};
@@ -116,7 +118,6 @@ struct render_wrapper {
116118
void render(bindgroup_wrapper, encoder_wrapper);
117119
void render(encoder_wrapper);
118120
bindgroup_layout_wrapper make_bindgroup_layout();
119-
bindgroup_wrapper make_bindgroup();
120121
void init_pipeline(bindgroup_layout_wrapper);
121122
void init_pipeline();
122123
bool is_valid() const;

‎src/render_wrapper.cpp‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ bindgroup_layout_wrapper render_wrapper::make_bindgroup_layout()
2828
return m_pimpl->make_bindgroup_layout();
2929
}
3030

31-
bindgroup_wrapper render_wrapper::make_bindgroup()
32-
{
33-
return m_pimpl->make_bindgroup();
34-
}
35-
3631
void render_wrapper::init_pipeline(bindgroup_layout_wrapper layout)
3732
{
3833
m_pimpl->init_pipeline(layout);

‎src/render_wrapper_impl.hpp‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct render_wrapper::pimpl : private shader_base {
6161
auto pass = dawn_utils::begin_render_pass(encoder.m_pimpl->m_encoder, textureView);
6262
pass.SetPipeline(get_pipeline());
6363

64-
auto bindGroupImpl = bindGroup.m_pimpl->make_bindgroup(m_device, m_bindGroupLayout);
64+
auto bindGroupImpl = bindGroup.m_pimpl->make_bindgroup(m_device);
6565
pass.SetBindGroup(0, bindGroupImpl);
6666

6767
pass.SetVertexBuffer(0, get_bufferVertex(), 0, get_bufferVertex().GetSize());
@@ -93,12 +93,7 @@ struct render_wrapper::pimpl : private shader_base {
9393

9494
bindgroup_layout_wrapper make_bindgroup_layout()
9595
{
96-
return std::make_shared<bindgroup_layout_wrapper::pimpl>(ShaderStage::Fragment);
97-
}
98-
99-
bindgroup_wrapper make_bindgroup()
100-
{
101-
return std::make_shared<bindgroup_wrapper::pimpl>(m_entryPoint);
96+
return std::make_shared<bindgroup_layout_wrapper::pimpl>(ShaderStage::Fragment, m_entryPoint);
10297
}
10398

10499
void compile_shader(std::string script, std::string entryPoint)
@@ -112,7 +107,7 @@ struct render_wrapper::pimpl : private shader_base {
112107
{
113108
ASSERT(m_shader);
114109

115-
m_bindGroupLayout = dawn_utils::make_bindGroupLayout(m_device, layout.m_pimpl->m_layoutEntries, m_entryPoint.c_str());
110+
m_bindGroupLayout = layout.m_pimpl->make_bindGroupLayout(m_device, m_entryPoint.c_str());
116111
m_pipeline = dawn_utils::make_render_pipeline(m_device, m_bindGroupLayout, m_shader, m_vertexShader, m_entryPoint.c_str());
117112
}
118113

0 commit comments

Comments
 (0)