From d853b80cb77cfd6f3d17b6499ff6e8c5672bddf6 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Sun, 15 May 2022 11:34:03 -0700 Subject: [PATCH] Move set_index_buffer FFI functions back into wgpu. It's very odd to have almost all the render pass and compute pass ffi functions in `wgpu` except for the `set_index_buffer` functions, which live in Firefox. I'd like to remove these from Firefox and put them back next to their companions. These functions were originally removed from wgpu in #1077, because wgpu-native has its own incompatible version of IndexFormat (see that PR for details). However, with wgpu-native#85, that code was removed, so having these functions in `wgpu` should be no longer be a problem for wgpu-native. --- wgpu-core/src/command/bundle.rs | 13 ++++++++++++- wgpu-core/src/command/render.rs | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 5bd7eafb1a..4a37e358ec 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -1219,7 +1219,7 @@ pub mod bundle_ffi { use super::{RenderBundleEncoder, RenderCommand}; use crate::{id, RawString}; use std::{convert::TryInto, slice}; - use wgt::{BufferAddress, BufferSize, DynamicOffset}; + use wgt::{BufferAddress, BufferSize, DynamicOffset, IndexFormat}; /// # Safety /// @@ -1283,6 +1283,17 @@ pub mod bundle_ffi { }); } + #[no_mangle] + pub extern "C" fn wgpu_render_bundle_set_index_buffer( + encoder: &mut RenderBundleEncoder, + buffer: id::BufferId, + index_format: IndexFormat, + offset: BufferAddress, + size: Option, + ) { + encoder.set_index_buffer(buffer, index_format, offset, size); + } + /// # Safety /// /// This function is unsafe as there is no guarantee that the given pointer is diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 2cd83a178f..0e08d37728 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -2005,7 +2005,7 @@ pub mod render_ffi { }; use crate::{id, RawString}; use std::{convert::TryInto, ffi, num::NonZeroU32, slice}; - use wgt::{BufferAddress, BufferSize, Color, DynamicOffset}; + use wgt::{BufferAddress, BufferSize, Color, DynamicOffset, IndexFormat}; /// # Safety /// @@ -2068,6 +2068,17 @@ pub mod render_ffi { }); } + #[no_mangle] + pub extern "C" fn wgpu_render_pass_set_index_buffer( + pass: &mut RenderPass, + buffer: id::BufferId, + index_format: IndexFormat, + offset: BufferAddress, + size: Option, + ) { + pass.set_index_buffer(buffer, index_format, offset, size); + } + #[no_mangle] pub extern "C" fn wgpu_render_pass_set_blend_constant(pass: &mut RenderPass, color: &Color) { pass.base