1683: [Backport 0.9] adapter specific render targets r=kvark a=Wumpf

Backport of #1528
Fixes #1682 

clean cherry-pick except for generic name adjustment

Co-authored-by: Alex S <alex0player@gmail.com>
Co-authored-by: Andreas Reich <r_andreas2@web.de>
This commit is contained in:
authored and GitHub committed 2021-07-17 18:32:44 +00:00
commit 0084d68c60
4 files changed
+33 -22

No files matched your search

+2
View File
@@ -1,4 +1,6 @@
# Change Log
## wgpu-core-0.9.2
- fix `Features::TEXTURE_SPECIFIC_FORMAT_FEATURES` not being supported for rendertargets
## wgpu-core-0.9.1 (2021-07-13)
- fix buffer inits delayed by a frame
Generated
+1 -1
View File
@@ -2222,7 +2222,7 @@ dependencies = [
[[package]]
name = "wgpu-core"
version = "0.9.1"
version = "0.9.2"
dependencies = [
"arrayvec",
"bitflags",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "wgpu-core"
version = "0.9.1"
version = "0.9.2"
authors = ["wgpu developers"]
edition = "2018"
description = "WebGPU core logic on gfx-hal"
+29 -20
View File
@@ -627,8 +627,8 @@ impl<B: GfxBackend> Device<B> {
) -> Result<resource::Texture<B>, resource::CreateTextureError> {
debug_assert_eq!(self_id.backend(), B::VARIANT);
let format_desc = desc.format.describe();
self.require_features(format_desc.required_features)
let format_features = self
.describe_format_features(adapter, desc.format)
.map_err(|error| resource::CreateTextureError::MissingFeatures(desc.format, error))?;
// Ensure `D24Plus` textures cannot be copied
@@ -648,15 +648,6 @@ impl<B: GfxBackend> Device<B> {
return Err(resource::CreateTextureError::EmptyUsage);
}
let format_features = if self
.features
.contains(wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES)
{
adapter.get_texture_format_features(desc.format)
} else {
format_desc.guaranteed_format_features
};
let missing_allowed_usages = desc.usage - format_features.allowed_usages;
if !missing_allowed_usages.is_empty() {
return Err(resource::CreateTextureError::InvalidUsages(
@@ -2112,6 +2103,7 @@ impl<B: GfxBackend> Device<B> {
fn create_render_pipeline<G: GlobalIdentityHandlerFactory>(
&self,
self_id: id::DeviceId,
adapter: &crate::instance::Adapter<B>,
desc: &pipeline::RenderPipelineDescriptor,
implicit_context: Option<ImplicitPipelineContext>,
hub: &Hub<B, G>,
@@ -2262,16 +2254,14 @@ impl<B: GfxBackend> Device<B> {
};
for (i, cs) in color_states.iter().enumerate() {
let error = loop {
let format_desc = cs.format.describe();
self.require_features(format_desc.required_features)?;
if !format_desc
.guaranteed_format_features
let format_features = self.describe_format_features(adapter, cs.format)?;
if !format_features
.allowed_usages
.contains(wgt::TextureUsage::RENDER_ATTACHMENT)
{
break Some(pipeline::ColorStateError::FormatNotRenderable(cs.format));
}
if cs.blend.is_some() && !format_desc.guaranteed_format_features.filterable {
if cs.blend.is_some() && !format_features.filterable {
break Some(pipeline::ColorStateError::FormatNotBlendable(cs.format));
}
let hal_format = conv::map_texture_format(cs.format, self.private_features);
@@ -2296,10 +2286,8 @@ impl<B: GfxBackend> Device<B> {
if let Some(ds) = depth_stencil_state {
let error = loop {
let format_desc = ds.format.describe();
self.require_features(format_desc.required_features)?;
if !format_desc
.guaranteed_format_features
if !self
.describe_format_features(adapter, ds.format)?
.allowed_usages
.contains(wgt::TextureUsage::RENDER_ATTACHMENT)
{
@@ -2643,6 +2631,24 @@ impl<B: GfxBackend> Device<B> {
Ok(pipeline)
}
fn describe_format_features(
&self,
adapter: &crate::instance::Adapter<B>,
format: TextureFormat,
) -> Result<wgt::TextureFormatFeatures, MissingFeatures> {
let format_desc = format.describe();
self.require_features(format_desc.required_features)?;
if self
.features
.contains(wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES)
{
Ok(adapter.get_texture_format_features(format))
} else {
Ok(format_desc.guaranteed_format_features)
}
}
fn wait_for_submit(
&self,
submission_index: SubmissionIndex,
@@ -4194,12 +4200,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let fid = hub.render_pipelines.prepare(id_in);
let implicit_context = implicit_pipeline_ids.map(|ipi| ipi.prepare(&hub));
let (adapter_guard, mut token) = hub.adapters.read(&mut token);
let (device_guard, mut token) = hub.devices.read(&mut token);
let error = loop {
let device = match device_guard.get(device_id) {
Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(),
};
let adapter = &adapter_guard[device.adapter_id.value];
#[cfg(feature = "trace")]
if let Some(ref trace) = device.trace {
trace.lock().add(trace::Action::CreateRenderPipeline {
@@ -4211,6 +4219,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let pipeline = match device.create_render_pipeline(
device_id,
adapter,
desc,
implicit_context,
&hub,