render: replace ResourceInfo with ResourceType

This commit is contained in:
Carter Anderson 2020-06-14 15:22:31 -07:00
parent 574656b767
commit 3786224b28
14 changed files with 61 additions and 65 deletions

View file

@ -14,8 +14,8 @@ pub fn derive_render_resource(input: TokenStream) -> TokenStream {
TokenStream::from(quote! {
impl #bevy_render_path::render_resource::RenderResource for #struct_name {
fn resource_info(&self) -> Option<#bevy_render_path::render_resource::ResourceInfo> {
Some(#bevy_render_path::render_resource::ResourceInfo::Buffer(None))
fn resource_type(&self) -> Option<#bevy_render_path::render_resource::ResourceType> {
Some(#bevy_render_path::render_resource::ResourceType::Buffer)
}
fn write_buffer_bytes(&self, buffer: &mut [u8]) {
use #bevy_core_path::bytes::Bytes;

View file

@ -1,5 +1,5 @@
use super::texture::Texture;
use crate::{render_resource::{ResourceInfo, RenderResource}, impl_render_resource_bytes};
use crate::{render_resource::{ResourceType, RenderResource}, impl_render_resource_bytes};
use bevy_asset::Handle;
use bevy_core::bytes::{Byteable, Bytes};
use bevy_property::Property;

View file

@ -202,7 +202,7 @@ impl RenderGraph {
});
}
if output_slot.info.resource_info != input_slot.info.resource_info {
if output_slot.info.resource_type != input_slot.info.resource_type {
return Err(RenderGraphError::MismatchedNodeSlots {
output_node,
output_slot: output_index,
@ -309,7 +309,7 @@ mod tests {
use super::RenderGraph;
use crate::{
render_graph::{Edge, Node, NodeId, RenderGraphError, ResourceSlotInfo, ResourceSlots},
renderer::RenderContext, render_resource::ResourceInfo,
renderer::RenderContext, render_resource::ResourceType,
};
use legion::prelude::{Resources, World};
use std::{collections::HashSet, iter::FromIterator};
@ -326,13 +326,13 @@ mod tests {
inputs: (0..inputs)
.map(|i| ResourceSlotInfo {
name: format!("in_{}", i).into(),
resource_info: ResourceInfo::Texture(None),
resource_type: ResourceType::Texture,
})
.collect(),
outputs: (0..outputs)
.map(|i| ResourceSlotInfo {
name: format!("out_{}", i).into(),
resource_info: ResourceInfo::Texture(None),
resource_type: ResourceType::Texture,
})
.collect(),
}

View file

@ -1,5 +1,5 @@
use super::RenderGraphError;
use crate::render_resource::{RenderResourceId, ResourceInfo};
use crate::render_resource::{RenderResourceId, ResourceType};
use std::borrow::Cow;
#[derive(Debug, Clone)]
@ -122,14 +122,14 @@ impl From<&[ResourceSlotInfo]> for ResourceSlots {
#[derive(Clone, Debug)]
pub struct ResourceSlotInfo {
pub name: Cow<'static, str>,
pub resource_info: ResourceInfo,
pub resource_type: ResourceType,
}
impl ResourceSlotInfo {
pub fn new(name: impl Into<Cow<'static, str>>, resource_info: ResourceInfo) -> Self {
pub fn new(name: impl Into<Cow<'static, str>>, resource_type: ResourceType) -> Self {
ResourceSlotInfo {
name: name.into(),
resource_info,
resource_type,
}
}
}

View file

@ -3,7 +3,7 @@ use crate::{
pass::{PassDescriptor, TextureAttachment},
pipeline::PipelineDescriptor,
render_graph::{Node, ResourceSlotInfo, ResourceSlots},
render_resource::{BufferId, RenderResourceBindings, BindGroupId, ResourceInfo},
render_resource::{BufferId, RenderResourceBindings, BindGroupId, ResourceType},
renderer::RenderContext,
};
use bevy_asset::{Assets, Handle};
@ -24,7 +24,7 @@ impl MainPassNode {
if let TextureAttachment::Input(ref name) = color_attachment.attachment {
inputs.push(ResourceSlotInfo::new(
name.to_string(),
ResourceInfo::Texture(None),
ResourceType::Texture,
));
color_attachment_input_indices.push(Some(inputs.len() - 1));
} else {
@ -37,7 +37,7 @@ impl MainPassNode {
if let TextureAttachment::Input(ref name) = depth_stencil_attachment.attachment {
inputs.push(ResourceSlotInfo::new(
name.to_string(),
ResourceInfo::Texture(None),
ResourceType::Texture,
));
depth_stencil_attachment_input_index = Some(inputs.len() - 1);
}

View file

@ -11,7 +11,7 @@ use crate::{
use bevy_asset::{Assets, Handle};
use legion::prelude::*;
use render_resource::{BufferId, ResourceInfo};
use render_resource::{BufferId, ResourceType};
use std::{collections::HashMap, marker::PhantomData};
pub const BIND_BUFFER_ALIGNMENT: usize = 256;
@ -97,7 +97,7 @@ where
.resize_with(uniforms.render_resources_len(), || None);
}
for (i, render_resource) in uniforms.iter_render_resources().enumerate() {
if let Some(ResourceInfo::Buffer(_)) = render_resource.resource_info() {
if let Some(ResourceType::Buffer) = render_resource.resource_type() {
let render_resource_name = uniforms.get_render_resource_name(i).unwrap();
let size = render_resource.buffer_byte_len().unwrap();
if let Some((ref _name, ref mut buffer_array_status)) = self.uniform_arrays[i] {
@ -201,8 +201,8 @@ where
staging_buffer: &mut [u8],
) {
for (i, render_resource) in uniforms.iter_render_resources().enumerate() {
match render_resource.resource_info() {
Some(ResourceInfo::Buffer(_)) => {
match render_resource.resource_type() {
Some(ResourceType::Buffer) => {
let size = render_resource.buffer_byte_len().unwrap();
let render_resource_name = uniforms.get_render_resource_name(i).unwrap();
let (_name, uniform_buffer_status) = self.uniform_arrays[i].as_mut().unwrap();
@ -293,8 +293,8 @@ where
});
uniform_buffer_status.current_offset += size;
}
Some(ResourceInfo::Texture(_)) => { /* ignore textures */ }
Some(ResourceInfo::Sampler) => { /* ignore samplers */ }
Some(ResourceType::Texture) => { /* ignore textures */ }
Some(ResourceType::Sampler) => { /* ignore samplers */ }
None => { /* ignore None */ }
}
}
@ -616,7 +616,7 @@ fn setup_uniform_texture_resources<T>(
T: render_resource::RenderResources,
{
for (i, render_resource) in uniforms.iter_render_resources().enumerate() {
if let Some(ResourceInfo::Texture(_)) = render_resource.resource_info() {
if let Some(ResourceType::Texture) = render_resource.resource_type() {
let render_resource_name = uniforms.get_render_resource_name(i).unwrap();
let sampler_name = format!("{}_sampler", render_resource_name);
if let Some(texture_handle) = render_resource.texture() {

View file

@ -1,6 +1,6 @@
use crate::{
render_graph::{Node, ResourceSlotInfo, ResourceSlots},
render_resource::{RenderResourceId, ResourceInfo},
render_resource::{RenderResourceId, ResourceType},
renderer::RenderContext,
};
use bevy_app::{EventReader, Events};
@ -29,7 +29,7 @@ impl Node for WindowSwapChainNode {
fn output(&self) -> &[ResourceSlotInfo] {
static OUTPUT: &[ResourceSlotInfo] = &[ResourceSlotInfo {
name: Cow::Borrowed(WindowSwapChainNode::OUT_TEXTURE),
resource_info: ResourceInfo::Texture(None),
resource_type: ResourceType::Texture,
}];
OUTPUT
}

View file

@ -1,6 +1,6 @@
use crate::{
render_graph::{Node, ResourceSlotInfo, ResourceSlots},
render_resource::{RenderResourceId, ResourceInfo},
render_resource::{RenderResourceId, ResourceType},
renderer::RenderContext,
texture::TextureDescriptor,
};
@ -32,7 +32,7 @@ impl Node for WindowTextureNode {
fn output(&self) -> &[ResourceSlotInfo] {
static OUTPUT: &[ResourceSlotInfo] = &[ResourceSlotInfo {
name: Cow::Borrowed(WindowTextureNode::OUT_TEXTURE),
resource_info: ResourceInfo::Texture(None),
resource_type: ResourceType::Texture,
}];
OUTPUT
}

View file

@ -264,8 +264,7 @@ mod tests {
use super::{DependentNodeStager, OrderedJob, RenderGraphStager, Stage};
use crate::{
render_graph::{Node, NodeId, RenderGraph, ResourceSlotInfo, ResourceSlots},
render_resource::ResourceInfo,
renderer::RenderContext,
renderer::RenderContext, render_resource::ResourceType,
};
use legion::prelude::{Resources, World};
@ -280,13 +279,13 @@ mod tests {
inputs: (0..inputs)
.map(|i| ResourceSlotInfo {
name: format!("in_{}", i).into(),
resource_info: ResourceInfo::Texture(None),
resource_type: ResourceType::Texture,
})
.collect(),
outputs: (0..outputs)
.map(|i| ResourceSlotInfo {
name: format!("out_{}", i).into(),
resource_info: ResourceInfo::Texture(None),
resource_type: ResourceType::Texture,
})
.collect(),
}

View file

@ -9,6 +9,20 @@ impl BufferId {
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct BufferInfo {
pub size: usize,
pub buffer_usage: BufferUsage,
}
impl Default for BufferInfo {
fn default() -> Self {
BufferInfo {
size: 0,
buffer_usage: BufferUsage::empty(),
}
}
}
bitflags::bitflags! {
#[repr(transparent)]

View file

@ -4,7 +4,6 @@ mod shared_buffer;
mod render_resource;
mod bind_group;
mod render_resource_bindings;
mod resource_info;
mod systems;
pub use buffer::*;
@ -13,5 +12,4 @@ pub use shared_buffer::*;
pub use render_resource::*;
pub use bind_group::*;
pub use render_resource_bindings::*;
pub use resource_info::*;
pub use systems::*;

View file

@ -1,4 +1,4 @@
use super::{BufferId, ResourceInfo, SamplerId, TextureId};
use super::{BufferId, SamplerId, TextureId};
use crate::texture::Texture;
use bevy_asset::Handle;
@ -6,6 +6,14 @@ use bevy_core::bytes::{Byteable, Bytes};
pub use bevy_derive::{RenderResource, RenderResources};
use glam::{Mat4, Vec2, Vec3, Vec4};
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ResourceType {
Buffer,
Texture,
Sampler,
}
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub enum RenderResourceId {
Buffer(BufferId),
@ -65,7 +73,7 @@ bitflags::bitflags! {
}
pub trait RenderResource {
fn resource_info(&self) -> Option<ResourceInfo>;
fn resource_type(&self) -> Option<ResourceType>;
fn write_buffer_bytes(&self, buffer: &mut [u8]);
fn buffer_byte_len(&self) -> Option<usize>;
// TODO: consider making these panic by default, but return non-options
@ -115,8 +123,8 @@ impl<'a> Iterator for RenderResourceIterator<'a> {
macro_rules! impl_render_resource_bytes {
($ty:ident) => {
impl RenderResource for $ty {
fn resource_info(&self) -> Option<ResourceInfo> {
Some(ResourceInfo::Buffer(None))
fn resource_type(&self) -> Option<ResourceType> {
Some(ResourceType::Buffer)
}
fn write_buffer_bytes(&self, buffer: &mut [u8]) {
self.write_bytes(buffer);
@ -151,8 +159,8 @@ impl<T> RenderResource for Vec<T>
where
T: Sized + Byteable,
{
fn resource_info(&self) -> Option<ResourceInfo> {
Some(ResourceInfo::Buffer(None))
fn resource_type(&self) -> Option<ResourceType> {
Some(ResourceType::Buffer)
}
fn write_buffer_bytes(&self, buffer: &mut [u8]) {
self.write_bytes(buffer);

View file

@ -1,23 +0,0 @@
use crate::{render_resource::BufferUsage, texture::TextureDescriptor};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct BufferInfo {
pub size: usize,
pub buffer_usage: BufferUsage,
}
impl Default for BufferInfo {
fn default() -> Self {
BufferInfo {
size: 0,
buffer_usage: BufferUsage::empty(),
}
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ResourceInfo {
Buffer(Option<BufferInfo>),
Texture(Option<TextureDescriptor>),
Sampler,
}

View file

@ -1,6 +1,6 @@
use super::{SamplerDescriptor, TextureDescriptor};
use crate::{
render_resource::{RenderResource, RenderResourceId, ResourceInfo},
render_resource::{RenderResource, RenderResourceId, ResourceType},
renderer::RenderResourceContext,
};
use bevy_app::{EventReader, Events};
@ -118,8 +118,8 @@ pub struct TextureResourceSystemState {
}
impl RenderResource for Option<Handle<Texture>> {
fn resource_info(&self) -> Option<ResourceInfo> {
self.map(|_texture| ResourceInfo::Texture(None))
fn resource_type(&self) -> Option<ResourceType> {
self.map(|_texture| ResourceType::Texture)
}
fn write_buffer_bytes(&self, _buffer: &mut [u8]) {}
fn buffer_byte_len(&self) -> Option<usize> {
@ -131,8 +131,8 @@ impl RenderResource for Option<Handle<Texture>> {
}
impl RenderResource for Handle<Texture> {
fn resource_info(&self) -> Option<ResourceInfo> {
Some(ResourceInfo::Texture(None))
fn resource_type(&self) -> Option<ResourceType> {
Some(ResourceType::Texture)
}
fn write_buffer_bytes(&self, _buffer: &mut [u8]) {}
fn buffer_byte_len(&self) -> Option<usize> {