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.
This commit is contained in:
Chad Brokaw 2022-08-17 16:06:48 -04:00
parent c84d1f6df5
commit 6c5a2cb4f4
6 changed files with 8 additions and 5 deletions

View file

@ -87,7 +87,7 @@ impl PgpuRenderer {
.session .session
.image_from_raw_mtl(target, self.width, self.height); .image_from_raw_mtl(target, self.width, self.height);
if let Some(renderer) = &mut self.pgpu_renderer { 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); renderer.record(&mut cmd_buf, &self.query_pool, 0);
// TODO later: we can bind the destination image and avoid the copy. // TODO later: we can bind the destination image and avoid the copy.
cmd_buf.blit_image(&renderer.image_dev, &dst_image); cmd_buf.blit_image(&renderer.image_dev, &dst_image);

View file

@ -331,7 +331,7 @@ impl crate::backend::Device for Dx12Device {
) -> Result<Self::Image, Error> { ) -> Result<Self::Image, Error> {
let format = match format { let format = match format {
ImageFormat::A8 => winapi::shared::dxgiformat::DXGI_FORMAT_R8_UNORM, 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 let resource = self
.device .device

View file

@ -98,6 +98,8 @@ pub enum ImageFormat {
A8, A8,
// 8 bit per pixel RGBA // 8 bit per pixel RGBA
Rgba8, Rgba8,
// Match default surface format
Surface,
} }
bitflags! { bitflags! {

View file

@ -351,7 +351,8 @@ impl crate::backend::Device for MtlDevice {
//desc.set_mipmap_level_count(1); //desc.set_mipmap_level_count(1);
let mtl_format = match format { let mtl_format = match format {
ImageFormat::A8 => metal::MTLPixelFormat::R8Unorm, 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_pixel_format(mtl_format);
desc.set_usage(metal::MTLTextureUsage::ShaderRead | metal::MTLTextureUsage::ShaderWrite); desc.set_usage(metal::MTLTextureUsage::ShaderRead | metal::MTLTextureUsage::ShaderWrite);

View file

@ -588,7 +588,7 @@ impl crate::backend::Device for VkDevice {
| vk::ImageUsageFlags::TRANSFER_DST; | vk::ImageUsageFlags::TRANSFER_DST;
let vk_format = match format { let vk_format = match format {
ImageFormat::A8 => vk::Format::R8_UNORM, 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( let image = device.create_image(
&vk::ImageCreateInfo::builder() &vk::ImageCreateInfo::builder()

View file

@ -224,7 +224,7 @@ impl Renderer {
let image_format = match config.format { let image_format = match config.format {
PixelFormat::A8 => piet_gpu_hal::ImageFormat::A8, 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)?; let image_dev = session.create_image2d(width as u32, height as u32, image_format)?;