Skip to content

Commit

Permalink
Add downlevel flags to capabilities, and add more capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
trolleyman committed Jul 1, 2023
1 parent fd32c6f commit 84a2584
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl Plugin for RenderPlugin {

render_app
.insert_resource(RenderInstance(instance))
.insert_resource(PipelineCache::new(device.clone()))
.insert_resource(PipelineCache::new(render_adapter.clone(), device.clone()))
.insert_resource(device)
.insert_resource(queue)
.insert_resource(render_adapter)
Expand Down
36 changes: 28 additions & 8 deletions crates/bevy_render/src/render_resource/pipeline_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
RawComputePipelineDescriptor, RawFragmentState, RawRenderPipelineDescriptor,
RawVertexState, RenderPipeline, RenderPipelineDescriptor, Shader, ShaderImport, Source,
},
renderer::RenderDevice,
renderer::{RenderAdapter, RenderDevice},
Extract,
};
use bevy_asset::{AssetEvent, Assets, Handle};
Expand All @@ -21,6 +21,7 @@ use std::{borrow::Cow, hash::Hash, mem, ops::Deref};
use thiserror::Error;
#[cfg(feature = "shader_format_spirv")]
use wgpu::util::make_spirv;
use wgpu::DownlevelFlags;
use wgpu::{
Features, PipelineLayoutDescriptor, PushConstantRange, ShaderModuleDescriptor,
VertexBufferLayout as RawVertexBufferLayout,
Expand Down Expand Up @@ -163,8 +164,8 @@ impl ShaderDefVal {
}

impl ShaderCache {
fn new(render_device: &RenderDevice) -> Self {
const CAPABILITIES: &[(Features, Capabilities)] = &[
fn new(render_adapter: &RenderAdapter, render_device: &RenderDevice) -> Self {
const FEATURES_CAPABILITIES: &[(Features, Capabilities)] = &[
(Features::PUSH_CONSTANTS, Capabilities::PUSH_CONSTANT),
(Features::SHADER_F64, Capabilities::FLOAT64),
(
Expand All @@ -175,22 +176,41 @@ impl ShaderCache {
Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
Capabilities::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
),
(
Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
Capabilities::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
),
(
Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
Capabilities::SAMPLER_NON_UNIFORM_INDEXING,
),
(
Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
Capabilities::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
Features::TEXTURE_FORMAT_16BIT_NORM,
Capabilities::STORAGE_TEXTURE_16BIT_NORM_FORMATS,
),
(Features::MULTIVIEW, Capabilities::MULTIVIEW),
(
Features::SHADER_EARLY_DEPTH_TEST,
Capabilities::EARLY_DEPTH_TEST,
),
];
const DOWNLEVEL_FLAGS_CAPABILITIES: &[(DownlevelFlags, Capabilities)] = &[(
DownlevelFlags::MULTISAMPLED_SHADING,
Capabilities::MULTISAMPLED_SHADING,
)];
let features = render_device.features();
let mut capabilities = Capabilities::empty();
for (feature, capability) in CAPABILITIES {
for (feature, capability) in FEATURES_CAPABILITIES {
if features.contains(*feature) {
capabilities |= *capability;
}
}
let downlevel_flags = render_adapter.get_downlevel_capabilities().flags;
for (downlevel_flag, capability) in DOWNLEVEL_FLAGS_CAPABILITIES {
if downlevel_flags.contains(*downlevel_flag) {
capabilities |= *capability;
}
}

#[cfg(debug_assertions)]
let composer = naga_oil::compose::Composer::default();
Expand Down Expand Up @@ -480,9 +500,9 @@ impl PipelineCache {
}

/// Create a new pipeline cache associated with the given render device.
pub fn new(device: RenderDevice) -> Self {
pub fn new(adapter: RenderAdapter, device: RenderDevice) -> Self {
Self {
shader_cache: ShaderCache::new(&device),
shader_cache: ShaderCache::new(&adapter, &device),
device,
layout_cache: default(),
waiting_pipelines: default(),
Expand Down

0 comments on commit 84a2584

Please sign in to comment.