Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vk: detect prime-select forced to Nvidia #95

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions blade-graphics/src/vulkan/init.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ use ash::{
vk,
};
use naga::back::spv;
use std::{ffi, mem, sync::Mutex};
use std::{ffi, fs, mem, sync::Mutex};

mod db {
pub mod intel {
@@ -16,8 +16,6 @@ mod layer {
unsafe { CStr::from_bytes_with_nul_unchecked(b"VK_LAYER_KHRONOS_validation\0") };
pub const MESA_OVERLAY: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"VK_LAYER_MESA_overlay\0") };
pub const NV_OPTIMUS: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"VK_LAYER_NV_optimus\0") };
}

const REQUIRED_DEVICE_EXTENSIONS: &[&ffi::CStr] = &[
@@ -43,6 +41,14 @@ struct SystemBugs {
intel_unable_to_present_on_xorg: bool,
}

// See https://github.com/canonical/nvidia-prime/blob/587c5012be9dddcc17ab4d958f10a24fa3342b4d/prime-select#L56
fn is_nvidia_prime_forced() -> bool {
match fs::read_to_string("/etc/prime-discrete") {
Ok(contents) => contents == "on\n",
Err(_) => false,
}
}

unsafe fn inspect_adapter(
phd: vk::PhysicalDevice,
instance: &super::Instance,
@@ -341,8 +347,7 @@ impl super::Context {
_ => false,
};
let bugs = SystemBugs {
intel_unable_to_present_on_xorg: is_xorg
&& supported_layer_names.contains(&layer::NV_OPTIMUS),
intel_unable_to_present_on_xorg: is_xorg && is_nvidia_prime_forced(),
};

let vk_surface = surface_handles.map(|(rwh, rdh)| {

Unchanged files with check annotations Beta

gl.dispatch_compute_indirect(indirect_buf.offset as i32);
}
Self::FillBuffer {
ref dst,

Check warning on line 510 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown)

unused variable: `dst`

Check warning on line 510 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `dst`
size,

Check warning on line 511 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown)

unused variable: `size`

Check warning on line 511 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `size`
value,

Check warning on line 512 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown)

unused variable: `value`

Check warning on line 512 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `value`
} => unimplemented!(),
Self::CopyBufferToBuffer {
ref src,
} => {
let format_desc = super::describe_texture_format(dst.format);
let block_info = dst.format.block_info();
let row_texels =

Check warning on line 568 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown)

unused variable: `row_texels`

Check warning on line 568 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `row_texels`
bytes_per_row / block_info.size as u32 * block_info.dimensions.0 as u32;
gl.bind_buffer(glow::PIXEL_UNPACK_BUFFER, Some(src.raw));
gl.bind_texture(dst.target, Some(dst.raw));
gl.bind_buffer(glow::PIXEL_UNPACK_BUFFER, None);
}
Self::CopyTextureToBuffer {
ref src,

Check warning on line 641 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown)

unused variable: `src`

Check warning on line 641 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `src`
ref dst,

Check warning on line 642 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown)

unused variable: `dst`

Check warning on line 642 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `dst`
bytes_per_row,

Check warning on line 643 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown)

unused variable: `bytes_per_row`

Check warning on line 643 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `bytes_per_row`
ref size,

Check warning on line 644 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown)

unused variable: `size`

Check warning on line 644 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `size`
} => unimplemented!(),
Self::ResetFramebuffer => {
for &attachment in COLOR_ATTACHMENTS.iter() {
gl.viewport(0, 0, size[0] as i32, size[1] as i32);
gl.depth_range_f32(depth.start, depth.end);
}
Self::SetScissor(ref rect) => unimplemented!(),

Check warning on line 745 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown)

unused variable: `rect`

Check warning on line 745 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `rect`
Self::SetStencilFunc {
face,

Check warning on line 747 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown)

unused variable: `face`

Check warning on line 747 in blade-graphics/src/gles/command.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `face`
function,
reference,
read_mask,
#![allow(irrefutable_let_patterns)]
use std::{env, path::Path, ptr, sync::Arc};

Check warning on line 3 in examples/init/main.rs

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused import: `ptr`
use blade_graphics as gpu;
use std::{
borrow::Cow,
collections::hash_map::{Entry, HashMap},

Check warning on line 3 in blade-render/src/model/mod.rs

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused imports: `Entry`, `HashMap`

Check warning on line 3 in blade-render/src/model/mod.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused imports: `Entry`, `HashMap`

Check warning on line 3 in blade-render/src/model/mod.rs

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused imports: `Entry`, `HashMap`
fmt, hash, mem,
ops::Range,
ptr, str,
fn cook(
&self,
source: &[u8],

Check warning on line 488 in blade-render/src/model/mod.rs

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused variable: `source`

Check warning on line 488 in blade-render/src/model/mod.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `source`

Check warning on line 488 in blade-render/src/model/mod.rs

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused variable: `source`
extension: &str,
meta: Meta,

Check warning on line 490 in blade-render/src/model/mod.rs

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused variable: `meta`

Check warning on line 490 in blade-render/src/model/mod.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `meta`

Check warning on line 490 in blade-render/src/model/mod.rs

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused variable: `meta`
cooker: Arc<blade_asset::Cooker<Self>>,

Check warning on line 491 in blade-render/src/model/mod.rs

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused variable: `cooker`

Check warning on line 491 in blade-render/src/model/mod.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `cooker`

Check warning on line 491 in blade-render/src/model/mod.rs

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused variable: `cooker`
exe_context: &choir::ExecutionContext,

Check warning on line 492 in blade-render/src/model/mod.rs

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused variable: `exe_context`

Check warning on line 492 in blade-render/src/model/mod.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `exe_context`

Check warning on line 492 in blade-render/src/model/mod.rs

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused variable: `exe_context`
) {
match extension {
#[cfg(feature = "asset")]
use std::{
fmt, io, mem, ptr, slice, str,

Check warning on line 2 in blade-render/src/texture/mod.rs

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused imports: `io`, `mem`, `slice`

Check warning on line 2 in blade-render/src/texture/mod.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused imports: `io`, `mem`, `slice`

Check warning on line 2 in blade-render/src/texture/mod.rs

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused imports: `io`, `mem`, `slice`
sync::{Arc, Mutex},
};
type Output = Texture;
fn cook(
&self,
source: &[u8],

Check warning on line 110 in blade-render/src/texture/mod.rs

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused variable: `source`

Check warning on line 110 in blade-render/src/texture/mod.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `source`

Check warning on line 110 in blade-render/src/texture/mod.rs

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused variable: `source`
extension: &str,
meta: Meta,

Check warning on line 112 in blade-render/src/texture/mod.rs

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused variable: `meta`

Check warning on line 112 in blade-render/src/texture/mod.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `meta`

Check warning on line 112 in blade-render/src/texture/mod.rs

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused variable: `meta`
cooker: Arc<blade_asset::Cooker<Self>>,
exe_context: &choir::ExecutionContext,
) {
use blade_graphics::TextureFormat as Tf;

Check warning on line 116 in blade-render/src/texture/mod.rs

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused import: `blade_graphics::TextureFormat as Tf`

Check warning on line 116 in blade-render/src/texture/mod.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused import: `blade_graphics::TextureFormat as Tf`

Check warning on line 116 in blade-render/src/texture/mod.rs

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused import: `blade_graphics::TextureFormat as Tf`
type LdrTexel = [u8; 4];
type HdrTexel = [f32; 3];
data: PlainData,
}
let src: PlainImage = match extension {

Check warning on line 130 in blade-render/src/texture/mod.rs

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused variable: `src`

Check warning on line 130 in blade-render/src/texture/mod.rs

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `src`

Check warning on line 130 in blade-render/src/texture/mod.rs

GitHub Actions / build (Windows, windows-latest, x86_64-pc-windows-msvc)

unused variable: `src`
#[cfg(feature = "asset")]
"png" => {
profiling::scope!("decode png");