Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/SecondHalfGames/yakui into …
Browse files Browse the repository at this point in the history
…dep/winit
  • Loading branch information
msparkles committed Jun 29, 2024
2 parents 11f957b + f893ad1 commit 86db33e
Show file tree
Hide file tree
Showing 26 changed files with 243 additions and 122 deletions.
3 changes: 2 additions & 1 deletion crates/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ log = "0.4.17"
pollster = "0.3.0"
profiling = "1.0.6"
tracy-client = { version = "0.15.1", optional = true }
wgpu = "0.19.0"

winit = "0.30.0"
wgpu = "0.20.1"
2 changes: 1 addition & 1 deletion crates/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ yakui-app = { path = "../yakui-app" }
env_logger = "0.10.0"
log = "0.4.17"
pollster = "0.3.0"
wgpu = { version = "0.19.0", features = ["webgl"] }
wgpu = { version = "0.20.1", features = ["webgl"] }
winit = "0.30.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/yakui-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ yakui-winit = { path = "../yakui-winit" }
yakui-wgpu = { path = "../yakui-wgpu" }

profiling = { version = "1.0.6", optional = true }
wgpu = "0.19.0"
winit = { version = "0.30.0" }
wgpu = "0.20.1"
2 changes: 1 addition & 1 deletion crates/yakui-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
[dependencies]
anymap = "0.12.1"
bitflags = "2.4.2"
glam = "0.25.0"
glam = "0.27.0"
keyboard-types = { version = "0.7.0", default-features = false }
log = "0.4.17"
fast-srgb8 = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/yakui-core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::dom::Dom;
type Storage<T> = RefCell<Option<T>>;

thread_local! {
static CURRENT_DOM: Storage<Dom> = RefCell::new(None);
static CURRENT_DOM: Storage<Dom> = const { RefCell::new(None) };
}

/// If there is a DOM currently being updated on this thread, returns a
Expand Down
4 changes: 1 addition & 3 deletions crates/yakui-core/src/geometry/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::f32::INFINITY;

use glam::Vec2;

/// Defines box constraints used for layout.
Expand Down Expand Up @@ -36,7 +34,7 @@ impl Constraints {
pub fn none() -> Self {
Self {
min: Vec2::ZERO,
max: Vec2::new(INFINITY, INFINITY),
max: Vec2::new(f32::INFINITY, f32::INFINITY),
}
}

Expand Down
14 changes: 13 additions & 1 deletion crates/yakui-core/src/paint/paint_dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use crate::dom::Dom;
use crate::geometry::Rect;
use crate::id::{ManagedTextureId, WidgetId};
use crate::layout::LayoutDom;
use crate::paint::{PaintCall, Pipeline};
use crate::widget::PaintContext;

use super::layers::PaintLayers;
use super::primitives::{PaintCall, PaintMesh, Vertex};
use super::primitives::{PaintMesh, Vertex};
use super::texture::{Texture, TextureChange};

/// Contains all information about how to paint the current set of widgets.
Expand Down Expand Up @@ -202,7 +203,18 @@ impl PaintDom {
let vertices = mesh.vertices.into_iter().map(|mut vertex| {
let mut pos = vertex.position * self.scale_factor;
pos += self.unscaled_viewport.pos();

// Currently, we only round the vertices of geometry fed to the text
// pipeline because rounding all geometry causes hairline cracks in
// some geometry, like rounded rectangles.
//
// See: https://github.com/SecondHalfGames/yakui/issues/153
if mesh.pipeline == Pipeline::Text {
pos = pos.round();
}

pos /= self.surface_size;

vertex.position = pos;
vertex
});
Expand Down
16 changes: 16 additions & 0 deletions crates/yakui-core/src/paint/texture.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use glam::UVec2;

/// A texture that is managed by yakui.
#[derive(Clone)]
pub struct Texture {
format: TextureFormat,
size: UVec2,
Expand All @@ -11,6 +12,9 @@ pub struct Texture {

/// How to filter the texture when it needs to be magnified (made larger)
pub mag_filter: TextureFilter,

/// How to handle texture addressing
pub address_mode: AddressMode,
}

impl std::fmt::Debug for Texture {
Expand All @@ -20,6 +24,7 @@ impl std::fmt::Debug for Texture {
.field("size", &self.size)
.field("min_filter", &self.min_filter)
.field("mag_filter", &self.mag_filter)
.field("address_mode", &self.address_mode)
.finish_non_exhaustive()
}
}
Expand All @@ -46,6 +51,16 @@ pub enum TextureFilter {
Nearest,
}

/// Which kind of address mode to use when UVs go outside the range `[0, 1]`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum AddressMode {
/// Clamp to the edge of the texture
ClampToEdge,

/// Repeat the texture
Repeat,
}

impl Texture {
/// Create a new texture from its format, size, and data.
pub fn new(format: TextureFormat, size: UVec2, data: Vec<u8>) -> Self {
Expand All @@ -55,6 +70,7 @@ impl Texture {
data,
min_filter: TextureFilter::Nearest,
mag_filter: TextureFilter::Linear,
address_mode: AddressMode::ClampToEdge,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/yakui-to-image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ edition = "2021"
yakui-core = { path = "../yakui-core" }
yakui-wgpu = { path = "../yakui-wgpu" }

wgpu = "0.19.0"
wgpu = "0.20.1"
image = { version = "0.24.4", default-features = false, features = ["png"] }
pollster = "0.3.0"
54 changes: 33 additions & 21 deletions crates/yakui-vulkan/examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ fn main() {
} => event_loop.exit(),

Event::NewEvents(cause) => {
if cause == winit::event::StartCause::Init {
winit_initializing = true;
} else {
winit_initializing = false;
}
winit_initializing = cause == winit::event::StartCause::Init;
}

Event::AboutToWait => {
Expand Down Expand Up @@ -148,21 +144,18 @@ fn main() {
event:
KeyEvent {
state: ElementState::Released,
physical_key,
physical_key: PhysicalKey::Code(KeyCode::KeyA),
..
},
..
},
..
} => match physical_key {
PhysicalKey::Code(KeyCode::KeyA) => {
gui_state.which_image = match &gui_state.which_image {
WhichImage::Monkey => WhichImage::Dog,
WhichImage::Dog => WhichImage::Monkey,
}
} => {
gui_state.which_image = match &gui_state.which_image {
WhichImage::Monkey => WhichImage::Dog,
WhichImage::Dog => WhichImage::Monkey,
}
_ => {}
},
}
_ => (),
});

Expand All @@ -189,6 +182,7 @@ fn create_vulkan_texture_info(
resolution,
filter,
filter,
vk::SamplerAddressMode::CLAMP_TO_EDGE,
)
}

Expand All @@ -214,7 +208,7 @@ fn gui(gui_state: &GuiState) {
use yakui::{column, label, row, text, widgets::Text, Color};
let (animal, texture): (&'static str, yakui::TextureId) = match gui_state.which_image {
WhichImage::Monkey => ("monkye", gui_state.monkey.into()),
WhichImage::Dog => ("dog haha good boy", gui_state.dog.into()),
WhichImage::Dog => ("dog haha good boy", gui_state.dog),
};
column(|| {
row(|| {
Expand Down Expand Up @@ -277,12 +271,23 @@ impl VulkanTest {
.engine_version(0)
.api_version(vk::make_api_version(0, 1, 3, 0));

let extension_names =
#[allow(unused_mut)]
let mut extension_names =
ash_window::enumerate_required_extensions(window.display_handle().unwrap().as_raw())
.unwrap()
.to_vec();

#[cfg(target_os = "macos")]
extension_names.push(ash::khr::portability_enumeration::NAME.as_ptr());

let create_flags = if cfg!(target_os = "macos") {
vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR
} else {
vk::InstanceCreateFlags::default()
};

let create_info = vk::InstanceCreateInfo::default()
.flags(create_flags)
.application_info(&appinfo)
.enabled_extension_names(&extension_names);

Expand Down Expand Up @@ -337,7 +342,13 @@ impl VulkanTest {
.expect("Couldn't find suitable device.")
};
let queue_family_index = queue_family_index as u32;
let device_extension_names_raw = [ash::khr::swapchain::NAME.as_ptr()];

#[allow(unused_mut)]
let mut device_exts = vec![ash::khr::swapchain::NAME.as_ptr()];

#[cfg(target_os = "macos")]
device_exts.push(ash::khr::portability_subset::NAME.as_ptr());

let priorities = [1.0];

let queue_info = vk::DeviceQueueCreateInfo::default()
Expand All @@ -346,11 +357,12 @@ impl VulkanTest {

let mut descriptor_indexing_features =
vk::PhysicalDeviceDescriptorIndexingFeatures::default()
.descriptor_binding_partially_bound(true);
.descriptor_binding_partially_bound(true)
.descriptor_binding_sampled_image_update_after_bind(true);

let device_create_info = vk::DeviceCreateInfo::default()
.queue_create_infos(std::slice::from_ref(&queue_info))
.enabled_extension_names(&device_extension_names_raw)
.enabled_extension_names(&device_exts)
.push_next(&mut descriptor_indexing_features);

let device = unsafe {
Expand Down Expand Up @@ -572,7 +584,7 @@ impl VulkanTest {
.swapchain_loader
.acquire_next_image(
self.swapchain,
std::u64::MAX,
u64::MAX,
self.present_complete_semaphore,
vk::Fence::null(),
)
Expand All @@ -585,7 +597,7 @@ impl VulkanTest {
.wait_for_fences(
std::slice::from_ref(&self.draw_commands_reuse_fence),
true,
std::u64::MAX,
u64::MAX,
)
.unwrap();
device
Expand Down
5 changes: 4 additions & 1 deletion crates/yakui-vulkan/src/descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl Descriptors {
device.create_descriptor_pool(
&vk::DescriptorPoolCreateInfo::default()
.max_sets(1)
.flags(vk::DescriptorPoolCreateFlags::UPDATE_AFTER_BIND)
.pool_sizes(&[vk::DescriptorPoolSize {
ty: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
descriptor_count: 1000,
Expand All @@ -27,7 +28,8 @@ impl Descriptors {
}
.unwrap();

let flags = [vk::DescriptorBindingFlags::PARTIALLY_BOUND];
let flags = [vk::DescriptorBindingFlags::PARTIALLY_BOUND
| vk::DescriptorBindingFlags::UPDATE_AFTER_BIND];
let mut binding_flags =
vk::DescriptorSetLayoutBindingFlagsCreateInfo::default().binding_flags(&flags);

Expand All @@ -41,6 +43,7 @@ impl Descriptors {
descriptor_count: 1000,
..Default::default()
}])
.flags(vk::DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL)
.push_next(&mut binding_flags),
None,
)
Expand Down
16 changes: 11 additions & 5 deletions crates/yakui-vulkan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub struct Options {
pub dynamic_rendering_format: Option<vk::Format>,
/// Render pass that the GUI will be drawn in. Ignored if `dynamic_rendering_format` is set.
pub render_pass: vk::RenderPass,
/// Subpass that the GUI will be drawn in. Ignored if `dynamic_rendering_format` is set.
pub subpass: u32,
}

#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -319,7 +321,9 @@ impl YakuiVulkan {
.color_attachment_formats(&rendering_info_formats);
graphic_pipeline_info = graphic_pipeline_info.push_next(&mut rendering_info);
} else {
graphic_pipeline_info = graphic_pipeline_info.render_pass(options.render_pass);
graphic_pipeline_info = graphic_pipeline_info
.render_pass(options.render_pass)
.subpass(options.subpass);
}

let graphics_pipelines = unsafe {
Expand Down Expand Up @@ -374,12 +378,12 @@ impl YakuiVulkan {
self.uploads.phase_submitted();
}

/// Call when the commands associated with the oldest call to `commands_submitted` have finished.
/// Call when the commands associated with the oldest call to `transfers_submitted` have finished.
///
/// ## Safety
///
/// Those commands recorded prior to the oldest call to `commands_submitted` not yet associated
/// with a call to `commands_finished` must not be executing.
/// Those commands recorded prior to the oldest call to `transfers_submitted` not yet associated
/// with a call to `transfers_finished` must not be executing.
pub unsafe fn transfers_finished(&mut self, vulkan_context: &VulkanContext) {
self.uploads.phase_executed(vulkan_context);
}
Expand Down Expand Up @@ -607,7 +611,9 @@ impl YakuiVulkan {

TextureChange::Modified => {
if let Some(old) = self.yakui_managed_textures.remove(&id) {
unsafe { old.cleanup(vulkan_context.device) };
unsafe {
self.uploads.dispose(old);
}
}
let new = paint.texture(id).unwrap();
let texture = VulkanTexture::from_yakui_texture(
Expand Down
Loading

0 comments on commit 86db33e

Please sign in to comment.