Skip to content

Commit 84a2584

Browse files
committed
Add downlevel flags to capabilities, and add more capabilities
1 parent fd32c6f commit 84a2584

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

crates/bevy_render/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl Plugin for RenderPlugin {
369369

370370
render_app
371371
.insert_resource(RenderInstance(instance))
372-
.insert_resource(PipelineCache::new(device.clone()))
372+
.insert_resource(PipelineCache::new(render_adapter.clone(), device.clone()))
373373
.insert_resource(device)
374374
.insert_resource(queue)
375375
.insert_resource(render_adapter)

crates/bevy_render/src/render_resource/pipeline_cache.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
RawComputePipelineDescriptor, RawFragmentState, RawRenderPipelineDescriptor,
55
RawVertexState, RenderPipeline, RenderPipelineDescriptor, Shader, ShaderImport, Source,
66
},
7-
renderer::RenderDevice,
7+
renderer::{RenderAdapter, RenderDevice},
88
Extract,
99
};
1010
use bevy_asset::{AssetEvent, Assets, Handle};
@@ -21,6 +21,7 @@ use std::{borrow::Cow, hash::Hash, mem, ops::Deref};
2121
use thiserror::Error;
2222
#[cfg(feature = "shader_format_spirv")]
2323
use wgpu::util::make_spirv;
24+
use wgpu::DownlevelFlags;
2425
use wgpu::{
2526
Features, PipelineLayoutDescriptor, PushConstantRange, ShaderModuleDescriptor,
2627
VertexBufferLayout as RawVertexBufferLayout,
@@ -163,8 +164,8 @@ impl ShaderDefVal {
163164
}
164165

165166
impl ShaderCache {
166-
fn new(render_device: &RenderDevice) -> Self {
167-
const CAPABILITIES: &[(Features, Capabilities)] = &[
167+
fn new(render_adapter: &RenderAdapter, render_device: &RenderDevice) -> Self {
168+
const FEATURES_CAPABILITIES: &[(Features, Capabilities)] = &[
168169
(Features::PUSH_CONSTANTS, Capabilities::PUSH_CONSTANT),
169170
(Features::SHADER_F64, Capabilities::FLOAT64),
170171
(
@@ -175,22 +176,41 @@ impl ShaderCache {
175176
Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
176177
Capabilities::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
177178
),
179+
(
180+
Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
181+
Capabilities::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
182+
),
178183
(
179184
Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
180185
Capabilities::SAMPLER_NON_UNIFORM_INDEXING,
181186
),
182187
(
183-
Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
184-
Capabilities::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
188+
Features::TEXTURE_FORMAT_16BIT_NORM,
189+
Capabilities::STORAGE_TEXTURE_16BIT_NORM_FORMATS,
190+
),
191+
(Features::MULTIVIEW, Capabilities::MULTIVIEW),
192+
(
193+
Features::SHADER_EARLY_DEPTH_TEST,
194+
Capabilities::EARLY_DEPTH_TEST,
185195
),
186196
];
197+
const DOWNLEVEL_FLAGS_CAPABILITIES: &[(DownlevelFlags, Capabilities)] = &[(
198+
DownlevelFlags::MULTISAMPLED_SHADING,
199+
Capabilities::MULTISAMPLED_SHADING,
200+
)];
187201
let features = render_device.features();
188202
let mut capabilities = Capabilities::empty();
189-
for (feature, capability) in CAPABILITIES {
203+
for (feature, capability) in FEATURES_CAPABILITIES {
190204
if features.contains(*feature) {
191205
capabilities |= *capability;
192206
}
193207
}
208+
let downlevel_flags = render_adapter.get_downlevel_capabilities().flags;
209+
for (downlevel_flag, capability) in DOWNLEVEL_FLAGS_CAPABILITIES {
210+
if downlevel_flags.contains(*downlevel_flag) {
211+
capabilities |= *capability;
212+
}
213+
}
194214

195215
#[cfg(debug_assertions)]
196216
let composer = naga_oil::compose::Composer::default();
@@ -480,9 +500,9 @@ impl PipelineCache {
480500
}
481501

482502
/// Create a new pipeline cache associated with the given render device.
483-
pub fn new(device: RenderDevice) -> Self {
503+
pub fn new(adapter: RenderAdapter, device: RenderDevice) -> Self {
484504
Self {
485-
shader_cache: ShaderCache::new(&device),
505+
shader_cache: ShaderCache::new(&adapter, &device),
486506
device,
487507
layout_cache: default(),
488508
waiting_pipelines: default(),

0 commit comments

Comments
 (0)