mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-10-30 14:01:39 +00:00
Introduce DynPipelineLayout & DynBindGroup
This commit is contained in:
parent
f8871e6ed1
commit
50a1811229
@ -550,6 +550,8 @@ pub struct BindGroup {
|
||||
dynamic_buffers: Vec<d3d12::GpuAddress>,
|
||||
}
|
||||
|
||||
impl crate::DynBindGroup for BindGroup {}
|
||||
|
||||
bitflags::bitflags! {
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
struct TableTypes: u8 {
|
||||
@ -594,6 +596,8 @@ pub struct PipelineLayout {
|
||||
naga_options: naga::back::hlsl::Options,
|
||||
}
|
||||
|
||||
impl crate::DynPipelineLayout for PipelineLayout {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ShaderModule {
|
||||
naga: crate::NagaShader,
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::ops::Range;
|
||||
|
||||
use crate::{
|
||||
BufferBarrier, BufferBinding, BufferCopy, CommandEncoder, DeviceError, DynQuerySet, Label,
|
||||
MemoryRange,
|
||||
BufferBarrier, BufferBinding, BufferCopy, CommandEncoder, DeviceError, DynBindGroup,
|
||||
DynPipelineLayout, DynQuerySet, Label, MemoryRange,
|
||||
};
|
||||
|
||||
use super::{DynBuffer, DynResourceExt as _};
|
||||
@ -23,6 +23,22 @@ pub trait DynCommandEncoder: std::fmt::Debug {
|
||||
regions: &[BufferCopy],
|
||||
);
|
||||
|
||||
unsafe fn set_bind_group(
|
||||
&mut self,
|
||||
layout: &dyn DynPipelineLayout,
|
||||
index: u32,
|
||||
group: &dyn DynBindGroup,
|
||||
dynamic_offsets: &[wgt::DynamicOffset],
|
||||
);
|
||||
|
||||
unsafe fn set_push_constants(
|
||||
&mut self,
|
||||
layout: &dyn DynPipelineLayout,
|
||||
stages: wgt::ShaderStages,
|
||||
offset_bytes: u32,
|
||||
data: &[u32],
|
||||
);
|
||||
|
||||
unsafe fn insert_debug_marker(&mut self, label: &str);
|
||||
unsafe fn begin_debug_marker(&mut self, group_label: &str);
|
||||
unsafe fn end_debug_marker(&mut self);
|
||||
@ -88,6 +104,29 @@ impl<C: CommandEncoder> DynCommandEncoder for C {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn set_bind_group(
|
||||
&mut self,
|
||||
layout: &dyn DynPipelineLayout,
|
||||
index: u32,
|
||||
group: &dyn DynBindGroup,
|
||||
dynamic_offsets: &[wgt::DynamicOffset],
|
||||
) {
|
||||
let layout = layout.expect_downcast_ref();
|
||||
let group = group.expect_downcast_ref();
|
||||
unsafe { C::set_bind_group(self, layout, index, group, dynamic_offsets) };
|
||||
}
|
||||
|
||||
unsafe fn set_push_constants(
|
||||
&mut self,
|
||||
layout: &dyn DynPipelineLayout,
|
||||
stages: wgt::ShaderStages,
|
||||
offset_bytes: u32,
|
||||
data: &[u32],
|
||||
) {
|
||||
let layout = layout.expect_downcast_ref();
|
||||
unsafe { C::set_push_constants(self, layout, stages, offset_bytes, data) };
|
||||
}
|
||||
|
||||
unsafe fn insert_debug_marker(&mut self, label: &str) {
|
||||
unsafe {
|
||||
C::insert_debug_marker(self, label);
|
||||
|
@ -86,7 +86,9 @@ impl<R: DynResource + ?Sized> DynResourceExt for R {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait DynBindGroup: DynResource + std::fmt::Debug {}
|
||||
pub trait DynBuffer: DynResource + std::fmt::Debug {}
|
||||
pub trait DynPipelineLayout: DynResource + std::fmt::Debug {}
|
||||
pub trait DynQuerySet: DynResource + std::fmt::Debug {}
|
||||
|
||||
impl<'a> BufferBinding<'a, dyn DynBuffer> {
|
||||
|
@ -42,7 +42,9 @@ impl crate::Api for Api {
|
||||
|
||||
crate::impl_dyn_resource!(Context, Encoder, Resource);
|
||||
|
||||
impl crate::DynBindGroup for Resource {}
|
||||
impl crate::DynBuffer for Resource {}
|
||||
impl crate::DynPipelineLayout for Resource {}
|
||||
impl crate::DynQuerySet for Resource {}
|
||||
|
||||
impl crate::Instance for Context {
|
||||
|
@ -487,6 +487,8 @@ pub struct PipelineLayout {
|
||||
naga_options: naga::back::glsl::Options,
|
||||
}
|
||||
|
||||
impl crate::DynPipelineLayout for PipelineLayout {}
|
||||
|
||||
impl PipelineLayout {
|
||||
fn get_slot(&self, br: &naga::ResourceBinding) -> u8 {
|
||||
let group_info = &self.group_infos[br.group as usize];
|
||||
@ -525,6 +527,8 @@ pub struct BindGroup {
|
||||
contents: Box<[RawBinding]>,
|
||||
}
|
||||
|
||||
impl crate::DynBindGroup for BindGroup {}
|
||||
|
||||
type ShaderId = u32;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -265,7 +265,7 @@ pub mod api {
|
||||
mod dynamic;
|
||||
|
||||
pub(crate) use dynamic::{impl_dyn_resource, DynResource};
|
||||
pub use dynamic::{DynBuffer, DynCommandEncoder, DynQuerySet};
|
||||
pub use dynamic::{DynBindGroup, DynBuffer, DynCommandEncoder, DynPipelineLayout, DynQuerySet};
|
||||
|
||||
use std::{
|
||||
borrow::{Borrow, Cow},
|
||||
@ -431,8 +431,8 @@ pub trait Api: Clone + fmt::Debug + Sized {
|
||||
type Fence: fmt::Debug + WasmNotSendSync;
|
||||
|
||||
type BindGroupLayout: fmt::Debug + WasmNotSendSync;
|
||||
type BindGroup: fmt::Debug + WasmNotSendSync;
|
||||
type PipelineLayout: fmt::Debug + WasmNotSendSync;
|
||||
type BindGroup: DynBindGroup;
|
||||
type PipelineLayout: DynPipelineLayout;
|
||||
type ShaderModule: fmt::Debug + WasmNotSendSync;
|
||||
type RenderPipeline: fmt::Debug + WasmNotSendSync;
|
||||
type ComputePipeline: fmt::Debug + WasmNotSendSync;
|
||||
|
@ -624,6 +624,8 @@ pub struct PipelineLayout {
|
||||
per_stage_map: MultiStageResources,
|
||||
}
|
||||
|
||||
impl crate::DynPipelineLayout for PipelineLayout {}
|
||||
|
||||
trait AsNative {
|
||||
type Native;
|
||||
fn from(native: &Self::Native) -> Self;
|
||||
@ -697,6 +699,8 @@ pub struct BindGroup {
|
||||
textures: Vec<TexturePtr>,
|
||||
}
|
||||
|
||||
impl crate::DynBindGroup for BindGroup {}
|
||||
|
||||
unsafe impl Send for BindGroup {}
|
||||
unsafe impl Sync for BindGroup {}
|
||||
|
||||
|
@ -716,11 +716,15 @@ pub struct PipelineLayout {
|
||||
binding_arrays: naga::back::spv::BindingMap,
|
||||
}
|
||||
|
||||
impl crate::DynPipelineLayout for PipelineLayout {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BindGroup {
|
||||
set: gpu_descriptor::DescriptorSet<vk::DescriptorSet>,
|
||||
}
|
||||
|
||||
impl crate::DynBindGroup for BindGroup {}
|
||||
|
||||
/// Miscellaneous allocation recycling pool for `CommandAllocator`.
|
||||
#[derive(Default)]
|
||||
struct Temp {
|
||||
|
Loading…
Reference in New Issue
Block a user