Fix non-mac builds

Also updates comment.

We know the implementation is incomplete and needs refinement, but it
seems useful to commit as a starting point for further work.
This commit is contained in:
Raph Levien 2022-02-07 13:54:24 -08:00
parent 2613a7e500
commit b2e7c80d3b
4 changed files with 15 additions and 11 deletions

View file

@ -21,7 +21,7 @@ use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::{BindType, BufferUsage, Error, GpuInfo, ImageLayout, MapMode, WorkgroupLimits}; use crate::{BindType, BufferUsage, Error, GpuInfo, ImageLayout, MapMode, WorkgroupLimits, ImageFormat};
use self::{ use self::{
descriptor::{CpuHeapRefOwned, DescriptorPool, GpuHeapRefOwned}, descriptor::{CpuHeapRefOwned, DescriptorPool, GpuHeapRefOwned},
@ -321,8 +321,11 @@ impl crate::backend::Device for Dx12Device {
Ok(()) Ok(())
} }
unsafe fn create_image2d(&self, width: u32, height: u32) -> Result<Self::Image, Error> { unsafe fn create_image2d(&self, width: u32, height: u32, format: ImageFormat) -> Result<Self::Image, Error> {
let format = winapi::shared::dxgiformat::DXGI_FORMAT_R8G8B8A8_UNORM; 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 let resource = self
.device .device
.create_texture2d_buffer(width.into(), height, format, true)?; .create_texture2d_buffer(width.into(), height, format, true)?;

View file

@ -308,10 +308,7 @@ impl Session {
} }
} }
/// Create an image. /// Create an image of the given size and pixel format.
///
/// Currently this creates only a 2D image in RGBA8 format, with usage
/// so that it can be accessed by shaders and used for transfer.
pub unsafe fn create_image2d( pub unsafe fn create_image2d(
&self, &self,
width: u32, width: u32,

View file

@ -13,7 +13,7 @@ use smallvec::SmallVec;
use crate::backend::Device as DeviceTrait; use crate::backend::Device as DeviceTrait;
use crate::{ use crate::{
BindType, BufferUsage, Error, GpuInfo, ImageLayout, MapMode, SamplerParams, SubgroupSize, BindType, BufferUsage, Error, GpuInfo, ImageFormat, ImageLayout, MapMode, SamplerParams, SubgroupSize,
WorkgroupLimits, WorkgroupLimits,
}; };
@ -533,7 +533,7 @@ impl crate::backend::Device for VkDevice {
Ok(()) Ok(())
} }
unsafe fn create_image2d(&self, width: u32, height: u32) -> Result<Self::Image, Error> { unsafe fn create_image2d(&self, width: u32, height: u32, format: ImageFormat) -> Result<Self::Image, Error> {
let device = &self.device.device; let device = &self.device.device;
let extent = vk::Extent3D { let extent = vk::Extent3D {
width, width,
@ -545,10 +545,14 @@ impl crate::backend::Device for VkDevice {
let usage = vk::ImageUsageFlags::STORAGE let usage = vk::ImageUsageFlags::STORAGE
| vk::ImageUsageFlags::TRANSFER_SRC | vk::ImageUsageFlags::TRANSFER_SRC
| vk::ImageUsageFlags::TRANSFER_DST; | 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( let image = device.create_image(
&vk::ImageCreateInfo::builder() &vk::ImageCreateInfo::builder()
.image_type(vk::ImageType::TYPE_2D) .image_type(vk::ImageType::TYPE_2D)
.format(vk::Format::R8G8B8A8_UNORM) .format(vk_format)
.extent(extent) .extent(extent)
.mip_levels(1) .mip_levels(1)
.array_layers(1) .array_layers(1)

View file

@ -17,7 +17,7 @@
//! An experimental API for glyph rendering. //! An experimental API for glyph rendering.
use piet::{kurbo::Affine, RenderContext}; use piet::{kurbo::Affine, RenderContext};
use swash::{scale::ScaleContext, CacheKey, FontDataRef, FontRef}; use swash::{scale::ScaleContext, CacheKey, FontDataRef};
use crate::{encoder::GlyphEncoder, PietGpuRenderContext}; use crate::{encoder::GlyphEncoder, PietGpuRenderContext};