Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into depth-for-deferred
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Oct 23, 2023
2 parents b0edde6 + d938275 commit 784d783
Show file tree
Hide file tree
Showing 66 changed files with 1,557 additions and 1,250 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ accesskit_unix = ["bevy_internal/accesskit_unix"]
# Enable assertions to check the validity of parameters passed to glam
glam_assert = ["bevy_internal/glam_assert"]

# Enable assertions in debug builds to check the validity of parameters passed to glam
debug_glam_assert = ["bevy_internal/debug_glam_assert"]

# Include a default font, containing only ASCII characters, at the cost of a 20kB binary size increase
default_font = ["bevy_internal/default_font"]

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ crossbeam-channel = "0.5"
downcast-rs = "1.2"
futures-io = "0.3"
futures-lite = "1.12"
md5 = "0.7"
blake3 = "1.5"
parking_lot = { version = "0.12", features = ["arc_lock", "send_guard"] }
ron = "0.8"
serde = { version = "1", features = ["derive"] }
Expand Down
20 changes: 9 additions & 11 deletions crates/bevy_asset/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,27 +225,25 @@ pub(crate) fn loader_settings_meta_transform<S: Settings>(
})
}

pub type AssetHash = [u8; 16];
pub type AssetHash = [u8; 32];

/// NOTE: changing the hashing logic here is a _breaking change_ that requires a [`META_FORMAT_VERSION`] bump.
pub(crate) fn get_asset_hash(meta_bytes: &[u8], asset_bytes: &[u8]) -> AssetHash {
let mut context = md5::Context::new();
context.consume(meta_bytes);
context.consume(asset_bytes);
let digest = context.compute();
digest.0
let mut hasher = blake3::Hasher::new();
hasher.update(meta_bytes);
hasher.update(asset_bytes);
*hasher.finalize().as_bytes()
}

/// NOTE: changing the hashing logic here is a _breaking change_ that requires a [`META_FORMAT_VERSION`] bump.
pub(crate) fn get_full_asset_hash(
asset_hash: AssetHash,
dependency_hashes: impl Iterator<Item = AssetHash>,
) -> AssetHash {
let mut context = md5::Context::new();
context.consume(asset_hash);
let mut hasher = blake3::Hasher::new();
hasher.update(&asset_hash);
for hash in dependency_hashes {
context.consume(hash);
hasher.update(&hash);
}
let digest = context.compute();
digest.0
*hasher.finalize().as_bytes()
}
3 changes: 3 additions & 0 deletions crates/bevy_asset/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ impl<'a> Debug for AssetPath<'a> {

impl<'a> Display for AssetPath<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let AssetSourceId::Name(name) = self.source() {
write!(f, "{name}://")?;
}
write!(f, "{}", self.path.display())?;
if let Some(label) = &self.label {
write!(f, "#{label}")?;
Expand Down
88 changes: 28 additions & 60 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,30 +170,16 @@ impl ViewNode for BloomNode {
// First downsample pass
{
let downsampling_first_bind_group =
render_context
.render_device()
.create_bind_group(&BindGroupDescriptor {
label: Some("bloom_downsampling_first_bind_group"),
layout: &downsampling_pipeline_res.bind_group_layout,
entries: &[
BindGroupEntry {
binding: 0,
// Read from main texture directly
resource: BindingResource::TextureView(
view_target.main_texture_view(),
),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(&bind_groups.sampler),
},
BindGroupEntry {
binding: 2,
resource: uniforms.clone(),
},
],
});
let downsampling_first_bind_group = render_context.render_device().create_bind_group(
"bloom_downsampling_first_bind_group",
&downsampling_pipeline_res.bind_group_layout,
&BindGroupEntries::sequential((
// Read from main texture directly
view_target.main_texture_view(),
&bind_groups.sampler,
uniforms.clone(),
)),
);

let view = &bloom_texture.view(0);
let mut downsampling_first_pass =
Expand Down Expand Up @@ -416,46 +402,28 @@ fn prepare_bloom_bind_groups(

let mut downsampling_bind_groups = Vec::with_capacity(bind_group_count);
for mip in 1..bloom_texture.mip_count {
downsampling_bind_groups.push(render_device.create_bind_group(&BindGroupDescriptor {
label: Some("bloom_downsampling_bind_group"),
layout: &downsampling_pipeline.bind_group_layout,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(&bloom_texture.view(mip - 1)),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(sampler),
},
BindGroupEntry {
binding: 2,
resource: uniforms.binding().unwrap(),
},
],
}));
downsampling_bind_groups.push(render_device.create_bind_group(
"bloom_downsampling_bind_group",
&downsampling_pipeline.bind_group_layout,
&BindGroupEntries::sequential((
&bloom_texture.view(mip - 1),
sampler,
uniforms.binding().unwrap(),
)),
));
}

let mut upsampling_bind_groups = Vec::with_capacity(bind_group_count);
for mip in (0..bloom_texture.mip_count).rev() {
upsampling_bind_groups.push(render_device.create_bind_group(&BindGroupDescriptor {
label: Some("bloom_upsampling_bind_group"),
layout: &upsampling_pipeline.bind_group_layout,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(&bloom_texture.view(mip)),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(sampler),
},
BindGroupEntry {
binding: 2,
resource: uniforms.binding().unwrap(),
},
],
}));
upsampling_bind_groups.push(render_device.create_bind_group(
"bloom_upsampling_bind_group",
&upsampling_pipeline.bind_group_layout,
&BindGroupEntries::sequential((
&bloom_texture.view(mip),
sampler,
uniforms.binding().unwrap(),
)),
));
}

commands.entity(entity).insert(BloomBindGroups {
Expand Down
36 changes: 11 additions & 25 deletions crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use bevy_render::{
extract_component::{ComponentUniforms, DynamicUniformIndex},
render_graph::{Node, NodeRunError, RenderGraphContext},
render_resource::{
BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, BufferId, Operations,
PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, TextureViewId,
BindGroup, BindGroupEntries, BufferId, Operations, PipelineCache,
RenderPassColorAttachment, RenderPassDescriptor, TextureViewId,
},
renderer::RenderContext,
view::{ExtractedView, ViewTarget},
Expand Down Expand Up @@ -77,29 +77,15 @@ impl Node for CASNode {
bind_group
}
cached_bind_group => {
let bind_group =
render_context
.render_device()
.create_bind_group(&BindGroupDescriptor {
label: Some("cas_bind_group"),
layout: &sharpening_pipeline.texture_bind_group,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(view_target.source),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(
&sharpening_pipeline.sampler,
),
},
BindGroupEntry {
binding: 2,
resource: uniforms,
},
],
});
let bind_group = render_context.render_device().create_bind_group(
"cas_bind_group",
&sharpening_pipeline.texture_bind_group,
&BindGroupEntries::sequential((
view_target.source,
&sharpening_pipeline.sampler,
uniforms,
)),
);

let (_, _, bind_group) =
cached_bind_group.insert((uniforms_id, source.id(), bind_group));
Expand Down
22 changes: 6 additions & 16 deletions crates/bevy_core_pipeline/src/deferred/copy_lighting_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ use bevy_render::{
use bevy_ecs::query::QueryItem;
use bevy_render::{
render_graph::{NodeRunError, RenderGraphContext, ViewNode},
render_resource::{
BindGroupDescriptor, BindGroupEntry, BindingResource, Operations, PipelineCache,
RenderPassDescriptor,
},
render_resource::{Operations, PipelineCache, RenderPassDescriptor},
renderer::RenderContext,
};

Expand Down Expand Up @@ -94,18 +91,11 @@ impl ViewNode for CopyDeferredLightingIdNode {
return Ok(());
};

let bind_group = render_context
.render_device()
.create_bind_group(&BindGroupDescriptor {
label: Some("copy_deferred_lighting_id_bind_group"),
layout: &copy_deferred_lighting_id_pipeline.layout,
entries: &[BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(
&deferred_lighting_pass_id_texture.default_view,
),
}],
});
let bind_group = render_context.render_device().create_bind_group(
"copy_deferred_lighting_id_bind_group",
&copy_deferred_lighting_id_pipeline.layout,
&BindGroupEntries::single(&deferred_lighting_pass_id_texture.default_view),
);

let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
label: Some("copy_deferred_lighting_id_pass"),
Expand Down
27 changes: 7 additions & 20 deletions crates/bevy_core_pipeline/src/fxaa/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use bevy_ecs::query::QueryItem;
use bevy_render::{
render_graph::{NodeRunError, RenderGraphContext, ViewNode},
render_resource::{
BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, FilterMode, Operations,
PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor,
TextureViewId,
BindGroup, BindGroupEntries, FilterMode, Operations, PipelineCache,
RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor, TextureViewId,
},
renderer::RenderContext,
view::ViewTarget,
Expand Down Expand Up @@ -61,23 +60,11 @@ impl ViewNode for FxaaNode {
..default()
});

let bind_group =
render_context
.render_device()
.create_bind_group(&BindGroupDescriptor {
label: None,
layout: &fxaa_pipeline.texture_bind_group,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(source),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(&sampler),
},
],
});
let bind_group = render_context.render_device().create_bind_group(
None,
&fxaa_pipeline.texture_bind_group,
&BindGroupEntries::sequential((source, &sampler)),
);

let (_, bind_group) = cached_bind_group.insert((source.id(), bind_group));
bind_group
Expand Down
23 changes: 6 additions & 17 deletions crates/bevy_core_pipeline/src/msaa_writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use bevy_ecs::prelude::*;
use bevy_render::{
camera::ExtractedCamera,
render_graph::{Node, NodeRunError, RenderGraphApp, RenderGraphContext},
render_resource::BindGroupEntries,
renderer::RenderContext,
view::{Msaa, ViewTarget},
Render, RenderSet,
Expand Down Expand Up @@ -90,23 +91,11 @@ impl Node for MsaaWritebackNode {
depth_stencil_attachment: None,
};

let bind_group =
render_context
.render_device()
.create_bind_group(&BindGroupDescriptor {
label: None,
layout: &blit_pipeline.texture_bind_group,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(post_process.source),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(&blit_pipeline.sampler),
},
],
});
let bind_group = render_context.render_device().create_bind_group(
None,
&blit_pipeline.texture_bind_group,
&BindGroupEntries::sequential((post_process.source, &blit_pipeline.sampler)),
);

let mut render_pass = render_context
.command_encoder()
Expand Down
41 changes: 16 additions & 25 deletions crates/bevy_core_pipeline/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
render_asset::RenderAssets,
render_resource::{
BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor,
BindGroupLayoutEntry, BindingResource, BindingType, BufferBindingType,
CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState,
DepthStencilState, FragmentState, MultisampleState, PipelineCache, PrimitiveState,
RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, ShaderType,
SpecializedRenderPipeline, SpecializedRenderPipelines, StencilFaceState, StencilState,
TextureFormat, TextureSampleType, TextureViewDimension, VertexState,
BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor,
BindGroupLayoutEntry, BindingType, BufferBindingType, CachedRenderPipelineId,
ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, DepthStencilState,
FragmentState, MultisampleState, PipelineCache, PrimitiveState, RenderPipelineDescriptor,
SamplerBindingType, Shader, ShaderStages, ShaderType, SpecializedRenderPipeline,
SpecializedRenderPipelines, StencilFaceState, StencilState, TextureFormat,
TextureSampleType, TextureViewDimension, VertexState,
},
renderer::RenderDevice,
texture::{BevyDefault, Image},
Expand Down Expand Up @@ -224,24 +224,15 @@ fn prepare_skybox_bind_groups(
if let (Some(skybox), Some(view_uniforms)) =
(images.get(&skybox.0), view_uniforms.uniforms.binding())
{
let bind_group = render_device.create_bind_group(&BindGroupDescriptor {
label: Some("skybox_bind_group"),
layout: &pipeline.bind_group_layout,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(&skybox.texture_view),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(&skybox.sampler),
},
BindGroupEntry {
binding: 2,
resource: view_uniforms,
},
],
});
let bind_group = render_device.create_bind_group(
"skybox_bind_group",
&pipeline.bind_group_layout,
&BindGroupEntries::sequential((
&skybox.texture_view,
&skybox.sampler,
view_uniforms,
)),
);

commands.entity(entity).insert(SkyboxBindGroup(bind_group));
}
Expand Down
Loading

0 comments on commit 784d783

Please sign in to comment.