Skip to content

Commit

Permalink
Refactor info and builder structs
Browse files Browse the repository at this point in the history
  • Loading branch information
attackgoat committed Feb 18, 2024
1 parent 8cdfdfd commit 3f34a2f
Show file tree
Hide file tree
Showing 47 changed files with 1,371 additions and 408 deletions.
46 changes: 41 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,53 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- `PhysicalDevice::sampler_filter_minmax_properties` added to report properties
- `SamplerInfo::reduction_mode` added to set mode
- `SamplerInfo::LINEAR` and `NEAREST` to make sampler creation easier
- `DeviceInfo` now implements `Default`
- `ComputePipeline::with_name`, `GraphicPipeline::with_name` and `RayTracePipeline::with_name`
debug helper functions
- `AccelerationStructureInfo::generic` function

### Changed

- `Device::image_format_properties` returns an `Option` so that unsupported formats may return
`None` instead of relying on user code to detect `DriverError::Unsupported`
- `ImageInfo::linear_tiling` renamed to `tiling` and type changed from `bool` to `vk::ImageTiling`
- `EventLoop` now produces linear surfaces by default - use `desired_surface_format` to select sRGB
- Information struct trait implementations, field and function naming normalized:
- Constructors no longer return builders
- Use `to_builder` to convert an info struct into a builder
- Use `build` to convert a builder into an info struct
- `AccelerationStructureInfo`
- Function `new_blas` renamed to `blas`
- Function `new_tlas` renamed to `tlas`
- `BufferInfo`
- Function `new` renamed to `device_mem`
- Function `new_mappable` renamed to `host_mem`
- `ComputePipelineInfo` now implements `Copy`, `Eq` and `Hash`
- `DeviceInfo` now implements `Default`
- `GraphicPipelineInfo` now implements `Copy`
- `ImageInfo`
- Constructor parameters reordered: `fmt` now after image size
- Function `new_2d` renamed to `image_2d` (_in addition to `cube`, `image_1d`, etc._)
- Field `linear_tiling` renamed to `tiling` (_type changed from `bool` to `vk::ImageTiling`_)
- `ImageViewInfo::new` function now `const`
- `RayTracePipelineInfo` now implements `Copy`
- `SwapchainInfo`
- Function `new` now returns `SwapchainInfo` (_previously returned `SwapchainInfoBuilder`_)
- Field `format` renamed to `surface`
- Default values for `width` and `height` fields removed
- `ComputePipelineInfo::name`, `GraphicPipelineInfo::name` and `RayTracePipelineInfo::name` have
each been moved to their respective pipeline struct
- `EventLoop` now produces linear surfaces by default - use `desired_surface_format` and `Surface::srgb` to select sRGB
- `Swapchain::present_image` now uses event-based waiting for rendering operations instead of
polling, greatly reducing CPU usage
- Updated `ash-molten` (Mac OS support) to v0.17
- Updated `ash-molten` (_Mac OS support_) to v0.17

### Fixed

- `ComputePipelineInfo::default` now properly sets a default value for `bindless_descriptor_count`

### Removed

- `GraphicPipelineInfo::new` function: Use `Default` implementation instead
- `RayTracePipelineInfo::new` function: Use `Default` implementation instead
- `SamplerInfo::new` function: Use `Default` implementation instead

## [0.10.0] - 2024-02-09

Expand All @@ -38,7 +74,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Information structs are now `#[non_exhaustive]` in order to make future additions minor changes -
update strategies:
- Use `..Default::default()` syntax during struct creation
- Use associated constructor functions such as `ImageInfo::new_2d(..)`
- Use associated constructor functions such as `ImageInfo::new_2d(..)`
- `BufferInfo::can_map` renamed to `BufferInfo::mappable`
- Increase `PoolInfo::DEFAULT_RESOURCE_CAPACITY` from 4 to 16 in order to prevent excess resource
creation
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ profile-with-tracy = ["profiling/profile-with-tracy"]
[dependencies]
ash = ">=0.37.1, <0.38"
ash-window = "0.12"
derive_builder = "0.13"
derive_builder = "0.20"
gpu-allocator = "0.25"
log = "0.4"
ordered-float = "4.1"
Expand Down
12 changes: 6 additions & 6 deletions contrib/screen-13-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Egui {
let ppl = Arc::new(
GraphicPipeline::create(
device,
GraphicPipelineInfo::new()
GraphicPipelineInfoBuilder::default()
.blend(BlendMode {
blend_enable: true,
src_color_blend_factor: vk::BlendFactor::ONE,
Expand Down Expand Up @@ -109,7 +109,7 @@ impl Egui {
let tmp_buf = {
let mut buf = self
.cache
.lease(BufferInfo::new_mappable(
.lease(BufferInfo::host_mem(
(pixels.len() * delta.image.bytes_per_pixel()) as u64,
vk::BufferUsageFlags::TRANSFER_SRC,
))
Expand Down Expand Up @@ -155,10 +155,10 @@ impl Egui {
} else {
let image = AnyImageNode::ImageLease(
self.cache
.lease(ImageInfo::new_2d(
vk::Format::R8G8B8A8_UNORM,
.lease(ImageInfo::image_2d(
delta.image.width() as u32,
delta.image.height() as u32,
vk::Format::R8G8B8A8_UNORM,
vk::ImageUsageFlags::SAMPLED | vk::ImageUsageFlags::TRANSFER_DST,
))
.unwrap()
Expand Down Expand Up @@ -234,7 +234,7 @@ impl Egui {
let idx_buf = {
let mut buf = self
.cache
.lease(BufferInfo::new_mappable(
.lease(BufferInfo::host_mem(
(mesh.indices.len() * 4) as u64,
vk::BufferUsageFlags::INDEX_BUFFER,
))
Expand All @@ -247,7 +247,7 @@ impl Egui {
let vert_buf = {
let mut buf = self
.cache
.lease(BufferInfo::new_mappable(
.lease(BufferInfo::host_mem(
(mesh.vertices.len() * std::mem::size_of::<egui::epaint::Vertex>())
as u64,
vk::BufferUsageFlags::VERTEX_BUFFER,
Expand Down
4 changes: 2 additions & 2 deletions contrib/screen-13-fx/src/bitmap_font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl BitmapFont {
let pipeline = Arc::new(
GraphicPipeline::create(
device,
GraphicPipelineInfo::new().blend(BlendMode::ALPHA),
GraphicPipelineInfoBuilder::default().blend(BlendMode::ALPHA),
[
Shader::new_vertex(
include_spirv!("res/shader/graphic/font.vert", vert).as_slice(),
Expand Down Expand Up @@ -163,7 +163,7 @@ impl BitmapFont {
let vertex_buf_len = 120 * text.chars().count() as vk::DeviceSize;
let mut vertex_buf = self
.cache
.lease(BufferInfo::new_mappable(
.lease(BufferInfo::host_mem(
vertex_buf_len,
vk::BufferUsageFlags::VERTEX_BUFFER,
))
Expand Down
6 changes: 3 additions & 3 deletions contrib/screen-13-fx/src/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl ImageLoader {
Ok(Arc::new(
Image::create(
&self.device,
ImageInfo::new_2d(format, width, height, usage),
ImageInfo::image_2d(width, height, format, usage),
)
.context("Unable to create new image")?,
))
Expand Down Expand Up @@ -159,7 +159,7 @@ impl ImageLoader {
//trace!("pixel_buf_len={pixel_buf_len} pixel_buf_stride={pixel_buf_stride}");

// Lease a temporary buffer from the cache pool
let mut pixel_buf = self.pool.lease(BufferInfo::new_mappable(
let mut pixel_buf = self.pool.lease(BufferInfo::host_mem(
pixel_buf_len,
vk::BufferUsageFlags::STORAGE_BUFFER,
))?;
Expand Down Expand Up @@ -208,7 +208,7 @@ impl ImageLoader {
}
ImageFormat::R8G8 | ImageFormat::R8G8B8A8 => {
// Lease a temporary buffer from the pool
let mut pixel_buf = self.pool.lease(BufferInfo::new_mappable(
let mut pixel_buf = self.pool.lease(BufferInfo::host_mem(
pixels.len() as _,
vk::BufferUsageFlags::TRANSFER_SRC,
))?;
Expand Down
2 changes: 1 addition & 1 deletion contrib/screen-13-fx/src/presenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl GraphicPresenter {
Ok(Self {
pipeline: Arc::new(GraphicPipeline::create(
device,
GraphicPipelineInfo::new(),
GraphicPipelineInfo::default(),
[
Shader::new_vertex(
include_spirv!("res/shader/graphic/present.vert", vert).as_slice(),
Expand Down
7 changes: 3 additions & 4 deletions contrib/screen-13-fx/src/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,15 @@ impl TransitionPipeline {
let a_info = render_graph.node_info(a_image);
let b_info = render_graph.node_info(b_image);

let dest_info = ImageInfo::new_2d(
vk::Format::R8G8B8A8_UNORM,
let dest_info = ImageInfo::image_2d(
a_info.width.max(b_info.width),
a_info.height.max(b_info.height),
vk::Format::R8G8B8A8_UNORM,
vk::ImageUsageFlags::SAMPLED
| vk::ImageUsageFlags::STORAGE
| vk::ImageUsageFlags::TRANSFER_DST
| vk::ImageUsageFlags::TRANSFER_SRC,
)
.build();
);
let dest_image = render_graph.bind_node(self.cache.lease(dest_info).unwrap());

self.apply_to(
Expand Down
8 changes: 3 additions & 5 deletions contrib/screen-13-hot/src/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ impl HotComputePipeline {

let (mut watcher, has_changes) = create_watcher();
if let Ok(compiled_shader) = compile_shader_and_watch(&self.shader, &mut watcher) {
if let Ok(instance) = ComputePipeline::create(
&self.device,
self.instance.info.clone(),
compiled_shader,
) {
if let Ok(instance) =
ComputePipeline::create(&self.device, self.instance.info, compiled_shader)
{
self.has_changes = has_changes;
self.watcher = watcher;
self.instance = Arc::new(instance);
Expand Down
8 changes: 3 additions & 5 deletions contrib/screen-13-hot/src/graphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ impl HotGraphicPipeline {
.map(|shader| compile_shader_and_watch(shader, &mut watcher))
.collect::<Result<Vec<_>, DriverError>>()
{
if let Ok(instance) = GraphicPipeline::create(
&self.device,
self.instance.info.clone(),
compiled_shaders,
) {
if let Ok(instance) =
GraphicPipeline::create(&self.device, self.instance.info, compiled_shaders)
{
self.has_changes = has_changes;
self.watcher = watcher;
self.instance = Arc::new(instance);
Expand Down
2 changes: 1 addition & 1 deletion contrib/screen-13-hot/src/ray_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl HotRayTracePipeline {
{
if let Ok(instance) = RayTracePipeline::create(
&self.device,
self.instance.info.clone(),
self.instance.info,
compiled_shaders,
self.shader_groups.iter().copied(),
) {
Expand Down
16 changes: 8 additions & 8 deletions contrib/screen-13-imgui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ImGui {
let pipeline = Arc::new(
GraphicPipeline::create(
device,
GraphicPipelineInfo::new()
GraphicPipelineInfoBuilder::default()
.blend(BlendMode::PRE_MULTIPLIED_ALPHA)
.cull_mode(vk::CullModeFlags::NONE),
[
Expand Down Expand Up @@ -90,10 +90,10 @@ impl ImGui {
let image = render_graph.bind_node({
let mut image = self
.pool
.lease(ImageInfo::new_2d(
vk::Format::R8G8B8A8_UNORM,
.lease(ImageInfo::image_2d(
window.inner_size().width,
window.inner_size().height,
vk::Format::R8G8B8A8_UNORM,
vk::ImageUsageFlags::COLOR_ATTACHMENT
| vk::ImageUsageFlags::SAMPLED
| vk::ImageUsageFlags::STORAGE
Expand All @@ -119,7 +119,7 @@ impl ImGui {
let indices = cast_slice(draw_list.idx_buffer());
let mut index_buf = self
.pool
.lease(BufferInfo::new_mappable(
.lease(BufferInfo::host_mem(
indices.len() as _,
vk::BufferUsageFlags::INDEX_BUFFER,
))
Expand All @@ -135,7 +135,7 @@ impl ImGui {
let vertex_buf_len = vertices.len() * 20;
let mut vertex_buf = self
.pool
.lease(BufferInfo::new_mappable(
.lease(BufferInfo::host_mem(
vertex_buf_len as _,
vk::BufferUsageFlags::VERTEX_BUFFER,
))
Expand Down Expand Up @@ -266,7 +266,7 @@ impl ImGui {
let temp_buf_len = texture.data.len();
let mut temp_buf = self
.pool
.lease(BufferInfo::new_mappable(
.lease(BufferInfo::host_mem(
temp_buf_len as _,
vk::BufferUsageFlags::TRANSFER_SRC,
))
Expand All @@ -281,10 +281,10 @@ impl ImGui {
let image = render_graph.bind_node({
let mut image = self
.pool
.lease(ImageInfo::new_2d(
vk::Format::R8G8B8A8_UNORM,
.lease(ImageInfo::image_2d(
texture.width,
texture.height,
vk::Format::R8G8B8A8_UNORM,
vk::ImageUsageFlags::SAMPLED
| vk::ImageUsageFlags::STORAGE
| vk::ImageUsageFlags::TRANSFER_DST,
Expand Down
11 changes: 5 additions & 6 deletions examples/aliasing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ use {
fn main() -> Result<(), DriverError> {
pretty_env_logger::init();

let device = Arc::new(Device::create_headless(DeviceInfo::new())?);
let device = Arc::new(Device::create_headless(DeviceInfo::default())?);

// We wrap HashPool in an AliasPool container to enable resource aliasing
let mut pool = AliasPool::new(HashPool::new(&device));

// This is the information we will use to alias image1 and image2
let image_info = ImageInfo::new_2d(
vk::Format::R8G8B8A8_UNORM,
let image_info = ImageInfo::image_2d(
128,
128,
vk::Format::R8G8B8A8_UNORM,
vk::ImageUsageFlags::TRANSFER_SRC | vk::ImageUsageFlags::TRANSFER_DST,
);

Expand All @@ -48,11 +48,10 @@ fn main() -> Result<(), DriverError> {
assert_eq!(image1, image2);

// Let's make up some different, yet compatible, image information:
let image_info = image_info.build();
let image_info = ImageInfo::new_2d(
image_info.fmt,
let image_info = ImageInfo::image_2d(
image_info.width,
image_info.height,
image_info.fmt,
vk::ImageUsageFlags::TRANSFER_DST,
);

Expand Down
4 changes: 2 additions & 2 deletions examples/bindless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ fn create_images(device: &Arc<Device>) -> Result<Vec<Arc<Image>>, DisplayError>
for x in 0..8 {
let texture = Arc::new(Image::create(
device,
ImageInfo::new_2d(
vk::Format::R8G8B8A8_UNORM,
ImageInfo::image_2d(
100,
100,
vk::Format::R8G8B8A8_UNORM,
vk::ImageUsageFlags::SAMPLED | vk::ImageUsageFlags::TRANSFER_DST,
),
)?);
Expand Down
2 changes: 1 addition & 1 deletion examples/cpu_readback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() -> Result<(), DriverError> {
pretty_env_logger::init();

// For this example we directly create a device, but the same thing works using an event loop
let device = Arc::new(Device::create_headless(DeviceInfo::new())?);
let device = Arc::new(Device::create_headless(DeviceInfo::default())?);

let mut render_graph = RenderGraph::new();

Expand Down
8 changes: 4 additions & 4 deletions examples/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ fn main() -> Result<(), screen_13::DisplayError> {
let image = frame.render_graph.bind_node(
Image::create(
frame.device,
ImageInfo::new_2d(
vk::Format::R8G8B8A8_UNORM,
ImageInfo::image_2d(
1024,
1024,
vk::Format::R8G8B8A8_UNORM,
vk::ImageUsageFlags::STORAGE | vk::ImageUsageFlags::TRANSFER_SRC,
),
)
Expand All @@ -115,10 +115,10 @@ fn main() -> Result<(), screen_13::DisplayError> {
let image = frame.render_graph.bind_node(
Image::create(
frame.device,
ImageInfo::new_2d(
vk::Format::UNDEFINED,
ImageInfo::image_2d(
u32::MAX,
u32::MAX,
vk::Format::UNDEFINED,
vk::ImageUsageFlags::RESERVED_22_EXT,
),
)
Expand Down
4 changes: 2 additions & 2 deletions examples/egui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ fn main() -> Result<(), DisplayError> {
event_loop.run(|frame| {
let img = frame.render_graph.bind_node(
cache
.lease(ImageInfo::new_2d(
vk::Format::R8G8B8A8_UNORM,
.lease(ImageInfo::image_2d(
100,
100,
vk::Format::R8G8B8A8_UNORM,
vk::ImageUsageFlags::SAMPLED | vk::ImageUsageFlags::TRANSFER_DST,
))
.unwrap(),
Expand Down
Loading

0 comments on commit 3f34a2f

Please sign in to comment.