mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Merge #593
593: Update wgpu with push constants API r=kvark a=kvark Includes https://github.com/gfx-rs/wgpu/pull/966, https://github.com/gfx-rs/wgpu/pull/969, and https://github.com/gfx-rs/wgpu/pull/970 Co-authored-by: Dzmitry Malyshau <kvark@fastmail.com> Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
@@ -26,14 +26,14 @@ vulkan-portability = ["wgc/gfx-backend-vulkan", "gfx-backend-vulkan"]
|
||||
package = "wgpu-core"
|
||||
#version = "0.6"
|
||||
git = "https://github.com/gfx-rs/wgpu"
|
||||
rev = "8059c03273bd7272688e3dac661e72c4973a2d0b"
|
||||
rev = "44a41dc9a4eac8ddc37675f0d52486ded27bdbb3"
|
||||
features = ["raw-window-handle"]
|
||||
|
||||
[dependencies.wgt]
|
||||
package = "wgpu-types"
|
||||
#version = "0.6"
|
||||
git = "https://github.com/gfx-rs/wgpu"
|
||||
rev = "8059c03273bd7272688e3dac661e72c4973a2d0b"
|
||||
rev = "44a41dc9a4eac8ddc37675f0d52486ded27bdbb3"
|
||||
|
||||
[dependencies]
|
||||
arrayvec = "0.5"
|
||||
|
||||
@@ -108,7 +108,20 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
||||
|
||||
log::info!("Initializing the surface...");
|
||||
|
||||
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
|
||||
let backend = if let Ok(backend) = std::env::var("WGPU_TRACE") {
|
||||
match backend.to_lowercase().as_str() {
|
||||
"vulkan" => wgpu::BackendBit::VULKAN,
|
||||
"metal" => wgpu::BackendBit::METAL,
|
||||
"dx12" => wgpu::BackendBit::DX12,
|
||||
"dx11" => wgpu::BackendBit::DX11,
|
||||
"gl" => wgpu::BackendBit::GL,
|
||||
"webgpu" => wgpu::BackendBit::BROWSER_WEBGPU,
|
||||
other => panic!("Unknown backend: {}", other),
|
||||
}
|
||||
} else {
|
||||
wgpu::BackendBit::PRIMARY
|
||||
};
|
||||
let instance = wgpu::Instance::new(backend);
|
||||
let (size, surface) = unsafe {
|
||||
let size = window.inner_size();
|
||||
let surface = instance.create_surface(&window);
|
||||
|
||||
@@ -88,14 +88,12 @@ mod pass_impl {
|
||||
)
|
||||
}
|
||||
}
|
||||
fn set_push_constants(&mut self, offset: u32, data: &[u32]) {
|
||||
fn set_push_constants(&mut self, offset: u32, data: &[u8]) {
|
||||
unsafe {
|
||||
wgpu_compute_pass_set_push_constant(
|
||||
self,
|
||||
offset,
|
||||
(data.len() * std::mem::size_of::<u32>())
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
data.len().try_into().unwrap(),
|
||||
data.as_ptr(),
|
||||
)
|
||||
}
|
||||
@@ -165,15 +163,13 @@ mod pass_impl {
|
||||
) {
|
||||
wgpu_render_pass_set_vertex_buffer(self, slot, buffer.id, offset, size)
|
||||
}
|
||||
fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u32]) {
|
||||
fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) {
|
||||
unsafe {
|
||||
wgpu_render_pass_set_push_constants(
|
||||
self,
|
||||
stages,
|
||||
offset,
|
||||
(data.len() * std::mem::size_of::<u32>())
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
data.len().try_into().unwrap(),
|
||||
data.as_ptr(),
|
||||
)
|
||||
}
|
||||
@@ -362,15 +358,13 @@ mod pass_impl {
|
||||
wgpu_render_bundle_set_vertex_buffer(self, slot, buffer.id, offset, size)
|
||||
}
|
||||
|
||||
fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u32]) {
|
||||
fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) {
|
||||
unsafe {
|
||||
wgpu_render_bundle_set_push_constants(
|
||||
self,
|
||||
stages,
|
||||
offset,
|
||||
(data.len() * std::mem::size_of::<u32>())
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
data.len().try_into().unwrap(),
|
||||
data.as_ptr(),
|
||||
)
|
||||
}
|
||||
@@ -1212,9 +1206,21 @@ impl crate::Context for Context {
|
||||
)
|
||||
}
|
||||
|
||||
fn buffer_destroy(&self, buffer: &Self::BufferId) {
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(buffer.id => global.buffer_destroy(buffer.id)).unwrap_pretty()
|
||||
}
|
||||
fn buffer_drop(&self, buffer: &Self::BufferId) {
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(buffer.id => global.buffer_drop(buffer.id, false))
|
||||
}
|
||||
fn texture_destroy(&self, texture: &Self::TextureId) {
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(texture.id => global.texture_destroy(texture.id)).unwrap_pretty()
|
||||
}
|
||||
fn texture_drop(&self, texture: &Self::TextureId) {
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(texture.id => global.texture_drop(texture.id))
|
||||
wgc::gfx_select!(texture.id => global.texture_drop(texture.id, false))
|
||||
}
|
||||
fn texture_view_drop(&self, texture_view: &Self::TextureViewId) {
|
||||
let global = &self.0;
|
||||
@@ -1224,10 +1230,6 @@ impl crate::Context for Context {
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(*sampler => global.sampler_drop(*sampler))
|
||||
}
|
||||
fn buffer_drop(&self, buffer: &Self::BufferId) {
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(buffer.id => global.buffer_drop(buffer.id, false))
|
||||
}
|
||||
fn bind_group_drop(&self, bind_group: &Self::BindGroupId) {
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(*bind_group => global.bind_group_drop(*bind_group))
|
||||
|
||||
@@ -109,7 +109,7 @@ impl crate::ComputePassInner<Context> for ComputePass {
|
||||
offsets.len() as u32,
|
||||
);
|
||||
}
|
||||
fn set_push_constants(&mut self, _offset: u32, _data: &[u32]) {
|
||||
fn set_push_constants(&mut self, _offset: u32, _data: &[u8]) {
|
||||
panic!("PUSH_CONSTANTS feature must be enabled to call multi_draw_indexed_indirect")
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ impl crate::RenderInner<Context> for RenderPass {
|
||||
self.0
|
||||
.set_vertex_buffer_with_f64_and_f64(slot, &buffer.0, offset as f64, mapped_size);
|
||||
}
|
||||
fn set_push_constants(&mut self, _stages: wgt::ShaderStage, _offset: u32, _data: &[u32]) {
|
||||
fn set_push_constants(&mut self, _stages: wgt::ShaderStage, _offset: u32, _data: &[u8]) {
|
||||
panic!("PUSH_CONSTANTS feature must be enabled to call multi_draw_indexed_indirect")
|
||||
}
|
||||
fn draw(&mut self, vertices: Range<u32>, instances: Range<u32>) {
|
||||
@@ -1267,6 +1267,15 @@ impl crate::Context for Context {
|
||||
Sendable(texture.0.create_view_with_descriptor(&mapped))
|
||||
}
|
||||
|
||||
fn buffer_destroy(&self, _buffer: &Self::BufferId) {
|
||||
// TODO
|
||||
}
|
||||
fn buffer_drop(&self, _buffer: &Self::BufferId) {
|
||||
// Dropped automatically
|
||||
}
|
||||
fn texture_destroy(&self, _texture: &Self::TextureId) {
|
||||
// TODO
|
||||
}
|
||||
fn texture_drop(&self, _texture: &Self::TextureId) {
|
||||
// Dropped automatically
|
||||
}
|
||||
@@ -1276,9 +1285,6 @@ impl crate::Context for Context {
|
||||
fn sampler_drop(&self, _sampler: &Self::SamplerId) {
|
||||
// Dropped automatically
|
||||
}
|
||||
fn buffer_drop(&self, _buffer: &Self::BufferId) {
|
||||
// Dropped automatically
|
||||
}
|
||||
fn bind_group_drop(&self, _bind_group: &Self::BindGroupId) {
|
||||
// Dropped automatically
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ trait ComputePassInner<Ctx: Context> {
|
||||
bind_group: &Ctx::BindGroupId,
|
||||
offsets: &[DynamicOffset],
|
||||
);
|
||||
fn set_push_constants(&mut self, offset: u32, data: &[u32]);
|
||||
fn set_push_constants(&mut self, offset: u32, data: &[u8]);
|
||||
fn insert_debug_marker(&mut self, label: &str);
|
||||
fn push_debug_group(&mut self, group_label: &str);
|
||||
fn pop_debug_group(&mut self);
|
||||
@@ -88,7 +88,7 @@ trait RenderInner<Ctx: Context> {
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
);
|
||||
fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u32]);
|
||||
fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]);
|
||||
fn draw(&mut self, vertices: Range<u32>, instances: Range<u32>);
|
||||
fn draw_indexed(&mut self, indices: Range<u32>, base_vertex: i32, instances: Range<u32>);
|
||||
fn draw_indirect(&mut self, indirect_buffer: &Ctx::BufferId, indirect_offset: BufferAddress);
|
||||
@@ -301,10 +301,13 @@ trait Context: Debug + Send + Sized + Sync {
|
||||
texture: &Self::TextureId,
|
||||
desc: &TextureViewDescriptor,
|
||||
) -> Self::TextureViewId;
|
||||
|
||||
fn buffer_destroy(&self, buffer: &Self::BufferId);
|
||||
fn buffer_drop(&self, buffer: &Self::BufferId);
|
||||
fn texture_destroy(&self, buffer: &Self::TextureId);
|
||||
fn texture_drop(&self, texture: &Self::TextureId);
|
||||
fn texture_view_drop(&self, texture_view: &Self::TextureViewId);
|
||||
fn sampler_drop(&self, sampler: &Self::SamplerId);
|
||||
fn buffer_drop(&self, buffer: &Self::BufferId);
|
||||
fn bind_group_drop(&self, bind_group: &Self::BindGroupId);
|
||||
fn bind_group_layout_drop(&self, bind_group_layout: &Self::BindGroupLayoutId);
|
||||
fn pipeline_layout_drop(&self, pipeline_layout: &Self::PipelineLayoutId);
|
||||
@@ -1716,6 +1719,11 @@ impl Buffer {
|
||||
self.map_context.lock().reset();
|
||||
Context::buffer_unmap(&*self.context, &self.id);
|
||||
}
|
||||
|
||||
/// Destroy the associated native resources as soon as possible.
|
||||
pub fn destroy(&self) {
|
||||
Context::buffer_destroy(&*self.context, &self.id);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> BufferSlice<'a> {
|
||||
@@ -1802,6 +1810,11 @@ impl Texture {
|
||||
owned: true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Destroy the associated native resources as soon as possible.
|
||||
pub fn destroy(&self) {
|
||||
Context::texture_destroy(&*self.context, &self.id);
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Texture {
|
||||
@@ -2316,7 +2329,7 @@ impl<'a> RenderPass<'a> {
|
||||
///
|
||||
/// You would need to upload this in three set_push_constants calls. First for the `Vertex` only range 0..4, second
|
||||
/// for the `Vertex | Fragment` range 4..8, third for the `Fragment` range 8..12.
|
||||
pub fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u32]) {
|
||||
pub fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) {
|
||||
self.id.set_push_constants(stages, offset, data);
|
||||
}
|
||||
}
|
||||
@@ -2392,7 +2405,7 @@ impl<'a> ComputePass<'a> {
|
||||
/// Data size must be a multiple of 4 and must be aligned to the 4s, so we take an array of u32.
|
||||
/// For example, with an offset of 4 and an array of `[u32; 3]`, that will write to the range
|
||||
/// of 4..16.
|
||||
pub fn set_push_constants(&mut self, offset: u32, data: &[u32]) {
|
||||
pub fn set_push_constants(&mut self, offset: u32, data: &[u8]) {
|
||||
self.id.set_push_constants(offset, data);
|
||||
}
|
||||
}
|
||||
@@ -2561,7 +2574,7 @@ impl<'a> RenderBundleEncoder<'a> {
|
||||
///
|
||||
/// You would need to upload this in three set_push_constants calls. First for the `Vertex` only range 0..4, second
|
||||
/// for the `Vertex | Fragment` range 4..8, third for the `Fragment` range 8..12.
|
||||
pub fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u32]) {
|
||||
pub fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) {
|
||||
self.id.set_push_constants(stages, offset, data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user