Use shader_def for oit resolve layer count (#15747)
# Objective - Size is currently hardcoded in the shader which means it will break if a user uses anything higher than that. ## Solution - Use a shader_def to define the size ## Testing Tested with the OIT example
This commit is contained in:
parent
675f8ad403
commit
dec52a0c8f
@ -15,7 +15,7 @@ use bevy_render::{
|
|||||||
BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries, BlendComponent,
|
BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries, BlendComponent,
|
||||||
BlendState, CachedRenderPipelineId, ColorTargetState, ColorWrites, DownlevelFlags,
|
BlendState, CachedRenderPipelineId, ColorTargetState, ColorWrites, DownlevelFlags,
|
||||||
FragmentState, MultisampleState, PipelineCache, PrimitiveState, RenderPipelineDescriptor,
|
FragmentState, MultisampleState, PipelineCache, PrimitiveState, RenderPipelineDescriptor,
|
||||||
Shader, ShaderStages, TextureFormat,
|
Shader, ShaderDefVal, ShaderStages, TextureFormat,
|
||||||
},
|
},
|
||||||
renderer::{RenderAdapter, RenderDevice},
|
renderer::{RenderAdapter, RenderDevice},
|
||||||
texture::BevyDefault,
|
texture::BevyDefault,
|
||||||
@ -121,6 +121,7 @@ pub struct OitResolvePipelineId(pub CachedRenderPipelineId);
|
|||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub struct OitResolvePipelineKey {
|
pub struct OitResolvePipelineKey {
|
||||||
hdr: bool,
|
hdr: bool,
|
||||||
|
layer_count: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
@ -128,15 +129,25 @@ pub fn queue_oit_resolve_pipeline(
|
|||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
pipeline_cache: Res<PipelineCache>,
|
pipeline_cache: Res<PipelineCache>,
|
||||||
resolve_pipeline: Res<OitResolvePipeline>,
|
resolve_pipeline: Res<OitResolvePipeline>,
|
||||||
views: Query<(Entity, &ExtractedView), With<OrderIndependentTransparencySettings>>,
|
views: Query<
|
||||||
|
(
|
||||||
|
Entity,
|
||||||
|
&ExtractedView,
|
||||||
|
&OrderIndependentTransparencySettings,
|
||||||
|
),
|
||||||
|
With<OrderIndependentTransparencySettings>,
|
||||||
|
>,
|
||||||
// Store the key with the id to make the clean up logic easier.
|
// Store the key with the id to make the clean up logic easier.
|
||||||
// This also means it will always replace the entry if the key changes so nothing to clean up.
|
// This also means it will always replace the entry if the key changes so nothing to clean up.
|
||||||
mut cached_pipeline_id: Local<EntityHashMap<(OitResolvePipelineKey, CachedRenderPipelineId)>>,
|
mut cached_pipeline_id: Local<EntityHashMap<(OitResolvePipelineKey, CachedRenderPipelineId)>>,
|
||||||
) {
|
) {
|
||||||
let mut current_view_entities = EntityHashSet::default();
|
let mut current_view_entities = EntityHashSet::default();
|
||||||
for (e, view) in &views {
|
for (e, view, oit_settings) in &views {
|
||||||
current_view_entities.insert(e);
|
current_view_entities.insert(e);
|
||||||
let key = OitResolvePipelineKey { hdr: view.hdr };
|
let key = OitResolvePipelineKey {
|
||||||
|
hdr: view.hdr,
|
||||||
|
layer_count: oit_settings.layer_count,
|
||||||
|
};
|
||||||
|
|
||||||
if let Some((cached_key, id)) = cached_pipeline_id.get(&e) {
|
if let Some((cached_key, id)) = cached_pipeline_id.get(&e) {
|
||||||
if *cached_key == key {
|
if *cached_key == key {
|
||||||
@ -179,7 +190,10 @@ fn specialize_oit_resolve_pipeline(
|
|||||||
fragment: Some(FragmentState {
|
fragment: Some(FragmentState {
|
||||||
entry_point: "fragment".into(),
|
entry_point: "fragment".into(),
|
||||||
shader: OIT_RESOLVE_SHADER_HANDLE,
|
shader: OIT_RESOLVE_SHADER_HANDLE,
|
||||||
shader_defs: vec![],
|
shader_defs: vec![ShaderDefVal::UInt(
|
||||||
|
"LAYER_COUNT".into(),
|
||||||
|
key.layer_count as u32,
|
||||||
|
)],
|
||||||
targets: vec![Some(ColorTargetState {
|
targets: vec![Some(ColorTargetState {
|
||||||
format,
|
format,
|
||||||
blend: Some(BlendState {
|
blend: Some(BlendState {
|
||||||
|
@ -12,8 +12,7 @@ struct OitFragment {
|
|||||||
depth: f32,
|
depth: f32,
|
||||||
}
|
}
|
||||||
// Contains all the colors and depth for this specific fragment
|
// Contains all the colors and depth for this specific fragment
|
||||||
// TODO don't hardcode size
|
var<private> fragment_list: array<OitFragment, #{LAYER_COUNT}>;
|
||||||
var<private> fragment_list: array<OitFragment, 32>;
|
|
||||||
|
|
||||||
struct FullscreenVertexOutput {
|
struct FullscreenVertexOutput {
|
||||||
@builtin(position) position: vec4<f32>,
|
@builtin(position) position: vec4<f32>,
|
||||||
|
Loading…
Reference in New Issue
Block a user