Skip to content
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d1fcac9
rm dawn again
Apr 8, 2026
5453d5f
add dawn
Apr 8, 2026
2157bd1
dawn/.gitignore
Apr 8, 2026
7fc6c84
rm dawn
Apr 8, 2026
ed2aea7
add dawn without .gitignore
Apr 8, 2026
241a16e
add lib dawn without gitignore file
Apr 8, 2026
20e5186
rm fucking dawn
Apr 8, 2026
cc629b3
dawn without .gitignore
Apr 8, 2026
2ab7beb
fetch dawn
Apr 8, 2026
6de4c2a
invoke fetch_dawn
Apr 8, 2026
b639613
fix up fetch_dawn with cmake
Apr 8, 2026
fdd873c
ignore lib/dawn
Apr 8, 2026
3e5cad8
Merge remote-tracking branch 'origin/master' into try_cache
Apr 9, 2026
ace73c9
try cache build folder
Apr 9, 2026
c68713f
try cache dawn instead
Apr 9, 2026
eb12122
try to cache dawn build folder
Apr 9, 2026
898c27d
dont remove build folder
Apr 9, 2026
a3b4231
move bindgroup factory method into bindgroup layout
Apr 10, 2026
0fb4add
try vendoring dawn code
Apr 10, 2026
d0c7c05
try to fetch deps
Apr 10, 2026
7cdc1bf
disable fetch from cmake
Apr 10, 2026
f6593ad
vendor dawn code
Apr 10, 2026
7c6e35a
update dawn fetch script
Apr 10, 2026
3b5e82a
cleanup
Apr 10, 2026
20cb98a
Merge branch 'dev-vendor-dawn2' into dev_bindgroup_set
Apr 10, 2026
6b7cead
Merge remote-tracking branch 'origin/master' into dev_bindgroup_set
Apr 10, 2026
283e966
Merge remote-tracking branch 'origin/master' into dev_bindgroup_set
Apr 10, 2026
0d51e10
bindgroup set pass
Apr 10, 2026
4c78336
implement compute and render with bindgroup set
Apr 10, 2026
8e04a00
fix default ctor issue
Apr 10, 2026
e42939c
some cleanup, add assertions
Apr 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ set_target_properties(dawn_wrapper PROPERTIES
target_sources(dawn_wrapper PRIVATE
src/bindgroup_layout_wrapper.cpp
src/bindgroup_layout_wrapper_impl.hpp
src/bindgroup_set.cpp
src/bindgroup_set_impl.hpp
src/bindgroup_wrapper.cpp
src/bindgroup_wrapper_impl.hpp
src/buffer_wrapper.cpp
Expand Down
19 changes: 19 additions & 0 deletions src/bindgroup_set.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include <map>
#include <memory>

#include "bindgroup_set_impl.hpp"

namespace dawn_wrapper {
bindgroup_set::bindgroup_set(ptr_type ptr)
: m_pimpl(ptr)
{
}

bindgroup_set& bindgroup_set::add_bindgroup(bindgroup_wrapper bg, unsigned group)
{
m_pimpl->add_bindgroup(bg, group);
return *this;
}

} // dawn_wrapper
31 changes: 31 additions & 0 deletions src/bindgroup_set_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "buffer_wrapper_impl.hpp"
#include "texture_output_wrapper_impl.hpp"
#include "texture_wrapper_impl.hpp"

#include <map>
#include <string>

using namespace wgpu;

namespace dawn_wrapper {

struct bindgroup_set::pimpl {

void add_bindgroup(bindgroup_wrapper bg, unsigned group)
{
m_bindgroups[group] = bg;
}

pimpl(std::string context_name)
: m_bindgroups()
, m_context_name(context_name)
{
}

std::map<unsigned, bindgroup_wrapper> m_bindgroups;
std::string m_context_name;
};

}
9 changes: 7 additions & 2 deletions src/compute_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ void compute_wrapper::init_pipeline(bindgroup_layout_wrapper layout)
m_pimpl->init_pipeline(layout);
}

bool compute_wrapper::compute(bindgroup_wrapper bindGroup, unsigned width, unsigned height, encoder_wrapper encoder)
void compute_wrapper::compute(bindgroup_set set, unsigned width, unsigned height, encoder_wrapper encoder)
{
return m_pimpl->compute(bindGroup, width, height, encoder);
m_pimpl->compute(set, width, height, encoder);
}

void compute_wrapper::compute(bindgroup_wrapper bindGroup, unsigned width, unsigned height, encoder_wrapper encoder)
{
m_pimpl->compute(bindGroup, width, height, encoder);
}

bindgroup_layout_wrapper compute_wrapper::make_bindgroup_layout()
Expand Down
24 changes: 21 additions & 3 deletions src/compute_wrapper_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "bindgroup_layout_wrapper_impl.hpp"
#include "bindgroup_set_impl.hpp"
#include "bindgroup_wrapper_impl.hpp"
#include "buffer_wrapper_impl.hpp"
#include "dawn_utils.hpp"
Expand Down Expand Up @@ -36,19 +37,36 @@ struct compute_wrapper::pimpl : private shader_base {
m_pipeline = dawn_utils::make_compute_pipeline(m_device, m_shader, m_bindGroupLayout, m_entryPoint.c_str());
}

bool compute(bindgroup_wrapper bindGroup, unsigned width, unsigned height, encoder_wrapper encoder)
void compute(bindgroup_set set, unsigned width, unsigned height, encoder_wrapper encoder)
{
ASSERT(get_pipeline());
ASSERT(width < 65535);
ASSERT(height < 65535);

auto computePass = dawn_utils::begin_compute_pass(encoder.m_pimpl->m_encoder);
computePass.SetPipeline(get_pipeline());
computePass.SetBindGroup(0, bindGroup.m_pimpl->make_bindgroup(m_device), 0, nullptr);

for (auto entry : set.m_pimpl->m_bindgroups)
{
computePass.SetBindGroup(entry.first, entry.second.m_pimpl->make_bindgroup(m_device));
}

computePass.DispatchWorkgroups(width, height, 1);
computePass.End();
}

return false;

void compute(bindgroup_wrapper bindGroup, unsigned width, unsigned height, encoder_wrapper encoder)
{
ASSERT(get_pipeline());
ASSERT(width < 65535);
ASSERT(height < 65535);

auto computePass = dawn_utils::begin_compute_pass(encoder.m_pimpl->m_encoder);
computePass.SetPipeline(get_pipeline());
computePass.SetBindGroup(0, bindGroup.m_pimpl->make_bindgroup(m_device), 0, nullptr);
computePass.DispatchWorkgroups(width, height, 1);
computePass.End();
}

ComputePipeline get_pipeline()
Expand Down
24 changes: 17 additions & 7 deletions src/dawn_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ namespace dawn_wrapper {

#define DAWN_WRAPPER_PIMPL_DEC(class_name) \
private: \
friend class render_wrapper; \
friend class compute_wrapper; \
friend class dawn_plugin; \
friend class texture_wrapper; \
friend class texture_output_wrapper; \
friend class bindgroup_layout_wrapper; \
friend class bindgroup_set; \
friend class bindgroup_wrapper; \
friend class buffer_wrapper; \
friend class bindgroup_layout_wrapper; \
friend class compute_wrapper; \
friend class dawn_plugin; \
friend class encoder_wrapper; \
friend class render_wrapper; \
friend class surface_wrapper; \
friend class texture_output_wrapper; \
friend class texture_wrapper; \
struct pimpl; \
using ptr_type = std::shared_ptr<pimpl>; \
class_name(ptr_type); \
Expand Down Expand Up @@ -87,11 +88,19 @@ struct bindgroup_wrapper {
DAWN_WRAPPER_PIMPL_DEC(bindgroup_wrapper);
};

struct bindgroup_set {
bindgroup_set() = default;
bindgroup_set& add_bindgroup(bindgroup_wrapper bg, unsigned group);

DAWN_WRAPPER_PIMPL_DEC(bindgroup_set);
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.

struct compute_wrapper {
compute_wrapper() = default;
void init_pipeline(bindgroup_layout_wrapper layout);
void compile_shader(std::string script, std::string entryPoint);
bool compute(bindgroup_wrapper, unsigned width, unsigned height, encoder_wrapper encoder);
void compute(bindgroup_wrapper, unsigned width, unsigned height, encoder_wrapper encoder);
void compute(bindgroup_set, unsigned width, unsigned height, encoder_wrapper encoder);
void setup_compute(unsigned width, unsigned height);
bindgroup_layout_wrapper make_bindgroup_layout();
bool is_valid() const;
Expand All @@ -115,6 +124,7 @@ struct render_wrapper {
void compile_shader(std::string script, std::string entryPoint);
void set_surface(surface_wrapper);

void render(bindgroup_set, encoder_wrapper);
void render(bindgroup_wrapper, encoder_wrapper);
void render(encoder_wrapper);
bindgroup_layout_wrapper make_bindgroup_layout();
Expand Down
5 changes: 5 additions & 0 deletions src/render_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ void render_wrapper::init_pipeline()
m_pimpl->init_pipeline();
}

void render_wrapper::render(bindgroup_set set, encoder_wrapper encoder)
{
m_pimpl->render(set, encoder);
}

void render_wrapper::render(bindgroup_wrapper bindGroup, encoder_wrapper encoder)
{
m_pimpl->render(bindGroup, encoder);
Expand Down
27 changes: 27 additions & 0 deletions src/render_wrapper_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "bindgroup_layout_wrapper_impl.hpp"
#include "bindgroup_set_impl.hpp"
#include "bindgroup_wrapper_impl.hpp"
#include "encoder_wrapper_impl.hpp"
#include "shader_base.hpp"
Expand Down Expand Up @@ -50,6 +51,32 @@ struct render_wrapper::pimpl : private shader_base {
return m_surface.m_pimpl->getCurrentTextureView();
}

void render(bindgroup_set set, encoder_wrapper encoder)
{
ASSERT(m_bindGroupLayout);

auto textureView = getCurrentTextureView();
ASSERT(textureView);

auto pass = dawn_utils::begin_render_pass(encoder.m_pimpl->m_encoder, textureView);
pass.SetPipeline(get_pipeline());

for (auto entry : set.m_pimpl->m_bindgroups)
{
pass.SetBindGroup(entry.first, entry.second.m_pimpl->make_bindgroup(m_device));
}
Comment on lines +54 to +67

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Guard bindgroup_set validity before dereferencing m_pimpl.

Line 64 dereferences set.m_pimpl without validation. Unlike the bindgroup_wrapper path (Line 83), this can crash on invalid/default bindgroup_set.

🛠️ Proposed fix
 void render(bindgroup_set set, encoder_wrapper encoder)
 {
     ASSERT(m_bindGroupLayout);
+    ASSERT(set.is_valid());
     
     auto textureView = getCurrentTextureView();
     ASSERT(textureView);

     auto pass = dawn_utils::begin_render_pass(encoder.m_pimpl->m_encoder, textureView);
     pass.SetPipeline(get_pipeline());
    
-    for (auto entry : set.m_pimpl->m_bindgroups)
+    for (const auto& entry : set.m_pimpl->m_bindgroups)
     {
+        ASSERT(entry.second.is_valid());
         pass.SetBindGroup(entry.first, entry.second.m_pimpl->make_bindgroup(m_device));
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void render(bindgroup_set set, encoder_wrapper encoder)
{
ASSERT(m_bindGroupLayout);
auto textureView = getCurrentTextureView();
ASSERT(textureView);
auto pass = dawn_utils::begin_render_pass(encoder.m_pimpl->m_encoder, textureView);
pass.SetPipeline(get_pipeline());
for (auto entry : set.m_pimpl->m_bindgroups)
{
pass.SetBindGroup(entry.first, entry.second.m_pimpl->make_bindgroup(m_device));
}
void render(bindgroup_set set, encoder_wrapper encoder)
{
ASSERT(m_bindGroupLayout);
ASSERT(set.is_valid());
auto textureView = getCurrentTextureView();
ASSERT(textureView);
auto pass = dawn_utils::begin_render_pass(encoder.m_pimpl->m_encoder, textureView);
pass.SetPipeline(get_pipeline());
for (const auto& entry : set.m_pimpl->m_bindgroups)
{
ASSERT(entry.second.is_valid());
pass.SetBindGroup(entry.first, entry.second.m_pimpl->make_bindgroup(m_device));
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/render_wrapper_impl.hpp` around lines 54 - 67, The render(bindgroup_set
set, encoder_wrapper encoder) function dereferences set.m_pimpl without
validating it which can crash for default/invalid bindgroup_set; before using
set.m_pimpl (and before iterating set.m_pimpl->m_bindgroups) add a guard (e.g.
ASSERT or if-check) to ensure set.m_pimpl is non-null and return/handle the
error early if it is null, mirroring the safety used for bindgroup_wrapper, so
subsequent calls like make_bindgroup(m_device) and access to m_bindgroups are
only performed when set.m_pimpl is valid.


pass.SetVertexBuffer(0, get_bufferVertex(), 0, get_bufferVertex().GetSize());
pass.SetIndexBuffer(get_bufferIndex(), IndexFormat::Uint16, 0, get_bufferIndex().GetSize());
pass.DrawIndexed(3, 1, 0, 0, 0);
pass.End();

encoder.submit_command_buffer();
#ifndef __EMSCRIPTEN__
m_surface.present();
#endif
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

void render(bindgroup_wrapper bindGroup, encoder_wrapper encoder)
{
ASSERT(m_bindGroupLayout);
Expand Down
2 changes: 1 addition & 1 deletion test/build_and_run
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -euo pipefail

cmake -B build
#cmake -B build
cmake --build build -j 8 #$(nproc)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
./build/Example
Loading