mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 16:31:11 +01:00
Merge #1710
1710: Check render bundle encoding for RODS r=cwfitzgerald a=kvark **Connections** Matches https://github.com/gpuweb/gpuweb/pull/1979 **Description** Allows render bundles to be encoded for RODS. In addition, validates that bundle RODS matches the pass RODS when executing. This part of the spec isn't written yet, and it's safer to be on the strict side. **Testing** Untested Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
commit
5dd3f6ba6b
10 files changed
+96
-52
No files matched your search
@@ -46,6 +46,7 @@ use crate::{
|
||||
hub::{GlobalIdentityHandlerFactory, HalApi, Hub, Resource, Storage, Token},
|
||||
id,
|
||||
memory_init_tracker::{MemoryInitKind, MemoryInitTrackerAction},
|
||||
pipeline::PipelineFlags,
|
||||
track::{TrackerSet, UsageConflict},
|
||||
validation::check_buffer_usage,
|
||||
Label, LabelHelpers, LifeGuard, Stored,
|
||||
@@ -66,9 +67,9 @@ pub struct RenderBundleEncoderDescriptor<'a> {
|
||||
/// The formats of the color attachments that this render bundle is capable to rendering to. This
|
||||
/// must match the formats of the color attachments in the renderpass this render bundle is executed in.
|
||||
pub color_formats: Cow<'a, [wgt::TextureFormat]>,
|
||||
/// The formats of the depth attachment that this render bundle is capable to rendering to. This
|
||||
/// must match the formats of the depth attachments in the renderpass this render bundle is executed in.
|
||||
pub depth_stencil_format: Option<wgt::TextureFormat>,
|
||||
/// Information about the depth attachment that this render bundle is capable to rendering to. The format
|
||||
/// must match the format of the depth attachments in the renderpass this render bundle is executed in.
|
||||
pub depth_stencil: Option<wgt::RenderBundleDepthStencil>,
|
||||
/// Sample count this render bundle is capable of rendering to. This must match the pipelines and
|
||||
/// the renderpasses it is used in.
|
||||
pub sample_count: u32,
|
||||
@@ -80,6 +81,7 @@ pub struct RenderBundleEncoder {
|
||||
base: BasePass<RenderCommand>,
|
||||
parent_id: id::DeviceId,
|
||||
pub(crate) context: RenderPassContext,
|
||||
pub(crate) is_ds_read_only: bool,
|
||||
}
|
||||
|
||||
impl RenderBundleEncoder {
|
||||
@@ -95,7 +97,7 @@ impl RenderBundleEncoder {
|
||||
attachments: AttachmentData {
|
||||
colors: desc.color_formats.iter().cloned().collect(),
|
||||
resolves: ArrayVec::new(),
|
||||
depth_stencil: desc.depth_stencil_format,
|
||||
depth_stencil: desc.depth_stencil.map(|ds| ds.format),
|
||||
},
|
||||
sample_count: {
|
||||
let sc = desc.sample_count;
|
||||
@@ -105,6 +107,14 @@ impl RenderBundleEncoder {
|
||||
sc
|
||||
},
|
||||
},
|
||||
is_ds_read_only: match desc.depth_stencil {
|
||||
Some(ds) => {
|
||||
let aspects = hal::FormatAspects::from(ds.format);
|
||||
(!aspects.contains(hal::FormatAspects::DEPTH) || ds.depth_read_only)
|
||||
&& (!aspects.contains(hal::FormatAspects::STENCIL) || ds.stencil_read_only)
|
||||
}
|
||||
None => false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -120,6 +130,7 @@ impl RenderBundleEncoder {
|
||||
},
|
||||
sample_count: 0,
|
||||
},
|
||||
is_ds_read_only: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,10 +243,15 @@ impl RenderBundleEncoder {
|
||||
|
||||
self.context
|
||||
.check_compatible(&pipeline.pass_context)
|
||||
.map_err(RenderCommandError::IncompatiblePipeline)
|
||||
.map_err(RenderCommandError::IncompatiblePipelineTargets)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
//TODO: check read-only depth
|
||||
if pipeline.flags.contains(PipelineFlags::WRITES_DEPTH_STENCIL)
|
||||
&& self.is_ds_read_only
|
||||
{
|
||||
return Err(RenderCommandError::IncompatiblePipelineRods)
|
||||
.map_pass_err(scope);
|
||||
}
|
||||
|
||||
let layout = &pipeline_layout_guard[pipeline.layout_id.value];
|
||||
pipeline_layout_id = Some(pipeline.layout_id.value);
|
||||
@@ -501,6 +517,7 @@ impl RenderBundleEncoder {
|
||||
string_data: Vec::new(),
|
||||
push_constant_data: Vec::new(),
|
||||
},
|
||||
is_ds_read_only: self.is_ds_read_only,
|
||||
device_id: Stored {
|
||||
value: id::Valid(self.parent_id),
|
||||
ref_count: device.life_guard.add_ref(),
|
||||
@@ -554,10 +571,11 @@ pub struct RenderBundle {
|
||||
// Normalized command stream. It can be executed verbatim,
|
||||
// without re-binding anything on the pipeline change.
|
||||
base: BasePass<RenderCommand>,
|
||||
pub(super) is_ds_read_only: bool,
|
||||
pub(crate) device_id: Stored<id::DeviceId>,
|
||||
pub(crate) used: TrackerSet,
|
||||
pub(crate) buffer_memory_init_actions: Vec<MemoryInitTrackerAction<id::BufferId>>,
|
||||
pub(crate) context: RenderPassContext,
|
||||
pub(super) buffer_memory_init_actions: Vec<MemoryInitTrackerAction<id::BufferId>>,
|
||||
pub(super) context: RenderPassContext,
|
||||
pub(crate) life_guard: LifeGuard,
|
||||
}
|
||||
|
||||
@@ -574,7 +592,7 @@ impl RenderBundle {
|
||||
/// Note that the function isn't expected to fail, generally.
|
||||
/// All the validation has already been done by this point.
|
||||
/// The only failure condition is if some of the used buffers are destroyed.
|
||||
pub(crate) unsafe fn execute<A: HalApi>(
|
||||
pub(super) unsafe fn execute<A: HalApi>(
|
||||
&self,
|
||||
raw: &mut A::CommandEncoder,
|
||||
pipeline_layout_guard: &Storage<
|
||||
|
||||
@@ -72,10 +72,10 @@ pub enum RenderCommandError {
|
||||
InvalidPipeline(id::RenderPipelineId),
|
||||
#[error("QuerySet {0:?} is invalid")]
|
||||
InvalidQuerySet(id::QuerySetId),
|
||||
#[error("Render pipeline is incompatible with render pass")]
|
||||
IncompatiblePipeline(#[from] crate::device::RenderPassCompatibilityError),
|
||||
#[error("pipeline is not compatible with the depth-stencil read-only render pass")]
|
||||
IncompatibleReadOnlyDepthStencil,
|
||||
#[error("Render pipeline targets are incompatible with render pass")]
|
||||
IncompatiblePipelineTargets(#[from] crate::device::RenderPassCompatibilityError),
|
||||
#[error("pipeline writes to depth/stencil, while the pass has read-only depth/stencil")]
|
||||
IncompatiblePipelineRods,
|
||||
#[error("buffer {0:?} is in error {1:?}")]
|
||||
Buffer(id::BufferId, BufferError),
|
||||
#[error("buffer {0:?} is destroyed")]
|
||||
|
||||
@@ -444,8 +444,10 @@ pub enum RenderPassErrorInner {
|
||||
InvalidPopDebugGroup,
|
||||
#[error(transparent)]
|
||||
ResourceUsageConflict(#[from] UsageConflict),
|
||||
#[error("render bundle is incompatible, {0}")]
|
||||
IncompatibleRenderBundle(#[from] RenderPassCompatibilityError),
|
||||
#[error("render bundle has incompatible targets, {0}")]
|
||||
IncompatibleBundleTargets(#[from] RenderPassCompatibilityError),
|
||||
#[error("render bundle has an incompatible read-only depth/stencil flag: bundle is {bundle}, while the pass is {pass}")]
|
||||
IncompatibleBundleRods { pass: bool, bundle: bool },
|
||||
#[error(transparent)]
|
||||
RenderCommand(#[from] RenderCommandError),
|
||||
#[error(transparent)]
|
||||
@@ -994,7 +996,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
|
||||
info.context
|
||||
.check_compatible(&pipeline.pass_context)
|
||||
.map_err(RenderCommandError::IncompatiblePipeline)
|
||||
.map_err(RenderCommandError::IncompatiblePipelineTargets)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
state.pipeline_flags = pipeline.flags;
|
||||
@@ -1002,7 +1004,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
if pipeline.flags.contains(PipelineFlags::WRITES_DEPTH_STENCIL)
|
||||
&& info.is_ds_read_only
|
||||
{
|
||||
return Err(RenderCommandError::IncompatibleReadOnlyDepthStencil)
|
||||
return Err(RenderCommandError::IncompatiblePipelineRods)
|
||||
.map_pass_err(scope);
|
||||
}
|
||||
|
||||
@@ -1678,9 +1680,17 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
|
||||
info.context
|
||||
.check_compatible(&bundle.context)
|
||||
.map_err(RenderPassErrorInner::IncompatibleRenderBundle)
|
||||
.map_err(RenderPassErrorInner::IncompatibleBundleTargets)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
if info.is_ds_read_only != bundle.is_ds_read_only {
|
||||
return Err(RenderPassErrorInner::IncompatibleBundleRods {
|
||||
pass: info.is_ds_read_only,
|
||||
bundle: bundle.is_ds_read_only,
|
||||
})
|
||||
.map_pass_err(scope);
|
||||
}
|
||||
|
||||
cmd_buf.buffer_memory_init_actions.extend(
|
||||
bundle
|
||||
.buffer_memory_init_actions
|
||||
|
||||
@@ -1939,7 +1939,7 @@ impl<A: HalApi> Device<A> {
|
||||
.iter()
|
||||
.any(|ct| ct.write_mask != first.write_mask || ct.blend != first.blend)
|
||||
} {
|
||||
log::error!("Color targets: {:?}", color_targets);
|
||||
log::info!("Color targets: {:?}", color_targets);
|
||||
self.require_downlevel_flags(wgt::DownlevelFlags::INDEPENDENT_BLENDING)?;
|
||||
}
|
||||
|
||||
@@ -3779,6 +3779,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
desc: trace::new_render_bundle_encoder_descriptor(
|
||||
desc.label.clone(),
|
||||
&bundle_encoder.context,
|
||||
bundle_encoder.is_ds_read_only,
|
||||
),
|
||||
base: bundle_encoder.to_base_pass(),
|
||||
});
|
||||
|
||||
@@ -13,11 +13,19 @@ pub const FILE_NAME: &str = "trace.ron";
|
||||
pub(crate) fn new_render_bundle_encoder_descriptor<'a>(
|
||||
label: crate::Label<'a>,
|
||||
context: &'a super::RenderPassContext,
|
||||
is_ds_read_only: bool,
|
||||
) -> crate::command::RenderBundleEncoderDescriptor<'a> {
|
||||
crate::command::RenderBundleEncoderDescriptor {
|
||||
label,
|
||||
color_formats: Cow::Borrowed(&context.attachments.colors),
|
||||
depth_stencil_format: context.attachments.depth_stencil,
|
||||
depth_stencil: context.attachments.depth_stencil.map(|format| {
|
||||
let aspects = hal::FormatAspects::from(format);
|
||||
wgt::RenderBundleDepthStencil {
|
||||
format,
|
||||
depth_read_only: is_ds_read_only && aspects.contains(hal::FormatAspects::DEPTH),
|
||||
stencil_read_only: is_ds_read_only && aspects.contains(hal::FormatAspects::STENCIL),
|
||||
}
|
||||
}),
|
||||
sample_count: context.sample_count,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2746,6 +2746,20 @@ impl<L> CommandBufferDescriptor<L> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes the depth/stencil attachment for render bundles.
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
|
||||
pub struct RenderBundleDepthStencil {
|
||||
/// Format of the attachment.
|
||||
pub format: TextureFormat,
|
||||
/// True if the depth aspect is used but not modified.
|
||||
pub depth_read_only: bool,
|
||||
/// True if the stencil aspect is used but not modified.
|
||||
pub stencil_read_only: bool,
|
||||
}
|
||||
|
||||
/// Describes a [`RenderBundle`].
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
|
||||
@@ -77,7 +77,7 @@ impl Example {
|
||||
device.create_render_bundle_encoder(&wgpu::RenderBundleEncoderDescriptor {
|
||||
label: None,
|
||||
color_formats: &[sc_desc.format],
|
||||
depth_stencil_format: None,
|
||||
depth_stencil: None,
|
||||
sample_count,
|
||||
});
|
||||
encoder.set_pipeline(&pipeline);
|
||||
|
||||
@@ -1291,7 +1291,7 @@ impl crate::Context for Context {
|
||||
let descriptor = wgc::command::RenderBundleEncoderDescriptor {
|
||||
label: desc.label.map(Borrowed),
|
||||
color_formats: Borrowed(desc.color_formats),
|
||||
depth_stencil_format: desc.depth_stencil_format,
|
||||
depth_stencil: desc.depth_stencil,
|
||||
sample_count: desc.sample_count,
|
||||
};
|
||||
match wgc::command::RenderBundleEncoder::new(&descriptor, device.id, None) {
|
||||
|
||||
@@ -1514,8 +1514,8 @@ impl crate::Context for Context {
|
||||
if let Some(ref label) = desc.label {
|
||||
mapped_desc.label(label);
|
||||
}
|
||||
if let Some(dsf) = desc.depth_stencil_format {
|
||||
mapped_desc.depth_stencil_format(map_texture_format(dsf));
|
||||
if let Some(ds) = desc.depth_stencil {
|
||||
mapped_desc.depth_stencil_format(map_texture_format(ds.format));
|
||||
}
|
||||
mapped_desc.sample_count(desc.sample_count);
|
||||
RenderBundleEncoder(device.0.create_render_bundle_encoder(&mapped_desc))
|
||||
|
||||
+21
-28
@@ -29,16 +29,16 @@ pub use wgt::{
|
||||
BlendFactor, BlendOperation, BlendState, BufferAddress, BufferBindingType, BufferSize,
|
||||
BufferUsages, Color, ColorTargetState, ColorWrites, CommandBufferDescriptor, CompareFunction,
|
||||
DepthBiasState, DepthStencilState, DeviceType, DownlevelCapabilities, DownlevelFlags,
|
||||
DynamicOffset, Extent3d, Face, Features, FilterMode, FrontFace, ImageDataLayout, IndexFormat,
|
||||
Limits, MultisampleState, Origin3d, PipelineStatisticsTypes, PolygonMode, PowerPreference,
|
||||
PresentMode, PrimitiveState, PrimitiveTopology, PushConstantRange, QueryType,
|
||||
SamplerBorderColor, ShaderLocation, ShaderModel, ShaderStages, StencilFaceState,
|
||||
StencilOperation, StencilState, StorageTextureAccess, SwapChainDescriptor, SwapChainStatus,
|
||||
TextureAspect, TextureDimension, TextureFormat, TextureFormatFeatureFlags,
|
||||
TextureFormatFeatures, TextureSampleType, TextureUsages, TextureViewDimension, VertexAttribute,
|
||||
VertexFormat, VertexStepMode, BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT,
|
||||
COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT, QUERY_SET_MAX_QUERIES,
|
||||
QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT,
|
||||
DynamicOffset, Extent3d, Face, Features, FilterMode, FrontFace, ImageDataLayout,
|
||||
ImageSubresourceRange, IndexFormat, Limits, MultisampleState, Origin3d,
|
||||
PipelineStatisticsTypes, PolygonMode, PowerPreference, PresentMode, PrimitiveState,
|
||||
PrimitiveTopology, PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBorderColor,
|
||||
ShaderLocation, ShaderModel, ShaderStages, StencilFaceState, StencilOperation, StencilState,
|
||||
StorageTextureAccess, SwapChainDescriptor, SwapChainStatus, TextureAspect, TextureDimension,
|
||||
TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType,
|
||||
TextureUsages, TextureViewDimension, VertexAttribute, VertexFormat, VertexStepMode,
|
||||
BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT,
|
||||
PUSH_CONSTANT_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT,
|
||||
};
|
||||
|
||||
use backend::{BufferMappedRange, Context as C};
|
||||
@@ -88,7 +88,7 @@ trait RenderInner<Ctx: Context> {
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
);
|
||||
fn set_push_constants(&mut self, stages: wgt::ShaderStages, offset: u32, data: &[u8]);
|
||||
fn set_push_constants(&mut self, stages: ShaderStages, 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);
|
||||
@@ -211,8 +211,8 @@ trait Context: Debug + Send + Sized + Sync {
|
||||
fn adapter_get_texture_format_features(
|
||||
&self,
|
||||
adapter: &Self::AdapterId,
|
||||
format: wgt::TextureFormat,
|
||||
) -> wgt::TextureFormatFeatures;
|
||||
format: TextureFormat,
|
||||
) -> TextureFormatFeatures;
|
||||
|
||||
fn device_features(&self, device: &Self::DeviceId) -> Features;
|
||||
fn device_limits(&self, device: &Self::DeviceId) -> Limits;
|
||||
@@ -410,7 +410,7 @@ trait Context: Debug + Send + Sized + Sync {
|
||||
&self,
|
||||
encoder: &Self::CommandEncoderId,
|
||||
texture: &Texture,
|
||||
subresource_range: &wgt::ImageSubresourceRange,
|
||||
subresource_range: &ImageSubresourceRange,
|
||||
);
|
||||
fn command_encoder_clear_buffer(
|
||||
&self,
|
||||
@@ -1324,9 +1324,9 @@ pub struct RenderBundleEncoderDescriptor<'a> {
|
||||
/// The formats of the color attachments that this render bundle is capable to rendering to. This
|
||||
/// must match the formats of the color attachments in the renderpass this render bundle is executed in.
|
||||
pub color_formats: &'a [TextureFormat],
|
||||
/// The formats of the depth attachment that this render bundle is capable to rendering to. This
|
||||
/// must match the formats of the depth attachments in the renderpass this render bundle is executed in.
|
||||
pub depth_stencil_format: Option<TextureFormat>,
|
||||
/// Information about the depth attachment that this render bundle is capable to rendering to. This
|
||||
/// must match the format of the depth attachments in the renderpass this render bundle is executed in.
|
||||
pub depth_stencil: Option<RenderBundleDepthStencil>,
|
||||
/// Sample count this render bundle is capable of rendering to. This must match the pipelines and
|
||||
/// the renderpasses it is used in.
|
||||
pub sample_count: u32,
|
||||
@@ -1540,10 +1540,7 @@ impl Adapter {
|
||||
///
|
||||
/// Note that the WebGPU spec further restricts the available usages/features.
|
||||
/// To disable these restrictions on a device, request the [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] feature.
|
||||
pub fn get_texture_format_features(
|
||||
&self,
|
||||
format: wgt::TextureFormat,
|
||||
) -> wgt::TextureFormatFeatures {
|
||||
pub fn get_texture_format_features(&self, format: TextureFormat) -> TextureFormatFeatures {
|
||||
Context::adapter_get_texture_format_features(&*self.context, &self.id, format)
|
||||
}
|
||||
}
|
||||
@@ -2187,11 +2184,7 @@ impl CommandEncoder {
|
||||
/// - `CLEAR_COMMANDS` extension not enabled
|
||||
/// - Texture does not have `COPY_DST` usage.
|
||||
/// - Range it out of bounds
|
||||
pub fn clear_texture(
|
||||
&mut self,
|
||||
texture: &Texture,
|
||||
subresource_range: &wgt::ImageSubresourceRange,
|
||||
) {
|
||||
pub fn clear_texture(&mut self, texture: &Texture, subresource_range: &ImageSubresourceRange) {
|
||||
Context::command_encoder_clear_image(
|
||||
&*self.context,
|
||||
self.id.as_ref().unwrap(),
|
||||
@@ -2642,7 +2635,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::ShaderStages, offset: u32, data: &[u8]) {
|
||||
pub fn set_push_constants(&mut self, stages: ShaderStages, offset: u32, data: &[u8]) {
|
||||
self.id.set_push_constants(stages, offset, data);
|
||||
}
|
||||
}
|
||||
@@ -2949,7 +2942,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::ShaderStages, offset: u32, data: &[u8]) {
|
||||
pub fn set_push_constants(&mut self, stages: ShaderStages, offset: u32, data: &[u8]) {
|
||||
self.id.set_push_constants(stages, offset, data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user