Fix attribute and input bindings for WebGPU, and ask for WGSL shaders
This commit is contained in:
parent
6b5bcc560e
commit
bd485c2eb8
2 changed files with 34 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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<std::vector<WGPUVertexAttribute>> 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<WGPUVertexBufferLayout> 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();
|
||||
|
|
Reference in a new issue