Skip to content

Commit

Permalink
Merge #217 #218 #221
Browse files Browse the repository at this point in the history
217: add parallel shader compile extensions r=grovesNL a=xyning

used to compile shaders asynchronously to prevent stalls.

* webgl: https://www.khronos.org/registry/webgl/extensions/KHR_parallel_shader_compile/
* gl: https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_parallel_shader_compile.txt
* gl & gles: https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_parallel_shader_compile.txt

its still not widely supported however. most real gles devices dont support it, neither does webgl on firefox

218: Add a `bind_external_framebuffer` function to the web sys context r=grovesNL a=expenses

This is necessary in order to bind the external framebuffer that you get from WebXR: https://developer.mozilla.org/en-US/docs/Web/API/XRWebGLLayer/framebuffer

I'm using this for my branch of wgpu that can render to WebXR framebuffers: gfx-rs/wgpu@master...expenses:webxr

221: Fix some dead code warnings r=grovesNL a=expenses

A recent cargo update is now a lot noiser about dead code, making this crate pretty noisy to compile. I've gone and slapped some ` #[allow(dead_code)]` on a few structs and appending unused variables with `_`.

Co-authored-by: Lictex Steaven <lictex_steaven@outlook.com>
Co-authored-by: Ashley Ruglys <ashley.ruglys@gmail.com>
  • Loading branch information
3 people authored Jun 26, 2022
4 parents cc3b8d3 + d8a692c + a2c98d1 + f30c8dd commit f004530
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 59 deletions.
76 changes: 76 additions & 0 deletions src/gl46.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! * `GL_ARB_framebuffer_object`
//! * `GL_ARB_framebuffer_sRGB`
//! * `GL_ARB_instanced_arrays`
//! * `GL_ARB_parallel_shader_compile`
//! * `GL_ARB_program_interface_query`
//! * `GL_ARB_sampler_objects`
//! * `GL_ARB_sync`
Expand All @@ -30,6 +31,7 @@
//! * `GL_EXT_draw_buffers2`
//! * `GL_EXT_texture_filter_anisotropic`
//! * `GL_KHR_debug`
//! * `GL_KHR_parallel_shader_compile`
//! * `GL_NV_copy_buffer`
//!
//! Supported Features:
Expand Down Expand Up @@ -4943,6 +4945,8 @@ pub mod struct_commands {
self.MapBufferRange_load_with_dyn(get_proc_address);
self.MapNamedBuffer_load_with_dyn(get_proc_address);
self.MapNamedBufferRange_load_with_dyn(get_proc_address);
self.MaxShaderCompilerThreadsARB_load_with_dyn(get_proc_address);
self.MaxShaderCompilerThreadsKHR_load_with_dyn(get_proc_address);
self.MemoryBarrier_load_with_dyn(get_proc_address);
self.MemoryBarrierByRegion_load_with_dyn(get_proc_address);
self.MinSampleShading_load_with_dyn(get_proc_address);
Expand Down Expand Up @@ -21120,6 +21124,76 @@ pub mod struct_commands {
pub fn MapNamedBufferRange_is_loaded(&self) -> bool {
!self.glMapNamedBufferRange_p.load(RELAX).is_null()
}
/// [MaxShaderCompilerThreadsARB](http://docs.gl/gl4/MaxShaderCompilerThreadsARB)(count)
#[cfg_attr(feature = "inline", inline)]
#[cfg_attr(feature = "inline_always", inline(always))]
pub unsafe fn MaxShaderCompilerThreadsARB(&self, count: GLuint) {
#[cfg(all(debug_assertions, feature = "debug_trace_calls"))]
{
trace!("calling gl.MaxShaderCompilerThreadsARB({:?});", count);
}
let out = call_atomic_ptr_1arg(
"MaxShaderCompilerThreadsARB",
&self.glMaxShaderCompilerThreadsARB_p,
count
);
#[cfg(all(debug_assertions, feature = "debug_automatic_glGetError"))]
{
self.automatic_glGetError("glMaxShaderCompilerThreadsARB");
}
out
}
#[doc(hidden)]
pub unsafe fn MaxShaderCompilerThreadsARB_load_with_dyn(
&self,
get_proc_address: &mut dyn FnMut(*const c_char) -> *mut c_void,
) -> bool {
load_dyn_name_atomic_ptr(
get_proc_address,
b"glMaxShaderCompilerThreadsARB\0",
&self.glMaxShaderCompilerThreadsARB_p,
)
}
#[inline]
#[doc(hidden)]
pub fn MaxShaderCompilerThreadsARB_is_loaded(&self) -> bool {
!self.glMaxShaderCompilerThreadsARB_p.load(RELAX).is_null()
}
/// [MaxShaderCompilerThreadsKHR](http://docs.gl/gl4/MaxShaderCompilerThreadsKHR)(count)
#[cfg_attr(feature = "inline", inline)]
#[cfg_attr(feature = "inline_always", inline(always))]
pub unsafe fn MaxShaderCompilerThreadsKHR(&self, count: GLuint) {
#[cfg(all(debug_assertions, feature = "debug_trace_calls"))]
{
trace!("calling gl.MaxShaderCompilerThreadsKHR({:?});", count);
}
let out = call_atomic_ptr_1arg(
"glMaxShaderCompilerThreadsKHR",
&self.glMaxShaderCompilerThreadsKHR_p,
count
);
#[cfg(all(debug_assertions, feature = "debug_automatic_glGetError"))]
{
self.automatic_glGetError("glMaxShaderCompilerThreadsKHR");
}
out
}
#[doc(hidden)]
pub unsafe fn MaxShaderCompilerThreadsKHR_load_with_dyn(
&self,
get_proc_address: &mut dyn FnMut(*const c_char) -> *mut c_void,
) -> bool {
load_dyn_name_atomic_ptr(
get_proc_address,
b"glMaxShaderCompilerThreadsKHR\0",
&self.glMaxShaderCompilerThreadsKHR_p,
)
}
#[inline]
#[doc(hidden)]
pub fn MaxShaderCompilerThreadsKHR_is_loaded(&self) -> bool {
!self.glMaxShaderCompilerThreadsKHR_p.load(RELAX).is_null()
}
/// [glMemoryBarrier](http://docs.gl/gl4/glMemoryBarrier)(barriers)
/// * `barriers` group: MemoryBarrierMask
#[cfg_attr(feature = "inline", inline)]
Expand Down Expand Up @@ -35574,6 +35648,8 @@ pub mod struct_commands {
glMapBufferRange_p: APcv,
glMapNamedBuffer_p: APcv,
glMapNamedBufferRange_p: APcv,
glMaxShaderCompilerThreadsARB_p: APcv,
glMaxShaderCompilerThreadsKHR_p: APcv,
glMemoryBarrier_p: APcv,
glMemoryBarrierByRegion_p: APcv,
glMinSampleShading_p: APcv,
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct ActiveTransformFeedback {
pub name: String,
}

#[allow(dead_code)]
#[derive(Debug)]
pub struct DebugMessageLogEntry {
source: u32,
Expand Down Expand Up @@ -128,6 +129,8 @@ pub trait HasContext {

unsafe fn compile_shader(&self, shader: Self::Shader);

unsafe fn get_shader_completion_status(&self, shader: Self::Shader) -> bool;

unsafe fn get_shader_compile_status(&self, shader: Self::Shader) -> bool;

unsafe fn get_shader_info_log(&self, shader: Self::Shader) -> String;
Expand All @@ -153,6 +156,8 @@ pub trait HasContext {

unsafe fn link_program(&self, program: Self::Program);

unsafe fn get_program_completion_status(&self, program: Self::Program) -> bool;

unsafe fn get_program_link_status(&self, program: Self::Program) -> bool;

unsafe fn get_program_info_log(&self, program: Self::Program) -> String;
Expand Down Expand Up @@ -1233,6 +1238,8 @@ pub trait HasContext {
access: u32,
format: u32,
);

unsafe fn max_shader_compiler_threads(&self, count: u32);
}

pub const ACTIVE_ATOMIC_COUNTER_BUFFERS: u32 = 0x92D9;
Expand Down Expand Up @@ -1545,6 +1552,8 @@ pub const COMPATIBLE_SUBROUTINES: u32 = 0x8E4B;

pub const COMPILE_STATUS: u32 = 0x8B81;

pub const COMPLETION_STATUS: u32 = 0x91B1;

pub const COMPRESSED_R11_EAC: u32 = 0x9270;

pub const COMPRESSED_RED: u32 = 0x8225;
Expand Down Expand Up @@ -2581,6 +2590,8 @@ pub const MAX_SAMPLE_MASK_WORDS: u32 = 0x8E59;

pub const MAX_SERVER_WAIT_TIMEOUT: u32 = 0x9111;

pub const MAX_SHADER_COMPILER_THREADS: u32 = 0x91B0;

pub const MAX_SHADER_STORAGE_BLOCK_SIZE: u32 = 0x90DE;

pub const MAX_SHADER_STORAGE_BUFFER_BINDINGS: u32 = 0x90DD;
Expand Down
23 changes: 23 additions & 0 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ impl HasContext for Context {
gl.CompileShader(shader.0.get());
}

unsafe fn get_shader_completion_status(&self, shader: Self::Shader) -> bool {
let gl = &self.raw;
let mut status = 0;
gl.GetShaderiv(shader.0.get(), COMPLETION_STATUS, &mut status);
1 == status
}

unsafe fn get_shader_compile_status(&self, shader: Self::Shader) -> bool {
let gl = &self.raw;
let mut status = 0;
Expand Down Expand Up @@ -338,6 +345,13 @@ impl HasContext for Context {
gl.LinkProgram(program.0.get());
}

unsafe fn get_program_completion_status(&self, program: Self::Program) -> bool {
let gl = &self.raw;
let mut status = 0;
gl.GetProgramiv(program.0.get(), COMPLETION_STATUS, &mut status);
1 == status
}

unsafe fn get_program_link_status(&self, program: Self::Program) -> bool {
let gl = &self.raw;
let mut status = 0;
Expand Down Expand Up @@ -2963,6 +2977,15 @@ impl HasContext for Context {
String::from("")
}
}

unsafe fn max_shader_compiler_threads(&self, count: u32) {
let gl = &self.raw;
if gl.MaxShaderCompilerThreadsKHR_is_loaded() {
gl.MaxShaderCompilerThreadsKHR(count);
} else {
gl.MaxShaderCompilerThreadsARB(count);
}
}
}

extern "system" fn raw_debug_message_callback<F>(
Expand Down
3 changes: 3 additions & 0 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Version {

impl Version {
/// Create a new OpenGL version number
#[allow(dead_code)]
pub(crate) fn new(major: u32, minor: u32, revision: Option<u32>, vendor_info: String) -> Self {
Version {
major: major,
Expand All @@ -19,7 +20,9 @@ impl Version {
vendor_info,
}
}

/// Create a new OpenGL ES version number
#[allow(dead_code)]
pub(crate) fn new_embedded(major: u32, minor: u32, vendor_info: String) -> Self {
Version {
major,
Expand Down
Loading

0 comments on commit f004530

Please sign in to comment.