diff --git a/piet-gpu-hal/src/dx12.rs b/piet-gpu-hal/src/dx12.rs index 337ca04..78ad449 100644 --- a/piet-gpu-hal/src/dx12.rs +++ b/piet-gpu-hal/src/dx12.rs @@ -21,7 +21,7 @@ use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use smallvec::SmallVec; -use crate::{BindType, BufferUsage, Error, GpuInfo, ImageLayout, MapMode, WorkgroupLimits}; +use crate::{BindType, BufferUsage, Error, GpuInfo, ImageLayout, MapMode, WorkgroupLimits, ImageFormat}; use self::{ descriptor::{CpuHeapRefOwned, DescriptorPool, GpuHeapRefOwned}, @@ -321,8 +321,11 @@ impl crate::backend::Device for Dx12Device { Ok(()) } - unsafe fn create_image2d(&self, width: u32, height: u32) -> Result { - let format = winapi::shared::dxgiformat::DXGI_FORMAT_R8G8B8A8_UNORM; + unsafe fn create_image2d(&self, width: u32, height: u32, format: ImageFormat) -> Result { + let format = match format { + ImageFormat::A8 => winapi::shared::dxgiformat::DXGI_FORMAT_R8_UNORM, + ImageFormat::Rgba8 => winapi::shared::dxgiformat::DXGI_FORMAT_R8G8B8A8_UNORM, + }; let resource = self .device .create_texture2d_buffer(width.into(), height, format, true)?; diff --git a/piet-gpu-hal/src/hub.rs b/piet-gpu-hal/src/hub.rs index ecfc2d4..8c5926a 100644 --- a/piet-gpu-hal/src/hub.rs +++ b/piet-gpu-hal/src/hub.rs @@ -308,10 +308,7 @@ impl Session { } } - /// Create an image. - /// - /// Currently this creates only a 2D image in RGBA8 format, with usage - /// so that it can be accessed by shaders and used for transfer. + /// Create an image of the given size and pixel format. pub unsafe fn create_image2d( &self, width: u32, diff --git a/piet-gpu-hal/src/vulkan.rs b/piet-gpu-hal/src/vulkan.rs index d5b31cb..924e2d6 100644 --- a/piet-gpu-hal/src/vulkan.rs +++ b/piet-gpu-hal/src/vulkan.rs @@ -13,7 +13,7 @@ use smallvec::SmallVec; use crate::backend::Device as DeviceTrait; use crate::{ - BindType, BufferUsage, Error, GpuInfo, ImageLayout, MapMode, SamplerParams, SubgroupSize, + BindType, BufferUsage, Error, GpuInfo, ImageFormat, ImageLayout, MapMode, SamplerParams, SubgroupSize, WorkgroupLimits, }; @@ -533,7 +533,7 @@ impl crate::backend::Device for VkDevice { Ok(()) } - unsafe fn create_image2d(&self, width: u32, height: u32) -> Result { + unsafe fn create_image2d(&self, width: u32, height: u32, format: ImageFormat) -> Result { let device = &self.device.device; let extent = vk::Extent3D { width, @@ -545,10 +545,14 @@ impl crate::backend::Device for VkDevice { let usage = vk::ImageUsageFlags::STORAGE | vk::ImageUsageFlags::TRANSFER_SRC | vk::ImageUsageFlags::TRANSFER_DST; + let vk_format = match format { + ImageFormat::A8 => vk::Format::R8_UNORM, + ImageFormat::Rgba8 => vk::Format::R8G8B8A8_UNORM, + }; let image = device.create_image( &vk::ImageCreateInfo::builder() .image_type(vk::ImageType::TYPE_2D) - .format(vk::Format::R8G8B8A8_UNORM) + .format(vk_format) .extent(extent) .mip_levels(1) .array_layers(1) diff --git a/piet-gpu/src/glyph_render.rs b/piet-gpu/src/glyph_render.rs index b848703..8f4c626 100644 --- a/piet-gpu/src/glyph_render.rs +++ b/piet-gpu/src/glyph_render.rs @@ -17,7 +17,7 @@ //! An experimental API for glyph rendering. use piet::{kurbo::Affine, RenderContext}; -use swash::{scale::ScaleContext, CacheKey, FontDataRef, FontRef}; +use swash::{scale::ScaleContext, CacheKey, FontDataRef}; use crate::{encoder::GlyphEncoder, PietGpuRenderContext};