render: rename RenderResource to RenderResourceId

This commit is contained in:
Carter Anderson 2020-06-07 12:10:14 -07:00
parent c1dcc74e0f
commit 4a71cd128d
14 changed files with 132 additions and 132 deletions

View file

@ -1,15 +1,15 @@
use super::{LoadOp, StoreOp};
use crate::{render_resource::RenderResource, Color};
use crate::{render_resource::RenderResourceId, Color};
#[derive(Debug, Clone)]
pub enum TextureAttachment {
RenderResource(RenderResource),
RenderResource(RenderResourceId),
Name(String),
Input(String),
}
impl TextureAttachment {
pub fn get_resource(&self) -> Option<RenderResource> {
pub fn get_resource(&self) -> Option<RenderResourceId> {
if let TextureAttachment::RenderResource(render_resource) = self {
Some(*render_resource)
} else {

View file

@ -1,6 +1,6 @@
use crate::{
pipeline::PipelineDescriptor,
render_resource::{RenderResource, RenderResourceAssignments},
render_resource::{RenderResourceId, RenderResourceAssignments},
renderer::RenderContext,
};
use bevy_asset::Handle;
@ -8,8 +8,8 @@ use std::ops::Range;
pub trait RenderPass {
fn get_render_context(&self) -> &dyn RenderContext;
fn set_index_buffer(&mut self, resource: RenderResource, offset: u64);
fn set_vertex_buffer(&mut self, start_slot: u32, resource: RenderResource, offset: u64);
fn set_index_buffer(&mut self, resource: RenderResourceId, offset: u64);
fn set_vertex_buffer(&mut self, start_slot: u32, resource: RenderResourceId, offset: u64);
fn set_pipeline(&mut self, pipeline_handle: Handle<PipelineDescriptor>);
fn set_viewport(&mut self, x: f32, y: f32, w: f32, h: f32, min_depth: f32, max_depth: f32);
fn set_stencil_reference(&mut self, reference: u32);

View file

@ -1,26 +1,26 @@
use crate::{render_resource::RenderResource, renderer::RenderContext, texture::Extent3d};
use crate::{render_resource::RenderResourceId, renderer::RenderContext, texture::Extent3d};
use std::sync::{Arc, Mutex};
#[derive(Clone, Debug)]
pub enum Command {
CopyBufferToBuffer {
source_buffer: RenderResource,
source_buffer: RenderResourceId,
source_offset: u64,
destination_buffer: RenderResource,
destination_buffer: RenderResourceId,
destination_offset: u64,
size: u64,
},
CopyBufferToTexture {
source_buffer: RenderResource,
source_buffer: RenderResourceId,
source_offset: u64,
source_bytes_per_row: u32,
destination_texture: RenderResource,
destination_texture: RenderResourceId,
destination_origin: [u32; 3],
destination_mip_level: u32,
size: Extent3d,
},
// TODO: Frees probably don't need to be queued?
FreeBuffer(RenderResource),
FreeBuffer(RenderResourceId),
}
#[derive(Default, Clone)]
@ -36,9 +36,9 @@ impl CommandQueue {
pub fn copy_buffer_to_buffer(
&mut self,
source_buffer: RenderResource,
source_buffer: RenderResourceId,
source_offset: u64,
destination_buffer: RenderResource,
destination_buffer: RenderResourceId,
destination_offset: u64,
size: u64,
) {
@ -53,10 +53,10 @@ impl CommandQueue {
pub fn copy_buffer_to_texture(
&mut self,
source_buffer: RenderResource,
source_buffer: RenderResourceId,
source_offset: u64,
source_bytes_per_row: u32,
destination_texture: RenderResource,
destination_texture: RenderResourceId,
destination_origin: [u32; 3],
destination_mip_level: u32,
size: Extent3d,
@ -72,7 +72,7 @@ impl CommandQueue {
});
}
pub fn free_buffer(&mut self, buffer: RenderResource) {
pub fn free_buffer(&mut self, buffer: RenderResourceId) {
self.push(Command::FreeBuffer(buffer));
}

View file

@ -1,10 +1,10 @@
use super::RenderGraphError;
use crate::{render_resource::RenderResource, shader::FieldBindType};
use crate::{render_resource::RenderResourceId, shader::FieldBindType};
use std::borrow::Cow;
#[derive(Debug, Clone)]
pub struct ResourceSlot {
pub resource: Option<RenderResource>,
pub resource: Option<RenderResourceId>,
pub info: ResourceSlotInfo,
}
@ -44,12 +44,12 @@ impl From<usize> for SlotLabel {
}
impl ResourceSlots {
pub fn set(&mut self, label: impl Into<SlotLabel>, resource: RenderResource) {
pub fn set(&mut self, label: impl Into<SlotLabel>, resource: RenderResourceId) {
let mut slot = self.get_slot_mut(label).unwrap();
slot.resource = Some(resource);
}
pub fn get(&self, label: impl Into<SlotLabel>) -> Option<RenderResource> {
pub fn get(&self, label: impl Into<SlotLabel>) -> Option<RenderResourceId> {
let slot = self.get_slot(label).unwrap();
slot.resource.clone()
}

View file

@ -2,7 +2,7 @@ use crate::{
pipeline::VertexBufferDescriptors,
render_graph::{CommandQueue, Node, ResourceSlots, SystemNode},
render_resource::{
BufferInfo, BufferUsage, EntitiesWaitingForAssets, RenderResource,
BufferInfo, BufferUsage, EntitiesWaitingForAssets, RenderResourceId,
RenderResourceAssignment, RenderResourceAssignments, RenderResourceAssignmentsId,
},
renderer::{RenderContext, RenderResourceContext, RenderResources},
@ -17,7 +17,7 @@ use std::{collections::HashMap, marker::PhantomData};
pub const BIND_BUFFER_ALIGNMENT: usize = 256;
#[derive(Debug)]
struct QueuedBufferWrite {
buffer: RenderResource,
buffer: RenderResourceId,
offset: usize,
}
@ -27,7 +27,7 @@ struct BufferArrayStatus {
item_size: usize,
aligned_size: usize,
staging_buffer_offset: usize,
buffer: Option<RenderResource>,
buffer: Option<RenderResourceId>,
queued_buffer_writes: Vec<QueuedBufferWrite>,
current_item_count: usize,
current_item_capacity: usize,
@ -273,7 +273,7 @@ where
fn copy_staging_buffer_to_final_buffers(
&mut self,
command_queue: &mut CommandQueue,
staging_buffer: RenderResource,
staging_buffer: RenderResourceId,
) {
for uniform_buffer_status in self.uniform_arrays.iter_mut() {
if let Some((_name, buffer_array_status)) = uniform_buffer_status {

View file

@ -2,10 +2,10 @@ use uuid::Uuid;
// TODO: Rename to RenderResourceId
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
pub struct RenderResource(Uuid);
pub struct RenderResourceId(Uuid);
impl RenderResource {
impl RenderResourceId {
pub fn new() -> Self {
RenderResource(Uuid::new_v4())
RenderResourceId(Uuid::new_v4())
}
}

View file

@ -1,4 +1,4 @@
use super::RenderResource;
use super::RenderResourceId;
use crate::pipeline::{BindGroupDescriptor, BindGroupDescriptorId, PipelineSpecialization};
use std::{
collections::{hash_map::DefaultHasher, HashMap, HashSet},
@ -10,16 +10,16 @@ use uuid::Uuid;
#[derive(Clone, Eq, PartialEq, Debug)]
pub enum RenderResourceAssignment {
Buffer {
resource: RenderResource,
resource: RenderResourceId,
range: Range<u64>,
dynamic_index: Option<u32>,
},
Texture(RenderResource),
Sampler(RenderResource),
Texture(RenderResourceId),
Sampler(RenderResourceId),
}
impl RenderResourceAssignment {
pub fn get_resource(&self) -> RenderResource {
pub fn get_resource(&self) -> RenderResourceId {
match self {
RenderResourceAssignment::Buffer { resource, .. } => *resource,
RenderResourceAssignment::Texture(resource) => *resource,
@ -39,7 +39,7 @@ pub struct RenderResourceSet {
pub struct RenderResourceAssignments {
pub id: RenderResourceAssignmentsId,
render_resources: HashMap<String, RenderResourceAssignment>,
vertex_buffers: HashMap<String, (RenderResource, Option<RenderResource>)>,
vertex_buffers: HashMap<String, (RenderResourceId, Option<RenderResourceId>)>,
bind_group_resource_sets: HashMap<BindGroupDescriptorId, RenderResourceSet>,
dirty_bind_groups: HashSet<BindGroupDescriptorId>,
pub pipeline_specialization: PipelineSpecialization,
@ -69,15 +69,15 @@ impl RenderResourceAssignments {
pub fn get_vertex_buffer(
&self,
name: &str,
) -> Option<(RenderResource, Option<RenderResource>)> {
) -> Option<(RenderResourceId, Option<RenderResourceId>)> {
self.vertex_buffers.get(name).cloned()
}
pub fn set_vertex_buffer(
&mut self,
name: &str,
vertices_resource: RenderResource,
indices_resource: Option<RenderResource>,
vertices_resource: RenderResourceId,
indices_resource: Option<RenderResourceId>,
) {
self.vertex_buffers
.insert(name.to_string(), (vertices_resource, indices_resource));
@ -198,10 +198,10 @@ mod tests {
],
);
let resource1 = RenderResourceAssignment::Texture(RenderResource::new());
let resource2 = RenderResourceAssignment::Texture(RenderResource::new());
let resource3 = RenderResourceAssignment::Texture(RenderResource::new());
let resource4 = RenderResourceAssignment::Texture(RenderResource::new());
let resource1 = RenderResourceAssignment::Texture(RenderResourceId::new());
let resource2 = RenderResourceAssignment::Texture(RenderResourceId::new());
let resource3 = RenderResourceAssignment::Texture(RenderResourceId::new());
let resource4 = RenderResourceAssignment::Texture(RenderResourceId::new());
let mut assignments = RenderResourceAssignments::default();
assignments.set("a", resource1.clone());

View file

@ -2,7 +2,7 @@ use super::RenderResourceContext;
use crate::{
pipeline::{BindGroupDescriptor, PipelineDescriptor},
render_resource::{
BufferInfo, RenderResource, RenderResourceAssignments, RenderResourceSetId, ResourceInfo,
BufferInfo, RenderResourceId, RenderResourceAssignments, RenderResourceSetId, ResourceInfo,
},
shader::Shader,
texture::{SamplerDescriptor, TextureDescriptor},
@ -16,12 +16,12 @@ use std::{
#[derive(Default)]
pub struct HeadlessRenderResourceContext {
resource_info: Arc<RwLock<HashMap<RenderResource, ResourceInfo>>>,
pub asset_resources: Arc<RwLock<HashMap<(HandleUntyped, usize), RenderResource>>>,
resource_info: Arc<RwLock<HashMap<RenderResourceId, ResourceInfo>>>,
pub asset_resources: Arc<RwLock<HashMap<(HandleUntyped, usize), RenderResourceId>>>,
}
impl HeadlessRenderResourceContext {
pub fn add_resource_info(&self, resource: RenderResource, resource_info: ResourceInfo) {
pub fn add_resource_info(&self, resource: RenderResourceId, resource_info: ResourceInfo) {
self.resource_info
.write()
.unwrap()
@ -31,23 +31,23 @@ impl HeadlessRenderResourceContext {
impl RenderResourceContext for HeadlessRenderResourceContext {
fn create_swap_chain(&self, _window: &Window) {}
fn next_swap_chain_texture(&self, _window_id: WindowId) -> RenderResource {
RenderResource::new()
fn next_swap_chain_texture(&self, _window_id: WindowId) -> RenderResourceId {
RenderResourceId::new()
}
fn drop_swap_chain_texture(&self, _render_resource: RenderResource) {}
fn drop_swap_chain_texture(&self, _render_resource: RenderResourceId) {}
fn drop_all_swap_chain_textures(&self) {}
fn create_sampler(&self, _sampler_descriptor: &SamplerDescriptor) -> RenderResource {
let resource = RenderResource::new();
fn create_sampler(&self, _sampler_descriptor: &SamplerDescriptor) -> RenderResourceId {
let resource = RenderResourceId::new();
self.add_resource_info(resource, ResourceInfo::Sampler);
resource
}
fn create_texture(&self, texture_descriptor: TextureDescriptor) -> RenderResource {
let resource = RenderResource::new();
fn create_texture(&self, texture_descriptor: TextureDescriptor) -> RenderResourceId {
let resource = RenderResourceId::new();
self.add_resource_info(resource, ResourceInfo::Texture(texture_descriptor));
resource
}
fn create_buffer(&self, buffer_info: BufferInfo) -> RenderResource {
let resource = RenderResource::new();
fn create_buffer(&self, buffer_info: BufferInfo) -> RenderResourceId {
let resource = RenderResourceId::new();
self.add_resource_info(resource, ResourceInfo::Buffer(buffer_info));
resource
}
@ -55,29 +55,29 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
&self,
buffer_info: BufferInfo,
setup_data: &mut dyn FnMut(&mut [u8], &dyn RenderResourceContext),
) -> RenderResource {
) -> RenderResourceId {
let mut buffer = vec![0; buffer_info.size];
setup_data(&mut buffer, self);
RenderResource::new()
RenderResourceId::new()
}
fn create_buffer_with_data(&self, buffer_info: BufferInfo, _data: &[u8]) -> RenderResource {
let resource = RenderResource::new();
fn create_buffer_with_data(&self, buffer_info: BufferInfo, _data: &[u8]) -> RenderResourceId {
let resource = RenderResourceId::new();
self.add_resource_info(resource, ResourceInfo::Buffer(buffer_info));
resource
}
fn create_shader_module(&self, _shader_handle: Handle<Shader>, _shaders: &Assets<Shader>) {}
fn remove_buffer(&self, resource: RenderResource) {
fn remove_buffer(&self, resource: RenderResourceId) {
self.resource_info.write().unwrap().remove(&resource);
}
fn remove_texture(&self, resource: RenderResource) {
fn remove_texture(&self, resource: RenderResourceId) {
self.resource_info.write().unwrap().remove(&resource);
}
fn remove_sampler(&self, resource: RenderResource) {
fn remove_sampler(&self, resource: RenderResourceId) {
self.resource_info.write().unwrap().remove(&resource);
}
fn get_resource_info(
&self,
resource: RenderResource,
resource: RenderResourceId,
handle_info: &mut dyn FnMut(Option<&ResourceInfo>),
) {
handle_info(self.resource_info.read().unwrap().get(&resource));
@ -85,7 +85,7 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
fn set_asset_resource_untyped(
&self,
handle: HandleUntyped,
render_resource: RenderResource,
render_resource: RenderResourceId,
index: usize,
) {
self.asset_resources
@ -97,7 +97,7 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
&self,
handle: HandleUntyped,
index: usize,
) -> Option<RenderResource> {
) -> Option<RenderResourceId> {
self.asset_resources
.write()
.unwrap()

View file

@ -1,7 +1,7 @@
use super::RenderResourceContext;
use crate::{
pass::{PassDescriptor, RenderPass},
render_resource::{RenderResource, RenderResourceAssignments},
render_resource::{RenderResourceId, RenderResourceAssignments},
texture::{Extent3d},
};
@ -10,18 +10,18 @@ pub trait RenderContext {
fn resources_mut(&mut self) -> &mut dyn RenderResourceContext;
fn copy_buffer_to_buffer(
&mut self,
source_buffer: RenderResource,
source_buffer: RenderResourceId,
source_offset: u64,
destination_buffer: RenderResource,
destination_buffer: RenderResourceId,
destination_offset: u64,
size: u64,
);
fn copy_buffer_to_texture(
&mut self,
source_buffer: RenderResource,
source_buffer: RenderResourceId,
source_offset: u64,
source_bytes_per_row: u32,
destination_texture: RenderResource,
destination_texture: RenderResourceId,
destination_origin: [u32; 3],
destination_mip_level: u32,
size: Extent3d,

View file

@ -1,7 +1,7 @@
use crate::{
pipeline::{BindGroupDescriptor, PipelineDescriptor},
render_resource::{
BufferInfo, RenderResource, RenderResourceAssignments, RenderResourceSetId, ResourceInfo,
BufferInfo, RenderResourceId, RenderResourceAssignments, RenderResourceSetId, ResourceInfo,
},
shader::Shader,
texture::{SamplerDescriptor, TextureDescriptor},
@ -27,40 +27,40 @@ impl RenderResources {
pub trait RenderResourceContext: Downcast + Send + Sync + 'static {
fn create_swap_chain(&self, window: &Window);
fn next_swap_chain_texture(&self, window_id: WindowId) -> RenderResource;
fn drop_swap_chain_texture(&self, render_resource: RenderResource);
fn next_swap_chain_texture(&self, window_id: WindowId) -> RenderResourceId;
fn drop_swap_chain_texture(&self, resource: RenderResourceId);
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_buffer(&self, buffer_info: BufferInfo) -> RenderResource;
fn create_sampler(&self, sampler_descriptor: &SamplerDescriptor) -> RenderResourceId;
fn create_texture(&self, texture_descriptor: TextureDescriptor) -> RenderResourceId;
fn create_buffer(&self, buffer_info: BufferInfo) -> RenderResourceId;
// TODO: remove RenderResourceContext here
fn create_buffer_mapped(
&self,
buffer_info: BufferInfo,
setup_data: &mut dyn FnMut(&mut [u8], &dyn RenderResourceContext),
) -> RenderResource;
fn create_buffer_with_data(&self, buffer_info: BufferInfo, data: &[u8]) -> RenderResource;
) -> RenderResourceId;
fn create_buffer_with_data(&self, buffer_info: BufferInfo, data: &[u8]) -> RenderResourceId;
fn create_shader_module(&self, shader_handle: Handle<Shader>, shaders: &Assets<Shader>);
fn create_shader_module_from_source(&self, shader_handle: Handle<Shader>, shader: &Shader);
fn remove_buffer(&self, resource: RenderResource);
fn remove_texture(&self, resource: RenderResource);
fn remove_sampler(&self, resource: RenderResource);
fn remove_buffer(&self, resource: RenderResourceId);
fn remove_texture(&self, resource: RenderResourceId);
fn remove_sampler(&self, resource: RenderResourceId);
fn get_resource_info(
&self,
resource: RenderResource,
resource: RenderResourceId,
handle_info: &mut dyn FnMut(Option<&ResourceInfo>),
);
fn set_asset_resource_untyped(
&self,
handle: HandleUntyped,
render_resource: RenderResource,
resource: RenderResourceId,
index: usize,
);
fn get_asset_resource_untyped(
&self,
handle: HandleUntyped,
index: usize,
) -> Option<RenderResource>;
) -> Option<RenderResourceId>;
fn remove_asset_resource_untyped(&self, handle: HandleUntyped, index: usize);
fn create_render_pipeline(
&self,
@ -90,14 +90,14 @@ impl dyn RenderResourceContext {
pub fn set_asset_resource<T>(
&self,
handle: Handle<T>,
render_resource: RenderResource,
resource: RenderResourceId,
index: usize,
) where
T: 'static,
{
self.set_asset_resource_untyped(handle.into(), render_resource, index);
self.set_asset_resource_untyped(handle.into(), resource, index);
}
pub fn get_asset_resource<T>(&self, handle: Handle<T>, index: usize) -> Option<RenderResource>
pub fn get_asset_resource<T>(&self, handle: Handle<T>, index: usize) -> Option<RenderResourceId>
where
T: 'static,
{

View file

@ -6,7 +6,7 @@ use bevy_render::{
PassDescriptor, RenderPass, RenderPassColorAttachmentDescriptor,
RenderPassDepthStencilAttachmentDescriptor, TextureAttachment,
},
render_resource::{RenderResource, RenderResourceAssignment, RenderResourceAssignments},
render_resource::{RenderResourceId, RenderResourceAssignment, RenderResourceAssignments},
renderer::{RenderContext, RenderResourceContext},
texture::Extent3d,
};
@ -73,9 +73,9 @@ impl WgpuRenderContext {
impl RenderContext for WgpuRenderContext {
fn copy_buffer_to_buffer(
&mut self,
source_buffer: RenderResource,
source_buffer: RenderResourceId,
source_offset: u64,
destination_buffer: RenderResource,
destination_buffer: RenderResourceId,
destination_offset: u64,
size: u64,
) {
@ -91,10 +91,10 @@ impl RenderContext for WgpuRenderContext {
fn copy_buffer_to_texture(
&mut self,
source_buffer: RenderResource,
source_buffer: RenderResourceId,
source_offset: u64,
source_bytes_per_row: u32,
destination_texture: RenderResource,
destination_texture: RenderResourceId,
destination_origin: [u32; 3],
destination_mip_level: u32,
size: Extent3d,

View file

@ -7,7 +7,7 @@ use bevy_asset::{Assets, Handle, HandleUntyped};
use bevy_render::{
pipeline::{BindGroupDescriptor, PipelineDescriptor},
render_resource::{
BufferInfo, RenderResource, RenderResourceAssignment, RenderResourceAssignments,
BufferInfo, RenderResourceId, RenderResourceAssignment, RenderResourceAssignments,
RenderResourceSetId, ResourceInfo,
},
renderer::RenderResourceContext,
@ -39,9 +39,9 @@ impl WgpuRenderResourceContext {
pub fn copy_buffer_to_buffer(
&self,
command_encoder: &mut wgpu::CommandEncoder,
source_buffer: RenderResource,
source_buffer: RenderResourceId,
source_offset: u64,
destination_buffer: RenderResource,
destination_buffer: RenderResourceId,
destination_offset: u64,
size: u64,
) {
@ -61,10 +61,10 @@ impl WgpuRenderResourceContext {
pub fn copy_buffer_to_texture(
&self,
command_encoder: &mut wgpu::CommandEncoder,
source_buffer: RenderResource,
source_buffer: RenderResourceId,
source_offset: u64,
source_bytes_per_row: u32,
destination_texture: RenderResource,
destination_texture: RenderResourceId,
destination_origin: [u32; 3], // TODO: replace with math type
destination_mip_level: u32,
size: Extent3d,
@ -129,20 +129,20 @@ impl WgpuRenderResourceContext {
}
impl RenderResourceContext for WgpuRenderResourceContext {
fn create_sampler(&self, sampler_descriptor: &SamplerDescriptor) -> RenderResource {
fn create_sampler(&self, sampler_descriptor: &SamplerDescriptor) -> RenderResourceId {
let mut samplers = self.resources.samplers.write().unwrap();
let mut resource_info = self.resources.resource_info.write().unwrap();
let descriptor: wgpu::SamplerDescriptor = (*sampler_descriptor).wgpu_into();
let sampler = self.device.create_sampler(&descriptor);
let resource = RenderResource::new();
let resource = RenderResourceId::new();
samplers.insert(resource, sampler);
resource_info.insert(resource, ResourceInfo::Sampler);
resource
}
fn create_texture(&self, texture_descriptor: TextureDescriptor) -> RenderResource {
fn create_texture(&self, texture_descriptor: TextureDescriptor) -> RenderResourceId {
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();
@ -151,14 +151,14 @@ impl RenderResourceContext for WgpuRenderResourceContext {
let texture = self.device.create_texture(&descriptor);
let texture_view = texture.create_default_view();
let resource = RenderResource::new();
let resource = RenderResourceId::new();
resource_info.insert(resource, ResourceInfo::Texture(texture_descriptor));
texture_views.insert(resource, texture_view);
textures.insert(resource, texture);
resource
}
fn create_buffer(&self, buffer_info: BufferInfo) -> RenderResource {
fn create_buffer(&self, buffer_info: BufferInfo) -> RenderResourceId {
// TODO: consider moving this below "create" for efficiency
let mut resource_info = self.resources.resource_info.write().unwrap();
let mut buffers = self.resources.buffers.write().unwrap();
@ -170,7 +170,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
mapped_at_creation: false,
});
let resource = RenderResource::new();
let resource = RenderResourceId::new();
resource_info.insert(resource, ResourceInfo::Buffer(buffer_info));
buffers.insert(resource, buffer);
resource
@ -180,7 +180,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
&self,
buffer_info: BufferInfo,
setup_data: &mut dyn FnMut(&mut [u8], &dyn RenderResourceContext),
) -> RenderResource {
) -> RenderResourceId {
let usage: wgpu::BufferUsage = buffer_info.buffer_usage.wgpu_into();
let buffer = self.device.create_buffer(&wgpu::BufferDescriptor {
size: buffer_info.size as u64,
@ -199,7 +199,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
}
buffer.unmap();
let resource = RenderResource::new();
let resource = RenderResourceId::new();
let mut resource_info = self.resources.resource_info.write().unwrap();
let mut buffers = self.resources.buffers.write().unwrap();
resource_info.insert(resource, ResourceInfo::Buffer(buffer_info));
@ -207,7 +207,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
resource
}
fn create_buffer_with_data(&self, mut buffer_info: BufferInfo, data: &[u8]) -> RenderResource {
fn create_buffer_with_data(&self, mut buffer_info: BufferInfo, data: &[u8]) -> RenderResourceId {
// TODO: consider moving this below "create" for efficiency
let mut resource_info = self.resources.resource_info.write().unwrap();
let mut buffers = self.resources.buffers.write().unwrap();
@ -217,13 +217,13 @@ impl RenderResourceContext for WgpuRenderResourceContext {
.device
.create_buffer_with_data(data, buffer_info.buffer_usage.wgpu_into());
let resource = RenderResource::new();
let resource = RenderResourceId::new();
resource_info.insert(resource, ResourceInfo::Buffer(buffer_info));
buffers.insert(resource, buffer);
resource
}
fn remove_buffer(&self, resource: RenderResource) {
fn remove_buffer(&self, resource: RenderResourceId) {
let mut buffers = self.resources.buffers.write().unwrap();
let mut resource_info = self.resources.resource_info.write().unwrap();
@ -231,7 +231,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
resource_info.remove(&resource);
}
fn remove_texture(&self, resource: RenderResource) {
fn remove_texture(&self, resource: RenderResourceId) {
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();
@ -241,7 +241,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
resource_info.remove(&resource);
}
fn remove_sampler(&self, resource: RenderResource) {
fn remove_sampler(&self, resource: RenderResourceId) {
let mut samplers = self.resources.samplers.write().unwrap();
let mut resource_info = self.resources.resource_info.write().unwrap();
@ -251,7 +251,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
fn get_resource_info(
&self,
resource: RenderResource,
resource: RenderResourceId,
handle_info: &mut dyn FnMut(Option<&ResourceInfo>),
) {
let resource_info = self.resources.resource_info.read().unwrap();
@ -295,7 +295,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
window_swap_chains.insert(window.id, swap_chain);
}
fn next_swap_chain_texture(&self, window_id: bevy_window::WindowId) -> RenderResource {
fn next_swap_chain_texture(&self, window_id: bevy_window::WindowId) -> RenderResourceId {
let mut window_swap_chains = self.resources.window_swap_chains.write().unwrap();
let mut swap_chain_outputs = self.resources.swap_chain_frames.write().unwrap();
@ -303,12 +303,12 @@ impl RenderResourceContext for WgpuRenderResourceContext {
let next_texture = window_swap_chain.get_next_frame().unwrap();
// TODO: Add ResourceInfo
let render_resource = RenderResource::new();
let render_resource = RenderResourceId::new();
swap_chain_outputs.insert(render_resource, next_texture);
render_resource
}
fn drop_swap_chain_texture(&self, render_resource: RenderResource) {
fn drop_swap_chain_texture(&self, render_resource: RenderResourceId) {
let mut swap_chain_outputs = self.resources.swap_chain_frames.write().unwrap();
swap_chain_outputs.remove(&render_resource);
}
@ -321,7 +321,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
fn set_asset_resource_untyped(
&self,
handle: HandleUntyped,
render_resource: RenderResource,
render_resource: RenderResourceId,
index: usize,
) {
let mut asset_resources = self.resources.asset_resources.write().unwrap();
@ -332,7 +332,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
&self,
handle: HandleUntyped,
index: usize,
) -> Option<RenderResource> {
) -> Option<RenderResourceId> {
let asset_resources = self.resources.asset_resources.read().unwrap();
asset_resources.get(&(handle, index)).cloned()
}

View file

@ -4,7 +4,7 @@ use bevy_render::{
pass::RenderPass,
pipeline::PipelineDescriptor,
render_resource::{
RenderResource, RenderResourceAssignments, RenderResourceSetId, ResourceInfo,
RenderResourceId, RenderResourceAssignments, RenderResourceSetId, ResourceInfo,
},
renderer::RenderContext,
};
@ -22,7 +22,7 @@ impl<'a> RenderPass for WgpuRenderPass<'a> {
self.render_context
}
fn set_vertex_buffer(&mut self, start_slot: u32, resource: RenderResource, offset: u64) {
fn set_vertex_buffer(&mut self, start_slot: u32, resource: RenderResourceId, offset: u64) {
let buffer = self.render_resources.buffers.get(&resource).unwrap();
self.render_pass
.set_vertex_buffer(start_slot, buffer.slice(offset..));
@ -37,7 +37,7 @@ impl<'a> RenderPass for WgpuRenderPass<'a> {
self.render_pass.set_stencil_reference(reference);
}
fn set_index_buffer(&mut self, resource: RenderResource, offset: u64) {
fn set_index_buffer(&mut self, resource: RenderResourceId, offset: u64) {
let buffer = self.render_resources.buffers.get(&resource).unwrap();
self.render_pass.set_index_buffer(buffer.slice(offset..));
}

View file

@ -1,7 +1,7 @@
use bevy_asset::{Handle, HandleUntyped};
use bevy_render::{
pipeline::{BindGroupDescriptorId, PipelineDescriptor},
render_resource::{RenderResource, RenderResourceSetId, ResourceInfo},
render_resource::{RenderResourceId, RenderResourceSetId, ResourceInfo},
shader::Shader,
};
use bevy_window::WindowId;
@ -38,9 +38,9 @@ pub struct WgpuBindGroupInfo {
/// Single threaded implementations don't need to worry about these lifetimes constraints at all. RenderPasses can use a RenderContext's
/// WgpuResources directly. RenderContext already has a lifetime greater than the RenderPass.
pub struct WgpuResourcesReadLock<'a> {
pub buffers: RwLockReadGuard<'a, HashMap<RenderResource, wgpu::Buffer>>,
pub textures: RwLockReadGuard<'a, HashMap<RenderResource, wgpu::TextureView>>,
pub swap_chain_frames: RwLockReadGuard<'a, HashMap<RenderResource, wgpu::SwapChainFrame>>,
pub buffers: RwLockReadGuard<'a, HashMap<RenderResourceId, wgpu::Buffer>>,
pub textures: RwLockReadGuard<'a, HashMap<RenderResourceId, wgpu::TextureView>>,
pub swap_chain_frames: RwLockReadGuard<'a, HashMap<RenderResourceId, wgpu::SwapChainFrame>>,
pub render_pipelines:
RwLockReadGuard<'a, HashMap<Handle<PipelineDescriptor>, wgpu::RenderPipeline>>,
pub bind_groups: RwLockReadGuard<'a, HashMap<BindGroupDescriptorId, WgpuBindGroupInfo>>,
@ -60,28 +60,28 @@ impl<'a> WgpuResourcesReadLock<'a> {
/// Stores read only references to WgpuResource collections. See WgpuResourcesReadLock docs for context on why this exists
pub struct WgpuResourceRefs<'a> {
pub buffers: &'a HashMap<RenderResource, wgpu::Buffer>,
pub textures: &'a HashMap<RenderResource, wgpu::TextureView>,
pub swap_chain_frames: &'a HashMap<RenderResource, wgpu::SwapChainFrame>,
pub buffers: &'a HashMap<RenderResourceId, wgpu::Buffer>,
pub textures: &'a HashMap<RenderResourceId, wgpu::TextureView>,
pub swap_chain_frames: &'a HashMap<RenderResourceId, wgpu::SwapChainFrame>,
pub render_pipelines: &'a HashMap<Handle<PipelineDescriptor>, wgpu::RenderPipeline>,
pub bind_groups: &'a HashMap<BindGroupDescriptorId, WgpuBindGroupInfo>,
}
#[derive(Default, Clone)]
pub struct WgpuResources {
pub resource_info: Arc<RwLock<HashMap<RenderResource, ResourceInfo>>>,
pub resource_info: Arc<RwLock<HashMap<RenderResourceId, ResourceInfo>>>,
pub window_surfaces: Arc<RwLock<HashMap<WindowId, wgpu::Surface>>>,
pub window_swap_chains: Arc<RwLock<HashMap<WindowId, wgpu::SwapChain>>>,
pub swap_chain_frames: Arc<RwLock<HashMap<RenderResource, wgpu::SwapChainFrame>>>,
pub buffers: Arc<RwLock<HashMap<RenderResource, wgpu::Buffer>>>,
pub texture_views: Arc<RwLock<HashMap<RenderResource, wgpu::TextureView>>>,
pub textures: Arc<RwLock<HashMap<RenderResource, wgpu::Texture>>>,
pub samplers: Arc<RwLock<HashMap<RenderResource, wgpu::Sampler>>>,
pub swap_chain_frames: Arc<RwLock<HashMap<RenderResourceId, wgpu::SwapChainFrame>>>,
pub buffers: Arc<RwLock<HashMap<RenderResourceId, wgpu::Buffer>>>,
pub texture_views: Arc<RwLock<HashMap<RenderResourceId, wgpu::TextureView>>>,
pub textures: Arc<RwLock<HashMap<RenderResourceId, wgpu::Texture>>>,
pub samplers: Arc<RwLock<HashMap<RenderResourceId, wgpu::Sampler>>>,
pub shader_modules: Arc<RwLock<HashMap<Handle<Shader>, wgpu::ShaderModule>>>,
pub render_pipelines: Arc<RwLock<HashMap<Handle<PipelineDescriptor>, wgpu::RenderPipeline>>>,
pub bind_groups: Arc<RwLock<HashMap<BindGroupDescriptorId, WgpuBindGroupInfo>>>,
pub bind_group_layouts: Arc<RwLock<HashMap<BindGroupDescriptorId, wgpu::BindGroupLayout>>>,
pub asset_resources: Arc<RwLock<HashMap<(HandleUntyped, usize), RenderResource>>>,
pub asset_resources: Arc<RwLock<HashMap<(HandleUntyped, usize), RenderResourceId>>>,
}
impl WgpuResources {