diff --git a/render/wgpu/src/context3d/current_pipeline.rs b/render/wgpu/src/context3d/current_pipeline.rs index 6c830c6b3415..3ca9b577c029 100644 --- a/render/wgpu/src/context3d/current_pipeline.rs +++ b/render/wgpu/src/context3d/current_pipeline.rs @@ -12,12 +12,11 @@ use wgpu::{Buffer, DepthStencilState, StencilFaceState}; use wgpu::{ColorTargetState, RenderPipelineDescriptor, TextureFormat, VertexState}; use std::cell::Cell; -use std::hash::{Hash, Hasher}; use std::num::NonZeroU64; use std::rc::Rc; use crate::bitmaps::WgpuSamplerConfig; -use crate::context3d::shader_pair::ShaderCompileData; +use crate::context3d::shader_pair::{ShaderCompileData, ShaderTextureInfo}; use crate::context3d::VertexBufferWrapper; use crate::descriptors::Descriptors; @@ -93,32 +92,6 @@ pub struct BoundTextureData { pub cube: bool, } -impl Hash for BoundTextureData { - fn hash(&self, state: &mut H) { - // We can't hash 'view', but we can hash the pointer of the 'Rc', - // which is unique to the TextureView - let BoundTextureData { id, cube, view: _ } = self; - (Rc::as_ptr(id) as *const ()).hash(state); - cube.hash(state); - } -} - -impl PartialEq for BoundTextureData { - fn eq(&self, other: &Self) -> bool { - let BoundTextureData { id, cube, view: _ } = self; - let BoundTextureData { - id: other_id, - cube: other_cube, - view: _, - } = other; - std::ptr::eq( - Rc::as_ptr(id) as *const (), - Rc::as_ptr(other_id) as *const (), - ) && cube == other_cube - } -} -impl Eq for BoundTextureData {} - impl CurrentPipeline { pub fn new(descriptors: &Descriptors) -> Self { let vertex_shader_uniforms = descriptors.device.create_buffer(&BufferDescriptor { @@ -345,12 +318,23 @@ impl CurrentPipeline { }) }); + let mut texture_infos = [None; 8]; + for (i, bound_texture) in self.bound_textures.iter().enumerate() { + if let Some(bound_texture) = bound_texture { + if bound_texture.cube { + texture_infos[i] = Some(ShaderTextureInfo::Cube); + } else { + texture_infos[i] = Some(ShaderTextureInfo::D2); + } + } + } + let compiled_shaders = self.shaders.as_ref().expect("Missing shaders!").compile( descriptors, ShaderCompileData { vertex_attributes: agal_attributes, sampler_configs: self.sampler_configs, - bound_textures: self.bound_textures.clone(), + texture_infos, }, ); diff --git a/render/wgpu/src/context3d/shader_pair.rs b/render/wgpu/src/context3d/shader_pair.rs index 297126a56698..03f068fbe1f9 100644 --- a/render/wgpu/src/context3d/shader_pair.rs +++ b/render/wgpu/src/context3d/shader_pair.rs @@ -8,7 +8,7 @@ use std::{ }; use wgpu::SamplerBindingType; -use super::{current_pipeline::BoundTextureData, MAX_VERTEX_ATTRIBUTES}; +use super::MAX_VERTEX_ATTRIBUTES; use crate::descriptors::Descriptors; @@ -110,12 +110,11 @@ impl ShaderPairAgal { }, ]; - for (i, bound_texture) in data.bound_textures.iter().enumerate() { - if let Some(bound_texture) = bound_texture { - let dimension = if bound_texture.cube { - wgpu::TextureViewDimension::Cube - } else { - wgpu::TextureViewDimension::D2 + for (i, texture_info) in data.texture_infos.iter().enumerate() { + if let Some(texture_info) = texture_info { + let dimension = match texture_info { + ShaderTextureInfo::D2 => wgpu::TextureViewDimension::D2, + ShaderTextureInfo::Cube => wgpu::TextureViewDimension::Cube, }; layout_entries.push(wgpu::BindGroupLayoutEntry { binding: naga_agal::TEXTURE_START_BIND_INDEX + i as u32, @@ -155,9 +154,15 @@ impl ShaderPairAgal { } } +#[derive(Hash, PartialEq, Eq, Clone, Copy)] +pub enum ShaderTextureInfo { + D2, + Cube, +} + #[derive(Hash, Eq, PartialEq, Clone)] pub struct ShaderCompileData { pub sampler_configs: [SamplerConfig; 8], pub vertex_attributes: [Option; MAX_VERTEX_ATTRIBUTES], - pub bound_textures: [Option; 8], + pub texture_infos: [Option; 8], }