8000 [Integration / DRAFT] OpenGL correctness and buffer updates from upstream #691, #682 by Tigon32 · Pull Request #2 · Tigon32/miniquad · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
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
Split Diff View
Split
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/integration-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Miniquad integration CI

on:
push:
branches:
- 'integration/**'
pull_request:
branches:
- master
workflow_dispatch:

permissions:
contents: read

jobs:
rust-wasm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install stable Rust and WASM target
run: |
rustup toolchain install stable --profile minimal
rustup default stable
rustup target add wasm32-unknown-unknown
- name: Rust library tests
run: cargo test --lib
- name: WASM library check
run: cargo check --target wasm32-unknown-unknown --lib
- name: Build WASM example
run: cargo build --release --target wasm32-unknown-unknown --example quad
- name: JavaScript syntax check
run: node --check js/gl.js
2 changes: 2 additions & 0 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,8 @@ pub trait RenderingBackend {
/// ```
fn new_buffer(&mut self, type_: BufferType, usage: BufferUsage, data: BufferSource)
-> BufferId;
/// Replace the buffer's contents with `data`, which can be shorter than
/// the buffer: what lies past it is undefined afterwards.
fn buffer_update(&mut self, buffer: BufferId, data: BufferSource);

/// Size of buffer in bytes.
Expand Down
12 changes: 9 additions & 3 deletions src/graphics/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub mod raw_gl {
struct Buffer {
gl_buf: GLuint,
buffer_type: BufferType,
/// The `usage` hint its stores get.
gl_usage: GLenum,
size: usize,
// Dimension of the indices for this buffer,
// used only as a type argument for glDrawElements and can be
Expand Down Expand Up @@ -911,12 +913,11 @@ impl RenderingBackend for GlContext {
}

fn delete_texture(&mut self, texture: TextureId) {
//self.cache.clear_texture_bindings();

let t = self.textures.get(texture);
match &t.raw {
TextureOrRenderbuffer::Texture(raw) => unsafe {
glDeleteTextures(1, raw as *const _);
self.cache.forget_texture(*raw);
},
TextureOrRenderbuffer::Renderbuffer(raw) => unsafe {
glDeleteRenderbuffers(1, raw as *const _);
Expand Down Expand Up @@ -1376,6 +1377,7 @@ impl RenderingBackend for GlContext {
let buffer = Buffer {
gl_buf,
buffer_type: type_,
gl_usage,
size,
index_type,
};
Expand Down Expand Up @@ -1404,7 +1406,11 @@ impl RenderingBackend for GlContext {
self.cache.store_buffer_binding(gl_target);
self.cache
.bind_buffer(gl_target, buffer.gl_buf, buffer.index_type);
unsafe { glBufferSubData(gl_target, 0, size as _, data.ptr as _) };
// A new store for each update, as Metal gives each update a buffer
// of its own. Writing into the store that draws already queued
// still read makes the driver copy it first, and Mali's driver
// waits on all the work it has queued to do so.
unsafe { glBufferData(gl_target, size as _, data.ptr as _, buffer.gl_usage) };
self.cache.restore_buffer_binding(gl_target);
}

Expand Down
19 changes: 19 additions & 0 deletions src/graphics/gl/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ impl GlCache {
self.index_buffer = 0;
}

/// Forgets `texture` wherever the cache records it as bound. Deleting a
/// texture already rebinds those units to 0 in GL, so no GL call is
/// needed; but if the cache kept the name, a texture created later with
/// the same name would be taken as already bound and never be bound.
pub fn forget_texture(&mut self, texture: GLuint) {
for cached in &mut self.textures {
if cached.texture == texture {
*cached = CachedTexture {
target: 0,
texture: 0,
};
}
}
if self.stored_texture == texture {
self.stored_target = 0;
self.stored_texture = 0;
}
}

pub fn clear_texture_bindings(&mut self) {
for ix in 0..MAX_SHADERSTAGE_IMAGES {
if self.textures[ix].texture != 0 {
Expand Down
Loading
0