Introduce DynPipelineLayout & DynBindGroup

This commit is contained in:
Andreas Reich 2024-07-15 23:28:49 +02:00
parent f8871e6ed1
commit 50a1811229
8 changed files with 64 additions and 5 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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> {

View File

@ -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 {

View File

@ -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)]

View File

@ -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;

View File

@ -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 {}

View File

@ -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 {