@@ -4,7 +4,7 @@ use crate::{
4
4
RawComputePipelineDescriptor , RawFragmentState , RawRenderPipelineDescriptor ,
5
5
RawVertexState , RenderPipeline , RenderPipelineDescriptor , Shader , ShaderImport , Source ,
6
6
} ,
7
- renderer:: RenderDevice ,
7
+ renderer:: { RenderAdapter , RenderDevice } ,
8
8
Extract ,
9
9
} ;
10
10
use bevy_asset:: { AssetEvent , Assets , Handle } ;
@@ -21,6 +21,7 @@ use std::{borrow::Cow, hash::Hash, mem, ops::Deref};
21
21
use thiserror:: Error ;
22
22
#[ cfg( feature = "shader_format_spirv" ) ]
23
23
use wgpu:: util:: make_spirv;
24
+ use wgpu:: DownlevelFlags ;
24
25
use wgpu:: {
25
26
Features , PipelineLayoutDescriptor , PushConstantRange , ShaderModuleDescriptor ,
26
27
VertexBufferLayout as RawVertexBufferLayout ,
@@ -163,8 +164,8 @@ impl ShaderDefVal {
163
164
}
164
165
165
166
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 ) ] = & [
168
169
( Features :: PUSH_CONSTANTS , Capabilities :: PUSH_CONSTANT ) ,
169
170
( Features :: SHADER_F64 , Capabilities :: FLOAT64 ) ,
170
171
(
@@ -175,22 +176,41 @@ impl ShaderCache {
175
176
Features :: SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING ,
176
177
Capabilities :: SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING ,
177
178
) ,
179
+ (
180
+ Features :: UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING ,
181
+ Capabilities :: UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING ,
182
+ ) ,
178
183
(
179
184
Features :: SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING ,
180
185
Capabilities :: SAMPLER_NON_UNIFORM_INDEXING ,
181
186
) ,
182
187
(
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 ,
185
195
) ,
186
196
] ;
197
+ const DOWNLEVEL_FLAGS_CAPABILITIES : & [ ( DownlevelFlags , Capabilities ) ] = & [ (
198
+ DownlevelFlags :: MULTISAMPLED_SHADING ,
199
+ Capabilities :: MULTISAMPLED_SHADING ,
200
+ ) ] ;
187
201
let features = render_device. features ( ) ;
188
202
let mut capabilities = Capabilities :: empty ( ) ;
189
- for ( feature, capability) in CAPABILITIES {
203
+ for ( feature, capability) in FEATURES_CAPABILITIES {
190
204
if features. contains ( * feature) {
191
205
capabilities |= * capability;
192
206
}
193
207
}
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
+ }
194
214
195
215
#[ cfg( debug_assertions) ]
196
216
let composer = naga_oil:: compose:: Composer :: default ( ) ;
@@ -480,9 +500,9 @@ impl PipelineCache {
480
500
}
481
501
482
502
/// 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 {
484
504
Self {
485
- shader_cache : ShaderCache :: new ( & device) ,
505
+ shader_cache : ShaderCache :: new ( & adapter , & device) ,
486
506
device,
487
507
layout_cache : default ( ) ,
488
508
waiting_pipelines : default ( ) ,
0 commit comments