use awsm_renderer_core::bind_groups::{
BindGroupLayoutResource, BufferBindingLayout, BufferBindingType, StorageTextureAccess,
StorageTextureBindingLayout,
};
use awsm_renderer_core::texture::{TextureSampleType, TextureViewDimension};
use crate::bind_group_layout::BindGroupLayoutKey;
use crate::bind_group_layout::{BindGroupLayoutCacheKey, BindGroupLayoutCacheKeyEntry};
use crate::error::Result;
use crate::render_passes::shared::material::bind_group::shadow_bind_group_layout_entries;
use crate::render_passes::RenderPassInitContext;
pub struct MaterialEdgeBindGroupLayouts {
pub shade_extended_shadows_layout_key: BindGroupLayoutKey,
pub final_blend_group0_layout_key: BindGroupLayoutKey,
}
impl MaterialEdgeBindGroupLayouts {
pub fn new(ctx: &mut RenderPassInitContext<'_>) -> Result<Self> {
let shade_extended_shadows_layout_key = build_extended_shadows_layout(ctx, true)?;
let final_blend_group0_layout_key = build_final_blend_layout(ctx)?;
Ok(Self {
shade_extended_shadows_layout_key,
final_blend_group0_layout_key,
})
}
}
fn build_extended_shadows_layout(
ctx: &mut RenderPassInitContext<'_>,
with_edge_id_tex: bool,
) -> Result<BindGroupLayoutKey> {
let mut entries = shadow_bind_group_layout_entries(true);
entries.push(BindGroupLayoutCacheKeyEntry {
resource: BindGroupLayoutResource::Buffer(
BufferBindingLayout::new().with_binding_type(BufferBindingType::Storage),
),
visibility_vertex: false,
visibility_fragment: false,
visibility_compute: true,
});
entries.push(BindGroupLayoutCacheKeyEntry {
resource: BindGroupLayoutResource::Buffer(
BufferBindingLayout::new().with_binding_type(BufferBindingType::Uniform),
),
visibility_vertex: false,
visibility_fragment: false,
visibility_compute: true,
});
if with_edge_id_tex {
entries.push(BindGroupLayoutCacheKeyEntry {
resource: BindGroupLayoutResource::StorageTexture(
StorageTextureBindingLayout::new(
awsm_renderer_core::texture::TextureFormat::R32uint,
)
.with_view_dimension(TextureViewDimension::N2d)
.with_access(StorageTextureAccess::ReadOnly),
),
visibility_vertex: false,
visibility_fragment: false,
visibility_compute: true,
});
}
Ok(ctx
.bind_group_layouts
.get_key(ctx.gpu, BindGroupLayoutCacheKey { entries })?)
}
fn build_final_blend_layout(ctx: &mut RenderPassInitContext<'_>) -> Result<BindGroupLayoutKey> {
let entries = vec![
BindGroupLayoutCacheKeyEntry {
resource: BindGroupLayoutResource::Buffer(
BufferBindingLayout::new().with_binding_type(BufferBindingType::ReadOnlyStorage),
),
visibility_vertex: false,
visibility_fragment: false,
visibility_compute: true,
},
BindGroupLayoutCacheKeyEntry {
resource: BindGroupLayoutResource::Buffer(
BufferBindingLayout::new().with_binding_type(BufferBindingType::Uniform),
),
visibility_vertex: false,
visibility_fragment: false,
visibility_compute: true,
},
BindGroupLayoutCacheKeyEntry {
resource: BindGroupLayoutResource::StorageTexture(
StorageTextureBindingLayout::new(ctx.render_texture_formats.color)
.with_view_dimension(TextureViewDimension::N2d)
.with_access(StorageTextureAccess::WriteOnly),
),
visibility_vertex: false,
visibility_fragment: false,
visibility_compute: true,
},
];
let _ = TextureSampleType::UnfilterableFloat; Ok(ctx
.bind_group_layouts
.get_key(ctx.gpu, BindGroupLayoutCacheKey { entries })?)
}