add TextureDescriptor to ResourceInfo
This commit is contained in:
parent
4eb562975f
commit
10637c1010
@ -15,7 +15,7 @@ use bevy_render::{
|
||||
},
|
||||
render_resource::{
|
||||
BufferInfo, BufferUsage, RenderResource, RenderResourceAssignment,
|
||||
RenderResourceAssignments,
|
||||
RenderResourceAssignments, ResourceInfo,
|
||||
},
|
||||
renderer::RenderContext,
|
||||
shader::{Shader, ShaderSource, ShaderStage, ShaderStages},
|
||||
@ -310,23 +310,18 @@ impl<'a> BevyPathfinderDevice<'a> {
|
||||
)
|
||||
}
|
||||
|
||||
fn get_texture_format(&self, _render_resource: RenderResource) -> Option<TextureFormat> {
|
||||
// TODO: lookup real texture format
|
||||
// let mut texture_format = None;
|
||||
// self.render_context.borrow().resources().get_resource_info(
|
||||
// texture_resource,
|
||||
// &mut |info| {
|
||||
// if let Some(info) = info {
|
||||
// match info {
|
||||
// ResourceInfo::Texture {
|
||||
|
||||
// }
|
||||
// }
|
||||
// texture_format = Some(info)
|
||||
// }
|
||||
// },
|
||||
// );
|
||||
Some(TextureFormat::Rgba16Float)
|
||||
fn get_texture_format(&self, render_resource: RenderResource) -> Option<TextureFormat> {
|
||||
// TODO: add swap chain resource info so this isnt necessary
|
||||
let mut texture_format = Some(TextureFormat::Bgra8UnormSrgb);
|
||||
self.render_context.borrow().resources().get_resource_info(
|
||||
render_resource,
|
||||
&mut |info| {
|
||||
if let Some(ResourceInfo::Texture(descriptor)) = info {
|
||||
texture_format = Some(descriptor.format)
|
||||
}
|
||||
},
|
||||
);
|
||||
texture_format
|
||||
}
|
||||
|
||||
pub fn setup_pipline_descriptor(
|
||||
@ -606,7 +601,7 @@ impl<'a> Device for BevyPathfinderDevice<'a> {
|
||||
.render_context
|
||||
.borrow()
|
||||
.resources()
|
||||
.create_texture(&descriptor),
|
||||
.create_texture(descriptor),
|
||||
texture_descriptor: descriptor,
|
||||
sampler_resource: RefCell::new(None),
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use bevy_render::{
|
||||
render_graph::{Node, ResourceSlotInfo, ResourceSlots},
|
||||
render_resource::ResourceInfo,
|
||||
renderer::RenderContext,
|
||||
shader::Shader,
|
||||
shader::{FieldBindType, Shader},
|
||||
};
|
||||
use legion::prelude::{Resources, World};
|
||||
use pathfinder_canvas::{vec2f, Canvas, CanvasFontContext, ColorF, Path2D, RectF, Vector2I};
|
||||
@ -32,11 +32,11 @@ impl Node for PathfinderNode {
|
||||
static INPUT: &[ResourceSlotInfo] = &[
|
||||
ResourceSlotInfo {
|
||||
name: Cow::Borrowed(PathfinderNode::IN_COLOR_TEXTURE),
|
||||
resource_type: ResourceInfo::Texture,
|
||||
resource_type: FieldBindType::Texture,
|
||||
},
|
||||
ResourceSlotInfo {
|
||||
name: Cow::Borrowed(PathfinderNode::IN_DEPTH_STENCIL_TEXTURE),
|
||||
resource_type: ResourceInfo::Texture,
|
||||
resource_type: FieldBindType::Texture,
|
||||
},
|
||||
];
|
||||
INPUT
|
||||
|
@ -315,7 +315,7 @@ mod tests {
|
||||
use crate::{
|
||||
render_graph::{Edge, Node, NodeId, RenderGraphError, ResourceSlotInfo, ResourceSlots},
|
||||
render_resource::ResourceInfo,
|
||||
renderer::RenderContext,
|
||||
renderer::RenderContext, shader::FieldBindType,
|
||||
};
|
||||
use legion::prelude::{Resources, World};
|
||||
use std::{collections::HashSet, iter::FromIterator};
|
||||
@ -332,13 +332,13 @@ mod tests {
|
||||
inputs: (0..inputs)
|
||||
.map(|i| ResourceSlotInfo {
|
||||
name: format!("in_{}", i).into(),
|
||||
resource_type: ResourceInfo::Texture,
|
||||
resource_type: FieldBindType::Texture,
|
||||
})
|
||||
.collect(),
|
||||
outputs: (0..outputs)
|
||||
.map(|i| ResourceSlotInfo {
|
||||
name: format!("out_{}", i).into(),
|
||||
resource_type: ResourceInfo::Texture,
|
||||
resource_type: FieldBindType::Texture,
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::RenderGraphError;
|
||||
use crate::render_resource::{RenderResource, ResourceInfo};
|
||||
use crate::{shader::FieldBindType, render_resource::{RenderResource, ResourceInfo}};
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -122,11 +122,11 @@ impl From<&[ResourceSlotInfo]> for ResourceSlots {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ResourceSlotInfo {
|
||||
pub name: Cow<'static, str>,
|
||||
pub resource_type: ResourceInfo,
|
||||
pub resource_type: FieldBindType,
|
||||
}
|
||||
|
||||
impl ResourceSlotInfo {
|
||||
pub fn new(name: impl Into<Cow<'static, str>>, resource_type: ResourceInfo) -> Self {
|
||||
pub fn new(name: impl Into<Cow<'static, str>>, resource_type: FieldBindType) -> Self {
|
||||
ResourceSlotInfo {
|
||||
name: name.into(),
|
||||
resource_type,
|
||||
|
@ -5,7 +5,7 @@ use crate::{
|
||||
render_graph::{Node, ResourceSlotInfo, ResourceSlots},
|
||||
render_resource::{RenderResourceAssignments, ResourceInfo},
|
||||
renderer::RenderContext,
|
||||
shader::Shader,
|
||||
shader::{FieldBindType, Shader},
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use legion::prelude::*;
|
||||
@ -26,7 +26,7 @@ impl PassNode {
|
||||
if let TextureAttachment::Input(ref name) = color_attachment.attachment {
|
||||
inputs.push(ResourceSlotInfo::new(
|
||||
name.to_string(),
|
||||
ResourceInfo::Texture,
|
||||
FieldBindType::Texture,
|
||||
));
|
||||
color_attachment_input_indices.push(Some(inputs.len() - 1));
|
||||
} else {
|
||||
@ -39,7 +39,7 @@ impl PassNode {
|
||||
if let TextureAttachment::Input(ref name) = depth_stencil_attachment.attachment {
|
||||
inputs.push(ResourceSlotInfo::new(
|
||||
name.to_string(),
|
||||
ResourceInfo::Texture,
|
||||
FieldBindType::Texture,
|
||||
));
|
||||
depth_stencil_attachment_input_index = Some(inputs.len() - 1);
|
||||
}
|
||||
|
@ -716,7 +716,7 @@ fn setup_uniform_texture_resources<T>(
|
||||
|
||||
let texture_descriptor: TextureDescriptor = texture.into();
|
||||
let texture_resource =
|
||||
render_resource_context.create_texture(&texture_descriptor);
|
||||
render_resource_context.create_texture(texture_descriptor);
|
||||
// TODO: queue texture copy
|
||||
// .create_texture_with_data(&texture_descriptor, &texture.data);
|
||||
let texture_buffer = render_resource_context.create_buffer_with_data(
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
render_graph::{Node, ResourceSlotInfo, ResourceSlots},
|
||||
render_resource::ResourceInfo,
|
||||
renderer::RenderContext,
|
||||
renderer::RenderContext, shader::FieldBindType,
|
||||
};
|
||||
use bevy_app::{EventReader, Events};
|
||||
use bevy_window::{WindowCreated, WindowReference, WindowResized, Windows};
|
||||
@ -33,7 +33,7 @@ impl Node for WindowSwapChainNode {
|
||||
fn output(&self) -> &[ResourceSlotInfo] {
|
||||
static OUTPUT: &[ResourceSlotInfo] = &[ResourceSlotInfo {
|
||||
name: Cow::Borrowed(WindowSwapChainNode::OUT_TEXTURE),
|
||||
resource_type: ResourceInfo::Texture,
|
||||
resource_type: FieldBindType::Texture,
|
||||
}];
|
||||
OUTPUT
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use crate::{
|
||||
render_graph::{Node, ResourceSlotInfo, ResourceSlots},
|
||||
render_resource::ResourceInfo,
|
||||
renderer::RenderContext,
|
||||
texture::TextureDescriptor,
|
||||
texture::TextureDescriptor, shader::FieldBindType,
|
||||
};
|
||||
use bevy_app::{EventReader, Events};
|
||||
use bevy_window::{WindowCreated, WindowReference, WindowResized, Windows};
|
||||
@ -37,7 +37,7 @@ impl Node for WindowTextureNode {
|
||||
fn output(&self) -> &[ResourceSlotInfo] {
|
||||
static OUTPUT: &[ResourceSlotInfo] = &[ResourceSlotInfo {
|
||||
name: Cow::Borrowed(WindowTextureNode::OUT_TEXTURE),
|
||||
resource_type: ResourceInfo::Texture,
|
||||
resource_type: FieldBindType::Texture,
|
||||
}];
|
||||
OUTPUT
|
||||
}
|
||||
@ -78,7 +78,7 @@ impl Node for WindowTextureNode {
|
||||
|
||||
self.descriptor.size.width = window.width;
|
||||
self.descriptor.size.height = window.height;
|
||||
let texture_resource = render_resources.create_texture(&self.descriptor);
|
||||
let texture_resource = render_resources.create_texture(self.descriptor);
|
||||
output.set(WINDOW_TEXTURE, texture_resource);
|
||||
}
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ mod tests {
|
||||
use crate::{
|
||||
render_graph::{Node, NodeId, RenderGraph, ResourceSlotInfo, ResourceSlots},
|
||||
render_resource::ResourceInfo,
|
||||
renderer::RenderContext,
|
||||
renderer::RenderContext, shader::FieldBindType,
|
||||
};
|
||||
use legion::prelude::{Resources, World};
|
||||
|
||||
@ -280,13 +280,13 @@ mod tests {
|
||||
inputs: (0..inputs)
|
||||
.map(|i| ResourceSlotInfo {
|
||||
name: format!("in_{}", i).into(),
|
||||
resource_type: ResourceInfo::Texture,
|
||||
resource_type: FieldBindType::Texture,
|
||||
})
|
||||
.collect(),
|
||||
outputs: (0..outputs)
|
||||
.map(|i| ResourceSlotInfo {
|
||||
name: format!("out_{}", i).into(),
|
||||
resource_type: ResourceInfo::Texture,
|
||||
resource_type: FieldBindType::Texture,
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::render_resource::BufferUsage;
|
||||
use crate::{texture::TextureDescriptor, render_resource::BufferUsage};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct BufferInfo {
|
||||
@ -18,6 +18,6 @@ impl Default for BufferInfo {
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum ResourceInfo {
|
||||
Buffer(BufferInfo),
|
||||
Texture,
|
||||
Texture(TextureDescriptor),
|
||||
Sampler,
|
||||
}
|
||||
|
@ -41,9 +41,9 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
|
||||
self.add_resource_info(resource, ResourceInfo::Sampler);
|
||||
resource
|
||||
}
|
||||
fn create_texture(&self, _texture_descriptor: &TextureDescriptor) -> RenderResource {
|
||||
fn create_texture(&self, texture_descriptor: TextureDescriptor) -> RenderResource {
|
||||
let resource = RenderResource::new();
|
||||
self.add_resource_info(resource, ResourceInfo::Texture);
|
||||
self.add_resource_info(resource, ResourceInfo::Texture(texture_descriptor));
|
||||
resource
|
||||
}
|
||||
fn create_buffer(&self, buffer_info: BufferInfo) -> RenderResource {
|
||||
|
@ -11,7 +11,7 @@ pub trait RenderContext {
|
||||
|
||||
fn create_texture_with_data(
|
||||
&mut self,
|
||||
texture_descriptor: &TextureDescriptor,
|
||||
texture_descriptor: TextureDescriptor,
|
||||
bytes: &[u8],
|
||||
) -> RenderResource;
|
||||
fn copy_buffer_to_buffer(
|
||||
|
@ -31,7 +31,7 @@ pub trait RenderResourceContext: Downcast + Send + Sync + 'static {
|
||||
fn drop_swap_chain_texture(&self, render_resource: RenderResource);
|
||||
fn drop_all_swap_chain_textures(&self);
|
||||
fn create_sampler(&self, sampler_descriptor: &SamplerDescriptor) -> RenderResource;
|
||||
fn create_texture(&self, texture_descriptor: &TextureDescriptor) -> RenderResource;
|
||||
fn create_texture(&self, texture_descriptor: TextureDescriptor) -> RenderResource;
|
||||
fn create_buffer(&self, buffer_info: BufferInfo) -> RenderResource;
|
||||
// TODO: remove RenderResourceContext here
|
||||
fn create_buffer_mapped(
|
||||
|
@ -68,6 +68,7 @@ impl ShaderDefSuffixProvider for bool {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum FieldBindType {
|
||||
Uniform { size: usize },
|
||||
Texture,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::{Extent3d, Texture, TextureDimension, TextureFormat, TextureUsage};
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub struct TextureDescriptor {
|
||||
pub size: Extent3d,
|
||||
pub mip_level_count: u32,
|
||||
|
@ -10,7 +10,7 @@ pub enum TextureViewDimension {
|
||||
D3,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub enum TextureDimension {
|
||||
D1,
|
||||
D2,
|
||||
@ -18,7 +18,7 @@ pub enum TextureDimension {
|
||||
}
|
||||
|
||||
// TODO: use math type here
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct Extent3d {
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
|
@ -73,7 +73,7 @@ impl WgpuRenderContext {
|
||||
impl RenderContext for WgpuRenderContext {
|
||||
fn create_texture_with_data(
|
||||
&mut self,
|
||||
texture_descriptor: &TextureDescriptor,
|
||||
texture_descriptor: TextureDescriptor,
|
||||
bytes: &[u8],
|
||||
) -> RenderResource {
|
||||
self.render_resources.create_texture_with_data(
|
||||
|
@ -39,14 +39,14 @@ impl WgpuRenderResourceContext {
|
||||
pub fn create_texture_with_data(
|
||||
&mut self,
|
||||
command_encoder: &mut wgpu::CommandEncoder,
|
||||
texture_descriptor: &TextureDescriptor,
|
||||
texture_descriptor: TextureDescriptor,
|
||||
bytes: &[u8],
|
||||
) -> RenderResource {
|
||||
let mut resource_info = self.resources.resource_info.write().unwrap();
|
||||
let mut texture_views = self.resources.texture_views.write().unwrap();
|
||||
let mut textures = self.resources.textures.write().unwrap();
|
||||
|
||||
let descriptor: wgpu::TextureDescriptor = (*texture_descriptor).wgpu_into();
|
||||
let descriptor: wgpu::TextureDescriptor = (&texture_descriptor).wgpu_into();
|
||||
let texture = self.device.create_texture(&descriptor);
|
||||
let texture_view = texture.create_default_view();
|
||||
let temp_buf = self
|
||||
@ -69,7 +69,7 @@ impl WgpuRenderResourceContext {
|
||||
);
|
||||
|
||||
let resource = RenderResource::new();
|
||||
resource_info.insert(resource, ResourceInfo::Texture);
|
||||
resource_info.insert(resource, ResourceInfo::Texture(texture_descriptor));
|
||||
texture_views.insert(resource, texture_view);
|
||||
textures.insert(resource, texture);
|
||||
|
||||
@ -182,17 +182,17 @@ impl RenderResourceContext for WgpuRenderResourceContext {
|
||||
resource
|
||||
}
|
||||
|
||||
fn create_texture(&self, texture_descriptor: &TextureDescriptor) -> RenderResource {
|
||||
fn create_texture(&self, texture_descriptor: TextureDescriptor) -> RenderResource {
|
||||
let mut textures = self.resources.textures.write().unwrap();
|
||||
let mut texture_views = self.resources.texture_views.write().unwrap();
|
||||
let mut resource_info = self.resources.resource_info.write().unwrap();
|
||||
|
||||
let descriptor: wgpu::TextureDescriptor = (*texture_descriptor).wgpu_into();
|
||||
let descriptor: wgpu::TextureDescriptor = (&texture_descriptor).wgpu_into();
|
||||
let texture = self.device.create_texture(&descriptor);
|
||||
let texture_view = texture.create_default_view();
|
||||
|
||||
let resource = RenderResource::new();
|
||||
resource_info.insert(resource, ResourceInfo::Texture);
|
||||
resource_info.insert(resource, ResourceInfo::Texture(texture_descriptor));
|
||||
texture_views.insert(resource, texture_view);
|
||||
textures.insert(resource, texture);
|
||||
resource
|
||||
|
@ -216,8 +216,8 @@ impl WgpuFrom<Extent3d> for wgpu::Extent3d {
|
||||
}
|
||||
}
|
||||
|
||||
impl WgpuFrom<TextureDescriptor> for wgpu::TextureDescriptor<'_> {
|
||||
fn from(texture_descriptor: TextureDescriptor) -> Self {
|
||||
impl WgpuFrom<&TextureDescriptor> for wgpu::TextureDescriptor<'_> {
|
||||
fn from(texture_descriptor: &TextureDescriptor) -> Self {
|
||||
wgpu::TextureDescriptor {
|
||||
label: None,
|
||||
size: texture_descriptor.size.wgpu_into(),
|
||||
|
Loading…
Reference in New Issue
Block a user