From 1636b9efccb9080c65375e9c99f4cceb7b525b71 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Sat, 9 May 2020 00:40:43 +0200 Subject: [PATCH] engine: textures --- assets/BUILD | 1 + assets/test-128px.png | Bin 0 -> 3788 bytes engine/BUILD | 1 + engine/shaders/forward.frag | 7 ++- engine/shaders/forward.vert | 4 ++ engine/src/main.rs | 65 ++++++++++++++++++--------- engine/src/render/renderable.rs | 65 +++++++++++++++++++++++---- engine/src/render/vulkan/data.rs | 7 +-- engine/src/render/vulkan/mod.rs | 11 ++++- engine/src/render/vulkan/pipeline.rs | 51 +++++++++++++++++---- engine/src/util/file.rs | 4 +- 11 files changed, 170 insertions(+), 46 deletions(-) create mode 100644 assets/BUILD create mode 100644 assets/test-128px.png diff --git a/assets/BUILD b/assets/BUILD new file mode 100644 index 0000000..c57d822 --- /dev/null +++ b/assets/BUILD @@ -0,0 +1 @@ +exports_files(["test-128px.png"]) diff --git a/assets/test-128px.png b/assets/test-128px.png new file mode 100644 index 0000000000000000000000000000000000000000..1e7665c5d9b729cd851a613b84e9f1e566b3ec69 GIT binary patch literal 3788 zcmb_fcTm&Yw*EncKnV356{G|~L<9jrrAE-8^m4EO5+Eoohmz0RAs4{MyT2d82er7cuh8hwYT4;c`CN1a%K}In56b z?>#%Fn_3>Ru@QcF(&0(xu1@&Z90ou((ffm|6lPht$rx-WE_sZVuR$+?6=PwD0i3KIkuQaAF*?*%k9F*-GR&sZU`8kah zAA_?ACMZ$!blHm+4k~22%3m(EN+SNc(5ANmMm8C#5|Ik(0V;Xif)#UM4q@UXL%gaK$LtC)auL|I zj`w*_nR=l#wbHyT5q0Gd-zYcS+ZppID(5_ao;`^JNl9_jdEPs-*o&wL3?~=8whnrw z642aAVg>ETh4-epu@S)ebL2I=xVLZN$C@|<0)VRgpOY)B&>&>r2o5r}yab-&;XA~4 z$ZMraecvPzbjdylf${Zq_X`3L0q(9r?ryT7=pZjyV^d2TyBMLv001p8HM(#$Y;a*X z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iSUmT5Ave<-1 zu2#$xE{&|it3%chHtM=e%-Yg;>1SJmEb?XgK5x)&C}j*NhCYdm!vLLf(_8Y7mK6-1!9=);D(F+c)+s{mlwH?)KqjZ~hzDXZ5Tdu;t}3^~?`Y{?9k zPBt&4Pl~#GqXuujI~CipmU{&e(#iS)m2Bj;OcVSR@})iN*J!C#b`RChq2GT_nJ!>0 zJ5RIxO7(=l+%D}0$%RVf>=M;!>sgI@r{Xq4IVYi=o8~9#luq~k46E*?tCf=))DWKD z+E~ZO^aU5^!x3!7*^n==afo5!!py;DZ|i19t=DiGcY3B76#w@IrKHefnci~ybcgTQ z!GD#3|DXu}L-2oXi~n=8{5P%tUC#c8$p5oU{x`Y(->&_$EdPJL;|Iv>j**@A5!Q9GuN1{*p!WYXfaxVGBg#co?B4(~oY;y0 literal 0 HcmV?d00001 diff --git a/engine/BUILD b/engine/BUILD index dc1ce44..b55f09a 100644 --- a/engine/BUILD +++ b/engine/BUILD @@ -38,6 +38,7 @@ rust_binary( data = [ "//engine/shaders:forward_vert", "//engine/shaders:forward_frag", + "//assets:test-128px.png", ], ) diff --git a/engine/shaders/forward.frag b/engine/shaders/forward.frag index e1d1db2..6b4673e 100644 --- a/engine/shaders/forward.frag +++ b/engine/shaders/forward.frag @@ -2,9 +2,14 @@ #version 450 #extension GL_ARB_separate_shader_objects : enable +layout(binding = 0) uniform sampler2D texSampler; + layout(location = 0) in vec3 fragColor; +layout(location = 1) in vec2 fragTexCoord; + layout(location = 0) out vec4 outColor; void main() { - outColor = vec4(fragColor, 1.0); + //outColor = vec4(fragColor, 1.0); + outColor = texture(texSampler, fragTexCoord); } diff --git a/engine/shaders/forward.vert b/engine/shaders/forward.vert index 484d785..10b8572 100644 --- a/engine/shaders/forward.vert +++ b/engine/shaders/forward.vert @@ -8,8 +8,10 @@ layout(push_constant) uniform UniformBufferObject { layout(location = 0) in vec3 pos; layout(location = 1) in vec3 color; layout(location = 2) in mat4 model; +layout(location = 6) in vec2 tex; layout(location = 0) out vec3 fragColor; +layout(location = 1) out vec2 fragTexCoord; out gl_PerVertex { vec4 gl_Position; @@ -19,6 +21,8 @@ void main() { gl_Position = ubo.view * model * vec4(pos, 1.0); fragColor = color; + fragTexCoord = tex; + // Vulkanize gl_Position.y = -gl_Position.y; } diff --git a/engine/src/main.rs b/engine/src/main.rs index 83f69ca..b923b9d 100644 --- a/engine/src/main.rs +++ b/engine/src/main.rs @@ -17,33 +17,55 @@ fn main() { let mesh_cube = { let vertices = Arc::new(vec![ - data::Vertex::new([-0.5, -0.5, -0.5], [1.0, 0.0, 0.0]), - data::Vertex::new([0.5, -0.5, -0.5], [0.0, 1.0, 0.0]), - data::Vertex::new([0.5, 0.5, -0.5], [0.0, 0.0, 1.0]), - data::Vertex::new([-0.5, 0.5, -0.5], [1.0, 1.0, 1.0]), - data::Vertex::new([-0.5, -0.5, 0.5], [1.0, 1.0, 1.0]), - data::Vertex::new([0.5, -0.5, 0.5], [1.0, 1.0, 0.0]), - data::Vertex::new([0.5, 0.5, 0.5], [0.0, 1.0, 1.0]), - data::Vertex::new([-0.5, 0.5, 0.5], [1.0, 0.0, 1.0]), + data::Vertex::new([-0.5, -0.5, 0.5], [1.0, 1.0, 1.0], [1.0, 0.0]), + data::Vertex::new([0.5, -0.5, 0.5], [1.0, 1.0, 0.0], [0.0, 0.0]), + data::Vertex::new([0.5, 0.5, 0.5], [0.0, 1.0, 1.0], [0.0, 1.0]), + data::Vertex::new([-0.5, 0.5, 0.5], [1.0, 0.0, 1.0], [1.0, 1.0]), + + data::Vertex::new([0.5, -0.5, -0.5], [1.0, 1.0, 1.0], [0.0, 1.0]), + data::Vertex::new([0.5, 0.5, -0.5], [1.0, 1.0, 0.0], [1.0, 1.0]), + data::Vertex::new([0.5, 0.5, 0.5], [0.0, 1.0, 1.0], [1.0, 0.0]), + data::Vertex::new([0.5, -0.5, 0.5], [1.0, 0.0, 1.0], [0.0, 0.0]), + + data::Vertex::new([-0.5, -0.5, -0.5], [1.0, 1.0, 1.0], [1.0, 1.0]), + data::Vertex::new([-0.5, 0.5, -0.5], [1.0, 1.0, 0.0], [0.0, 1.0]), + data::Vertex::new([-0.5, 0.5, 0.5], [0.0, 1.0, 1.0], [0.0, 0.0]), + data::Vertex::new([-0.5, -0.5, 0.5], [1.0, 0.0, 1.0], [1.0, 0.0]), + + data::Vertex::new([-0.5, -0.5, -0.5], [1.0, 1.0, 1.0], [0.0, 1.0]), + data::Vertex::new([0.5, -0.5, -0.5], [1.0, 1.0, 0.0], [1.0, 1.0]), + data::Vertex::new([0.5, -0.5, 0.5], [0.0, 1.0, 1.0], [1.0, 0.0]), + data::Vertex::new([-0.5, -0.5, 0.5], [1.0, 0.0, 1.0], [0.0, 0.0]), + + data::Vertex::new([-0.5, 0.5, -0.5], [1.0, 1.0, 1.0], [1.0, 1.0]), + data::Vertex::new([0.5, 0.5, -0.5], [1.0, 1.0, 0.0], [0.0, 1.0]), + data::Vertex::new([0.5, 0.5, 0.5], [0.0, 1.0, 1.0], [0.0, 0.0]), + data::Vertex::new([-0.5, 0.5, 0.5], [1.0, 0.0, 1.0], [1.0, 0.0]), + + data::Vertex::new([-0.5, -0.5, -0.5], [1.0, 1.0, 1.0], [0.0, 0.0]), + data::Vertex::new([0.5, -0.5, -0.5], [1.0, 1.0, 0.0], [1.0, 0.0]), + data::Vertex::new([0.5, 0.5, -0.5], [0.0, 1.0, 1.0], [1.0, 1.0]), + data::Vertex::new([-0.5, 0.5, -0.5], [1.0, 0.0, 1.0], [0.0, 1.0]), ]); let indices = Arc::new(vec![ - // bottom - 2, 1, 0, 0, 3, 2, - // top - 4, 5, 6, 6, 7, 4, + 0, 1, 2, 2, 3, 0, + + 4, 5, 6, 6, 7, 4, + 8, 10, 9, 10, 8, 11, + + 12, 13, 14, 14, 15, 12, + 16, 18, 17, 18, 16, 19, + + 20, 22, 21, 22, 20, 23, - // left - 4, 7, 0, 0, 7, 3, - // right - 5, 1, 6, 6, 1, 2, - // front - 7, 6, 3, 3, 6, 2, - // back - 5, 4, 1, 1, 4, 0, ]); Arc::new(render::renderable::Mesh::new(vertices, indices)) }; + let path = &crate::util::file::resource_path(String::from("assets/test-128px.png")); + let image = Arc::new(image::open(path).unwrap()); + let texture_cube = Arc::new(render::renderable::Texture::new(image)); + let mut renderer = render::Renderer::initialize(); let mut cubes: Vec> = Vec::new(); @@ -53,7 +75,8 @@ fn main() { let transform = cgm::Matrix4::from_translation(cgm::Vector3::new((x as f32)*4.0, (y as f32)*4.0, (z as f32)*4.0)); let cube = render::renderable::Object { mesh: mesh_cube.clone(), - transform + transform, + texture: texture_cube.clone(), }; cubes.push(Arc::new(cube)); } diff --git a/engine/src/render/renderable.rs b/engine/src/render/renderable.rs index 50230d7..10958d9 100644 --- a/engine/src/render/renderable.rs +++ b/engine/src/render/renderable.rs @@ -4,21 +4,64 @@ use std::sync::Mutex; use std::time; use cgmath as cgm; +use image; +use image::GenericImageView; use vulkano::device as vd; use vulkano::buffer as vb; use vulkano::sync::GpuFuture; +use vulkano::format as vf; +use vulkano::image as vm; use crate::render::vulkan::data; pub trait Renderable { - fn render_data(&self) -> Option<(Arc, cgm::Matrix4)> { + fn render_data(&self) -> Option<(Arc, Arc, cgm::Matrix4)> { None } } -struct VulkanData { - vbuffer: Arc>, - ibuffer: Arc>, +pub struct Texture { + image: Arc, + + // vulkan cache + vulkan: Mutex>>>, +} + +impl Texture { + pub fn new( + image: Arc, + ) -> Self { + Self { + image, + vulkan: Mutex::new(None), + } + } + pub fn vulkan_texture( + &self, + graphics_queue: Arc, + ) -> Arc> { + let mut cache = self.vulkan.lock().unwrap(); + match &mut *cache { + Some(data) => data.clone(), + None => { + let width = self.image.width(); + let height = self.image.height(); + let image_rgba = self.image.to_rgba(); + let (image_view, future) = vm::ImmutableImage::from_iter( + image_rgba.into_raw().iter().cloned(), + vm::Dimensions::Dim2d{ width, height }, + vf::Format::R8G8B8A8Unorm, + graphics_queue.clone(), + ).unwrap(); + + future.flush().unwrap(); + + *cache = Some(image_view.clone()); + + image_view + }, + } + } } pub struct Mesh { @@ -27,7 +70,12 @@ pub struct Mesh { id: u64, // vulkan buffers cache - vulkan: Mutex>, + vulkan: Mutex>, +} + +struct MeshVulkanData { + vbuffer: Arc>, + ibuffer: Arc>, } impl Mesh { @@ -69,7 +117,7 @@ impl Mesh { vfuture.flush().unwrap(); ifuture.flush().unwrap(); - *cache = Some(VulkanData { + *cache = Some(MeshVulkanData { vbuffer: vbuffer.clone(), ibuffer: ibuffer.clone(), }); @@ -96,11 +144,12 @@ impl Eq for Mesh {} pub struct Object { pub mesh: Arc, + pub texture: Arc, pub transform: cgm::Matrix4, } impl Renderable for Object { - fn render_data(&self) -> Option<(Arc, cgm::Matrix4)> { - Some((self.mesh.clone(), self.transform.clone())) + fn render_data(&self) -> Option<(Arc, Arc, cgm::Matrix4)> { + Some((self.mesh.clone(), self.texture.clone(), self.transform.clone())) } } diff --git a/engine/src/render/vulkan/data.rs b/engine/src/render/vulkan/data.rs index 8053dab..3b2df09 100644 --- a/engine/src/render/vulkan/data.rs +++ b/engine/src/render/vulkan/data.rs @@ -4,16 +4,17 @@ use cgmath as cgm; pub struct Vertex { pos: [f32; 3], color: [f32; 3], + tex: [f32; 2], } impl Vertex { - pub fn new(pos: [f32; 3], color: [f32; 3]) -> Self { + pub fn new(pos: [f32; 3], color: [f32; 3], tex: [f32; 2]) -> Self { Self { - pos, color, + pos, color, tex, } } } -vulkano::impl_vertex!(Vertex, pos, color); +vulkano::impl_vertex!(Vertex, pos, color, tex); #[derive(Default, Copy, Clone)] pub struct Instance { diff --git a/engine/src/render/vulkan/mod.rs b/engine/src/render/vulkan/mod.rs index a987b75..7a60464 100644 --- a/engine/src/render/vulkan/mod.rs +++ b/engine/src/render/vulkan/mod.rs @@ -161,8 +161,10 @@ impl Instance { // Sort renderables by mesh. let mut meshes: HashMap, Vec>> = HashMap::new(); + let mut textures: HashMap, Arc> = HashMap::new(); for r in renderables { - if let Some((mesh, transform)) = r.render_data() { + if let Some((mesh, texture, transform)) = r.render_data() { + textures.entry(mesh.clone()).or_insert(texture); let entry = meshes.entry(mesh.clone()).or_insert(vec![]); entry.push(transform); } @@ -171,6 +173,7 @@ impl Instance { let device = self.surface_binding().device.clone(); let queue = self.surface_binding().graphics_queue.clone(); let rp = self.swapchain_binding().render_pass.clone(); + let pipeline = self.pipeline.as_ref().unwrap().get_pipeline().clone(); for (mesh, transforms) in meshes { @@ -188,9 +191,13 @@ impl Instance { ).unwrap(); future.flush().unwrap(); + let texture = textures.get(&mesh).unwrap().clone(); + let image = texture.vulkan_texture(queue.clone()); + let ds = self.pipeline.as_mut().unwrap().make_descriptor_set(image); + let (vbuffer, ibuffer) = mesh.vulkan_buffers(queue.clone()); builder = builder.draw_indexed(pipeline.clone(), &vc::DynamicState::none(), - vec![vbuffer.clone(), instancebuffer], ibuffer.clone(), (), ubo).unwrap(); + vec![vbuffer.clone(), instancebuffer], ibuffer.clone(), ds, ubo).unwrap(); buffers.push(Box::new(builder.build().unwrap())); } diff --git a/engine/src/render/vulkan/pipeline.rs b/engine/src/render/vulkan/pipeline.rs index e583726..5071e45 100644 --- a/engine/src/render/vulkan/pipeline.rs +++ b/engine/src/render/vulkan/pipeline.rs @@ -11,6 +11,8 @@ use vulkano::framebuffer as vf; use vulkano::pipeline as vp; use vulkano::pipeline::shader as vps; use vulkano::pipeline::vertex as vpv; +use vulkano::sampler as vs; +use vulkano::image as vm; use crate::render::vulkan::data; use crate::render::vulkan::shaders; @@ -20,12 +22,13 @@ type VulkanoDescriptorSet = dyn vdd::DescriptorSet + Send + Sync; pub trait Pipeline { fn get_pipeline(&self) -> Arc; - fn make_descriptor_set(&mut self, buffer: Box) -> Arc; + fn make_descriptor_set(&mut self, texture_image: Arc>) -> Arc; } pub struct Forward { pipeline: Arc, descriptor_set_pool: vdd::FixedSizeDescriptorSetsPool, + device: Arc, } impl Forward { @@ -35,7 +38,7 @@ impl Forward { render_pass: Arc, ) -> Forward { let vertex_shader = shaders::ShaderDefinition { - name: "forward_vert.spv".to_string(), + name: "engine/shaders/forward_vert.spv".to_string(), ty: vps::GraphicsShaderType::Vertex, inputs: vec![ vps::ShaderInterfaceDefEntry { @@ -50,12 +53,20 @@ impl Forward { location: 2..6, format: Format::R32G32B32A32Sfloat, name: Some(Cow::Borrowed("model")), }, + vps::ShaderInterfaceDefEntry { + location: 6..7, format: Format::R32G32Sfloat, + name: Some(Cow::Borrowed("tex")), + }, ], outputs: vec![ vps::ShaderInterfaceDefEntry { location: 0..1, format: Format::R32G32B32Sfloat, name: Some(Cow::Borrowed("fragColor")), - } + }, + vps::ShaderInterfaceDefEntry { + location: 1..2, format: Format::R32G32Sfloat, + name: Some(Cow::Borrowed("fragTexCoord")), + }, ], uniforms: vec![], push_constants: vec![ @@ -71,13 +82,17 @@ impl Forward { }.load_into(device.clone()).expect("could not load vertex shader"); let fragment_shader = shaders::ShaderDefinition { - name: "forward_frag.spv".to_string(), + name: "engine/shaders/forward_frag.spv".to_string(), ty: vps::GraphicsShaderType::Fragment, inputs: vec![ vps::ShaderInterfaceDefEntry { location: 0..1, format: Format::R32G32B32Sfloat, name: Some(Cow::Borrowed("fragColor")), - } + }, + vps::ShaderInterfaceDefEntry { + location: 1..2, format: Format::R32G32Sfloat, + name: Some(Cow::Borrowed("fragTexCoord")), + }, ], outputs: vec![ vps::ShaderInterfaceDefEntry { @@ -85,7 +100,23 @@ impl Forward { name: Some(Cow::Borrowed("outColor")), } ], - uniforms: vec![], + uniforms: vec![ + vdD::DescriptorDesc { + ty: vdD::DescriptorDescTy::CombinedImageSampler(vdD::DescriptorImageDesc { + sampled: true, + dimensions: vdD::DescriptorImageDescDimensions::TwoDimensional, + format: None, + multisampled: false, + array_layers: vdD::DescriptorImageDescArray::NonArrayed, + }), + array_count: 1, + readonly: true, + stages: vdD::ShaderStages { + fragment: true, + ..vdD::ShaderStages::none() + }, + }, + ], push_constants: vec![], }.load_into(device.clone()).expect("could not load fragment shader"); @@ -127,7 +158,8 @@ impl Forward { Forward { pipeline, - descriptor_set_pool + descriptor_set_pool, + device } } } @@ -137,9 +169,10 @@ impl Pipeline for Forward { self.pipeline.clone() } - fn make_descriptor_set(&mut self, buffer: Box) -> Arc { + fn make_descriptor_set(&mut self, texture_image: Arc>) -> Arc { + let image_sampler = vs::Sampler::simple_repeat_linear(self.device.clone()); Arc::new(self.descriptor_set_pool.next() - .add_buffer(buffer).unwrap() + .add_sampled_image(texture_image.clone(), image_sampler).unwrap() .build().unwrap()) } } diff --git a/engine/src/util/file.rs b/engine/src/util/file.rs index d186989..4b5e183 100644 --- a/engine/src/util/file.rs +++ b/engine/src/util/file.rs @@ -6,7 +6,7 @@ pub fn resource_path(name: String) -> path::PathBuf { fn stringify(x: std::io::Error) -> String { format!("IO error: {}", x) } match Runfiles::create().map_err(stringify) { - Err(_) => path::Path::new(".").join("shaders").join(name), - Ok(r) => r.rlocation(format!("abrasion/engine/shaders/{}", name)) + Err(_) => path::Path::new(".").join(name), + Ok(r) => r.rlocation(format!("abrasion/{}", name)) } }