From a6597af52af4b29b162f5ea1703857906d2a0561 Mon Sep 17 00:00:00 2001 From: Chad Brokaw Date: Wed, 17 Aug 2022 16:06:48 -0400 Subject: [PATCH] macOS fixes * Fix call to removed encoded_scene method in pgpu-render * Add new ImageFormat::Surface variant to select a pixel format that matches the platform specific surface format. This makes gradients consistent across platforms. --- pgpu-render/src/render.rs | 2 +- piet-gpu-hal/src/dx12.rs | 2 +- piet-gpu-hal/src/lib.rs | 2 ++ piet-gpu-hal/src/metal.rs | 3 ++- piet-gpu-hal/src/vulkan.rs | 2 +- piet-gpu/src/lib.rs | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pgpu-render/src/render.rs b/pgpu-render/src/render.rs index 4cf9563..6c59997 100644 --- a/pgpu-render/src/render.rs +++ b/pgpu-render/src/render.rs @@ -87,7 +87,7 @@ impl PgpuRenderer { .session .image_from_raw_mtl(target, self.width, self.height); if let Some(renderer) = &mut self.pgpu_renderer { - renderer.upload_scene(&scene.encoded_scene(), 0).unwrap(); + renderer.upload_scene(&scene.0, 0).unwrap(); renderer.record(&mut cmd_buf, &self.query_pool, 0); // TODO later: we can bind the destination image and avoid the copy. cmd_buf.blit_image(&renderer.image_dev, &dst_image); diff --git a/piet-gpu-hal/src/dx12.rs b/piet-gpu-hal/src/dx12.rs index 8d6820b..6cfd8c8 100644 --- a/piet-gpu-hal/src/dx12.rs +++ b/piet-gpu-hal/src/dx12.rs @@ -330,7 +330,7 @@ impl crate::backend::Device for Dx12Device { ) -> Result { let format = match format { ImageFormat::A8 => winapi::shared::dxgiformat::DXGI_FORMAT_R8_UNORM, - ImageFormat::Rgba8 => winapi::shared::dxgiformat::DXGI_FORMAT_R8G8B8A8_UNORM, + ImageFormat::Rgba8 | ImageFormat::Surface => winapi::shared::dxgiformat::DXGI_FORMAT_R8G8B8A8_UNORM, }; let resource = self .device diff --git a/piet-gpu-hal/src/lib.rs b/piet-gpu-hal/src/lib.rs index a1073f4..1e3fa32 100644 --- a/piet-gpu-hal/src/lib.rs +++ b/piet-gpu-hal/src/lib.rs @@ -98,6 +98,8 @@ pub enum ImageFormat { A8, // 8 bit per pixel RGBA Rgba8, + // Match default surface format + Surface, } bitflags! { diff --git a/piet-gpu-hal/src/metal.rs b/piet-gpu-hal/src/metal.rs index 7471d19..a17f448 100644 --- a/piet-gpu-hal/src/metal.rs +++ b/piet-gpu-hal/src/metal.rs @@ -349,7 +349,8 @@ impl crate::backend::Device for MtlDevice { //desc.set_mipmap_level_count(1); let mtl_format = match format { ImageFormat::A8 => metal::MTLPixelFormat::R8Unorm, - ImageFormat::Rgba8 => metal::MTLPixelFormat::BGRA8Unorm, + ImageFormat::Rgba8 => metal::MTLPixelFormat::RGBA8Unorm, + ImageFormat::Surface => metal::MTLPixelFormat::BGRA8Unorm, }; desc.set_pixel_format(mtl_format); desc.set_usage(metal::MTLTextureUsage::ShaderRead | metal::MTLTextureUsage::ShaderWrite); diff --git a/piet-gpu-hal/src/vulkan.rs b/piet-gpu-hal/src/vulkan.rs index 6a790ef..1ce698b 100644 --- a/piet-gpu-hal/src/vulkan.rs +++ b/piet-gpu-hal/src/vulkan.rs @@ -578,7 +578,7 @@ impl crate::backend::Device for VkDevice { | vk::ImageUsageFlags::TRANSFER_DST; let vk_format = match format { ImageFormat::A8 => vk::Format::R8_UNORM, - ImageFormat::Rgba8 => vk::Format::R8G8B8A8_UNORM, + ImageFormat::Rgba8 | ImageFormat::Surface => vk::Format::R8G8B8A8_UNORM, }; let image = device.create_image( &vk::ImageCreateInfo::builder() diff --git a/piet-gpu/src/lib.rs b/piet-gpu/src/lib.rs index b2dfffb..8030234 100644 --- a/piet-gpu/src/lib.rs +++ b/piet-gpu/src/lib.rs @@ -224,7 +224,7 @@ impl Renderer { let image_format = match config.format { PixelFormat::A8 => piet_gpu_hal::ImageFormat::A8, - PixelFormat::Rgba8 => piet_gpu_hal::ImageFormat::Rgba8, + PixelFormat::Rgba8 => piet_gpu_hal::ImageFormat::Surface, }; let image_dev = session.create_image2d(width as u32, height as u32, image_format)?;