Skip to content

Commit caa7ec6

Browse files
sampetterssonSam Pettersson
and
Sam Pettersson
authored
FIX: iOS Simulator not rendering due to missing CUBE_ARRAY_TEXTURES (#12052)
This PR closes #11978 # Objective Fix rendering on iOS Simulators. iOS Simulator doesn't support the capability CUBE_ARRAY_TEXTURES, since 0.13 this started to make iOS Simulator not render anything with the following message being outputted: ``` 2024-02-19T14:59:34.896266Z ERROR bevy_render::render_resource::pipeline_cache: failed to create shader module: Validation Error Caused by: In Device::create_shader_module Shader validation error: Type [40] '' is invalid Capability Capabilities(CUBE_ARRAY_TEXTURES) is required ``` ## Solution - Split up NO_ARRAY_TEXTURES_SUPPORT into both NO_ARRAY_TEXTURES_SUPPORT and NO_CUBE_ARRAY_TEXTURES_SUPPORT and correctly apply NO_ARRAY_TEXTURES_SUPPORT for iOS Simulator using the cfg flag introduced in #10178. --- ## Changelog ### Fixed - Rendering on iOS Simulator due to missing CUBE_ARRAY_TEXTURES support. --------- Co-authored-by: Sam Pettersson <[email protected]>
1 parent fa17406 commit caa7ec6

File tree

6 files changed

+47
-22
lines changed

6 files changed

+47
-22
lines changed

crates/bevy_pbr/src/render/light.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,16 +1210,20 @@ pub fn prepare_lights(
12101210
.create_view(&TextureViewDescriptor {
12111211
label: Some("point_light_shadow_map_array_texture_view"),
12121212
format: None,
1213-
#[cfg(any(
1214-
not(feature = "webgl"),
1215-
not(target_arch = "wasm32"),
1216-
feature = "webgpu"
1213+
// NOTE: iOS Simulator is missing CubeArray support so we use Cube instead.
1214+
// See https://github.com/bevyengine/bevy/pull/12052 - remove if support is added.
1215+
#[cfg(all(
1216+
not(ios_simulator),
1217+
any(
1218+
not(feature = "webgl"),
1219+
not(target_arch = "wasm32"),
1220+
feature = "webgpu"
1221+
)
12171222
))]
12181223
dimension: Some(TextureViewDimension::CubeArray),
1219-
#[cfg(all(
1220-
feature = "webgl",
1221-
target_arch = "wasm32",
1222-
not(feature = "webgpu")
1224+
#[cfg(any(
1225+
ios_simulator,
1226+
all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu"))
12231227
))]
12241228
dimension: Some(TextureViewDimension::Cube),
12251229
aspect: TextureAspect::DepthOnly,

crates/bevy_pbr/src/render/mesh_view_bindings.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,19 @@ fn layout_entries(
191191
// Point Shadow Texture Cube Array
192192
(
193193
2,
194-
#[cfg(any(
195-
not(feature = "webgl"),
196-
not(target_arch = "wasm32"),
197-
feature = "webgpu"
194+
#[cfg(all(
195+
not(ios_simulator),
196+
any(
197+
not(feature = "webgl"),
198+
not(target_arch = "wasm32"),
199+
feature = "webgpu"
200+
)
198201
))]
199202
texture_cube_array(TextureSampleType::Depth),
200-
#[cfg(all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu")))]
203+
#[cfg(any(
204+
ios_simulator,
205+
all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu"))
206+
))]
201207
texture_cube(TextureSampleType::Depth),
202208
),
203209
// Point Shadow Texture Array Sampler

crates/bevy_pbr/src/render/mesh_view_bindings.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@group(0) @binding(0) var<uniform> view: View;
1010
@group(0) @binding(1) var<uniform> lights: types::Lights;
11-
#ifdef NO_ARRAY_TEXTURES_SUPPORT
11+
#ifdef NO_CUBE_ARRAY_TEXTURES_SUPPORT
1212
@group(0) @binding(2) var point_shadow_textures: texture_depth_cube;
1313
#else
1414
@group(0) @binding(2) var point_shadow_textures: texture_depth_cube_array;

crates/bevy_pbr/src/render/shadows.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn fetch_point_shadow(light_id: u32, frag_position: vec4<f32>, surface_normal: v
4444
// a quad (2x2 fragments) being processed not being sampled, and this messing with
4545
// mip-mapping functionality. The shadow maps have no mipmaps so Level just samples
4646
// from LOD 0.
47-
#ifdef NO_ARRAY_TEXTURES_SUPPORT
47+
#ifdef NO_CUBE_ARRAY_TEXTURES_SUPPORT
4848
return textureSampleCompare(view_bindings::point_shadow_textures, view_bindings::point_shadow_textures_sampler, frag_ls * flip_z, depth);
4949
#else
5050
return textureSampleCompareLevel(view_bindings::point_shadow_textures, view_bindings::point_shadow_textures_sampler, frag_ls * flip_z, i32(light_id), depth);

crates/bevy_render/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ impl Plugin for RenderPlugin {
363363
.insert_resource(instance)
364364
.insert_resource(PipelineCache::new(
365365
device.clone(),
366+
render_adapter.clone(),
366367
self.synchronous_pipeline_compilation,
367368
))
368369
.insert_resource(device)

crates/bevy_render/src/render_resource/pipeline_cache.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::renderer::RenderAdapter;
12
use crate::{render_resource::*, renderer::RenderDevice, Extract};
23
use bevy_asset::{AssetEvent, AssetId, Assets};
34
use bevy_ecs::system::{Res, ResMut};
@@ -21,7 +22,7 @@ use thiserror::Error;
2122
#[cfg(feature = "shader_format_spirv")]
2223
use wgpu::util::make_spirv;
2324
use wgpu::{
24-
Features, PipelineLayoutDescriptor, PushConstantRange, ShaderModuleDescriptor,
25+
DownlevelFlags, Features, PipelineLayoutDescriptor, PushConstantRange, ShaderModuleDescriptor,
2526
VertexBufferLayout as RawVertexBufferLayout,
2627
};
2728

@@ -167,7 +168,7 @@ impl ShaderDefVal {
167168
}
168169

169170
impl ShaderCache {
170-
fn new(render_device: &RenderDevice) -> Self {
171+
fn new(render_device: &RenderDevice, render_adapter: &RenderAdapter) -> Self {
171172
const CAPABILITIES: &[(Features, Capabilities)] = &[
172173
(Features::PUSH_CONSTANTS, Capabilities::PUSH_CONSTANT),
173174
(Features::SHADER_F64, Capabilities::FLOAT64),
@@ -196,9 +197,13 @@ impl ShaderCache {
196197
}
197198
}
198199

199-
// TODO: Check if this is supported, though I'm not sure if bevy works without this feature?
200-
// We can't compile for native at least without it.
201-
capabilities |= Capabilities::CUBE_ARRAY_TEXTURES;
200+
if render_adapter
201+
.get_downlevel_capabilities()
202+
.flags
203+
.contains(DownlevelFlags::CUBE_ARRAY_TEXTURES)
204+
{
205+
capabilities |= Capabilities::CUBE_ARRAY_TEXTURES;
206+
}
202207

203208
#[cfg(debug_assertions)]
204209
let composer = naga_oil::compose::Composer::default();
@@ -279,9 +284,14 @@ impl ShaderCache {
279284
#[cfg(all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu")))]
280285
{
281286
shader_defs.push("NO_ARRAY_TEXTURES_SUPPORT".into());
287+
shader_defs.push("NO_CUBE_ARRAY_TEXTURES_SUPPORT".into());
282288
shader_defs.push("SIXTEEN_BYTE_ALIGNMENT".into());
283289
}
284290

291+
if cfg!(ios_simulator) {
292+
shader_defs.push("NO_CUBE_ARRAY_TEXTURES_SUPPORT".into());
293+
}
294+
285295
shader_defs.push(ShaderDefVal::UInt(
286296
String::from("AVAILABLE_STORAGE_BUFFER_BINDINGS"),
287297
render_device.limits().max_storage_buffers_per_shader_stage,
@@ -491,9 +501,13 @@ impl PipelineCache {
491501
}
492502

493503
/// Create a new pipeline cache associated with the given render device.
494-
pub fn new(device: RenderDevice, synchronous_pipeline_compilation: bool) -> Self {
504+
pub fn new(
505+
device: RenderDevice,
506+
render_adapter: RenderAdapter,
507+
synchronous_pipeline_compilation: bool,
508+
) -> Self {
495509
Self {
496-
shader_cache: Arc::new(Mutex::new(ShaderCache::new(&device))),
510+
shader_cache: Arc::new(Mutex::new(ShaderCache::new(&device, &render_adapter))),
497511
device,
498512
layout_cache: default(),
499513
waiting_pipelines: default(),

0 commit comments

Comments
 (0)