diff --git a/engine/gfx/webgpu/include/gfx_webgpu.hpp b/engine/gfx/webgpu/include/gfx_webgpu.hpp index 1549a05..8aae6da 100755 --- a/engine/gfx/webgpu/include/gfx_webgpu.hpp +++ b/engine/gfx/webgpu/include/gfx_webgpu.hpp @@ -8,6 +8,7 @@ class GFXWebGPU : public GFX { public: bool initialize(const GFXCreateInfo& createInfo) override; + ShaderLanguage accepted_shader_language() override; const char* get_name() override; // buffer diff --git a/engine/gfx/webgpu/src/gfx_webgpu.cpp b/engine/gfx/webgpu/src/gfx_webgpu.cpp index 16fa69b..47b5c9a 100755 --- a/engine/gfx/webgpu/src/gfx_webgpu.cpp +++ b/engine/gfx/webgpu/src/gfx_webgpu.cpp @@ -8,6 +8,7 @@ #include "gfx_webgpu_renderpass.hpp" #include "gfx_webgpu_sampler.hpp" #include "gfx_webgpu_texture.hpp" +#include "utility.hpp" WGPUTextureFormat toPixFormat(GFXPixelFormat format) { switch (format) { @@ -177,6 +178,10 @@ bool GFXWebGPU::initialize(const GFXCreateInfo& createInfo) { return true; } +ShaderLanguage GFXWebGPU::accepted_shader_language() { + return ShaderLanguage::WGSL; +} + const char* GFXWebGPU::get_name() { return "WebGPU"; } @@ -317,8 +322,21 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate } } + prism::log("building pipeline {}", info.label); + + // alright, webgpu in their infinite wisdom does not allow arbitrary binding locations + // so, to be consistent with what vulkan, metal and virtually every other API allows, + // we will create dummy buffers with no attributes attached. congrats webgpu devs. + int dummy_buffer_count = 0; + for (auto& binding : info.vertex_input.inputs) { + dummy_buffer_count = std::max(binding.location, dummy_buffer_count); + } + dummy_buffer_count += 1; + std::vector> attributes; - attributes.resize(info.vertex_input.inputs.size()); + attributes.resize(dummy_buffer_count); + + prism::log("dummy buffer count: {}", dummy_buffer_count); for (auto& attribute : info.vertex_input.attributes) { WGPUVertexAttribute description; @@ -326,18 +344,30 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate description.format = toVertFormat(attribute.format); description.offset = attribute.offset; + prism::log("{} of {}", attribute.binding, info.vertex_input.inputs.size()); + attributes[attribute.binding].push_back(description); } std::vector inputs; + inputs.resize(dummy_buffer_count); for (auto& binding : info.vertex_input.inputs) { + prism::log("binding loc {}", binding.location); + + prism::log("debugging attributes at loc {}", binding.location); + + for(auto attr : attributes[binding.location]) { + prism::log("- attrib {}", attr.shaderLocation); + prism::log("fmt: {}", utility::enum_to_string(attr.format)); + } + WGPUVertexBufferLayout b; b.attributes = attributes[binding.location].data(); - b.attributeCount = attributes.size(); + b.attributeCount = attributes[binding.location].size(); b.arrayStride = binding.stride; b.stepMode = WGPUVertexStepMode_Vertex; - inputs.push_back(b); + inputs[binding.location] = b; } descriptor.vertex.buffers = inputs.data();