From 63a67a721842c0c070a096f9b14836b4077fb1e2 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Fri, 2 Dec 2022 15:35:14 +0000 Subject: [PATCH] node: Support sparse vertex buffer layouts Bug: dawn:1000 Change-Id: I616369acdf5c9d883da8d0da292aa1b3f4a77250 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/112021 Commit-Queue: Corentin Wallez Kokoro: Kokoro Reviewed-by: Austin Eng Reviewed-by: Ben Clayton --- src/dawn/node/binding/Converter.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/dawn/node/binding/Converter.cpp b/src/dawn/node/binding/Converter.cpp index 6ec7778d30..b42a8eaa5e 100644 --- a/src/dawn/node/binding/Converter.cpp +++ b/src/dawn/node/binding/Converter.cpp @@ -1148,9 +1148,25 @@ bool Converter::Convert(wgpu::VertexBufferLayout& out, const interop::GPUVertexB bool Converter::Convert(wgpu::VertexState& out, const interop::GPUVertexState& in) { out = {}; - return Convert(out.module, in.module) && Convert(out.buffers, out.bufferCount, in.buffers) && - Convert(out.entryPoint, in.entryPoint) && - Convert(out.constants, out.constantCount, in.constants); + wgpu::VertexBufferLayout* outBuffers = nullptr; + if (!Convert(out.module, in.module) || // + !Convert(outBuffers, out.bufferCount, in.buffers) || // + !Convert(out.entryPoint, in.entryPoint) || // + !Convert(out.constants, out.constantCount, in.constants)) { + return false; + } + + // Patch up the unused vertex buffer layouts to use wgpu::VertexStepMode::VertexBufferNotUsed. + // The converter for optional value will have put the default value of wgpu::VertexBufferLayout + // that has wgpu::VertexStepMode::Vertex. + out.buffers = outBuffers; + for (size_t i = 0; i < in.buffers.size(); i++) { + if (!in.buffers[i].has_value()) { + outBuffers[i].stepMode = wgpu::VertexStepMode::VertexBufferNotUsed; + } + } + + return true; } bool Converter::Convert(wgpu::VertexStepMode& out, const interop::GPUVertexStepMode& in) {