mirror of
https://github.com/bevyengine/bevy
synced 2024-11-24 21:53:07 +00:00
add texture and sampler shader reflection
This commit is contained in:
parent
2f1a0cb4a4
commit
4eaae0f815
2 changed files with 20 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
asset::{AssetStorage, Handle},
|
asset::{AssetStorage, Handle, Texture},
|
||||||
legion::prelude::*,
|
legion::prelude::*,
|
||||||
render::{
|
render::{
|
||||||
render_graph::{
|
render_graph::{
|
||||||
|
@ -22,6 +22,7 @@ pub struct WgpuRenderer {
|
||||||
pub render_pipelines: HashMap<Handle<PipelineDescriptor>, wgpu::RenderPipeline>,
|
pub render_pipelines: HashMap<Handle<PipelineDescriptor>, wgpu::RenderPipeline>,
|
||||||
pub buffers: HashMap<String, wgpu::Buffer>,
|
pub buffers: HashMap<String, wgpu::Buffer>,
|
||||||
pub textures: HashMap<String, wgpu::TextureView>,
|
pub textures: HashMap<String, wgpu::TextureView>,
|
||||||
|
pub textures_from_handles: HashMap<Handle<Texture>, wgpu::TextureView>,
|
||||||
pub resource_info: HashMap<String, ResourceInfo>,
|
pub resource_info: HashMap<String, ResourceInfo>,
|
||||||
pub bind_groups: HashMap<u64, BindGroupInfo>,
|
pub bind_groups: HashMap<u64, BindGroupInfo>,
|
||||||
pub bind_group_layouts: HashMap<u64, wgpu::BindGroupLayout>,
|
pub bind_group_layouts: HashMap<u64, wgpu::BindGroupLayout>,
|
||||||
|
@ -62,6 +63,7 @@ impl WgpuRenderer {
|
||||||
render_pipelines: HashMap::new(),
|
render_pipelines: HashMap::new(),
|
||||||
buffers: HashMap::new(),
|
buffers: HashMap::new(),
|
||||||
textures: HashMap::new(),
|
textures: HashMap::new(),
|
||||||
|
textures_from_handles: HashMap::new(),
|
||||||
resource_info: HashMap::new(),
|
resource_info: HashMap::new(),
|
||||||
bind_groups: HashMap::new(),
|
bind_groups: HashMap::new(),
|
||||||
bind_group_layouts: HashMap::new(),
|
bind_group_layouts: HashMap::new(),
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::render::render_graph::{
|
use crate::render::render_graph::{
|
||||||
BindGroup, BindType, Binding, UniformProperty, UniformPropertyType,
|
BindGroup, BindType, Binding, UniformProperty, UniformPropertyType, TextureViewDimension
|
||||||
};
|
};
|
||||||
use spirv_reflect::{
|
use spirv_reflect::{
|
||||||
types::{
|
types::{
|
||||||
ReflectDescriptorBinding, ReflectDescriptorSet, ReflectDescriptorType,
|
ReflectDescriptorBinding, ReflectDescriptorSet, ReflectDescriptorType,
|
||||||
ReflectTypeDescription, ReflectTypeFlags,
|
ReflectTypeDescription, ReflectTypeFlags, ReflectDimension,
|
||||||
},
|
},
|
||||||
ShaderModule,
|
ShaderModule,
|
||||||
};
|
};
|
||||||
|
@ -58,6 +58,16 @@ fn reflect_bind_group(descriptor_set: &ReflectDescriptorSet) -> BindGroup {
|
||||||
BindGroup::new(descriptor_set.set, bindings)
|
BindGroup::new(descriptor_set.set, bindings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn reflect_dimension(type_description: &ReflectTypeDescription) -> TextureViewDimension {
|
||||||
|
match type_description.traits.image.dim {
|
||||||
|
ReflectDimension::Type1d => TextureViewDimension::D1,
|
||||||
|
ReflectDimension::Type2d => TextureViewDimension::D2,
|
||||||
|
ReflectDimension::Type3d => TextureViewDimension::D3,
|
||||||
|
ReflectDimension::Cube => TextureViewDimension::Cube,
|
||||||
|
dimension => panic!("unsupported image dimension: {:?}", dimension),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn reflect_binding(binding: &ReflectDescriptorBinding) -> Binding {
|
fn reflect_binding(binding: &ReflectDescriptorBinding) -> Binding {
|
||||||
let type_description = binding.type_description.as_ref().unwrap();
|
let type_description = binding.type_description.as_ref().unwrap();
|
||||||
let bind_type = match binding.descriptor_type {
|
let bind_type = match binding.descriptor_type {
|
||||||
|
@ -65,6 +75,11 @@ fn reflect_binding(binding: &ReflectDescriptorBinding) -> Binding {
|
||||||
dynamic: false,
|
dynamic: false,
|
||||||
properties: vec![reflect_uniform(type_description)],
|
properties: vec![reflect_uniform(type_description)],
|
||||||
},
|
},
|
||||||
|
ReflectDescriptorType::SampledImage => BindType::SampledTexture {
|
||||||
|
dimension: reflect_dimension(type_description),
|
||||||
|
multisampled: false,
|
||||||
|
},
|
||||||
|
ReflectDescriptorType::Sampler => BindType::Sampler,
|
||||||
_ => panic!("unsupported bind type {:?}", binding.descriptor_type),
|
_ => panic!("unsupported bind type {:?}", binding.descriptor_type),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue