Skip to content

Commit

Permalink
[vulkan] Only check supported status once and store the result; Hack …
Browse files Browse the repository at this point in the history
…workaround fix for samizdatco#145
  • Loading branch information
mpaperno committed Aug 16, 2023
1 parent 35ac526 commit f0e6d81
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/gpu/vulkan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ thread_local!(static VK_CONTEXT: RefCell<Option<VulkanEngine>> = RefCell::new(No
pub struct VulkanEngine {
context: gpu::DirectContext,
_ash_graphics: AshGraphics,
_supported: u8,
}

impl VulkanEngine {
Expand All @@ -39,9 +40,34 @@ impl VulkanEngine {

pub fn supported() -> bool {
Self::init();
VK_CONTEXT.with(|cell| cell.borrow().is_some()) && Self::surface(
&ImageInfo::new_n32_premul(ISize::new(100, 100), Some(ColorSpace::new_srgb()))
).is_some()
VK_CONTEXT.with(|cell| {
let mut local_ctx = cell.borrow_mut();
if local_ctx.is_some() {
let this = local_ctx.as_mut().unwrap();
if this._supported == 0 {
let mut context = this.context.clone();
let surface = Surface::new_render_target(
&mut context,
Budgeted::Yes,
&ImageInfo::new_n32_premul(ISize::new(10, 10), Some(ColorSpace::new_srgb())),
Some(4),
SurfaceOrigin::BottomLeft,
None,
true,
);
if surface.is_some() {
this._supported = 1;
}
else {
this._supported = 2;
}
}
this._supported == 1
}
else {
false
}
})
}

fn new() -> Result<Self, String> {
Expand Down Expand Up @@ -76,6 +102,7 @@ impl VulkanEngine {
Ok(Self {
context,
_ash_graphics: ash_graphics,
_supported: 0,
})
}

Expand Down

0 comments on commit f0e6d81

Please sign in to comment.