WebGL renderer does not implement GP0(E6) destination mask protection

Open
#228 0 comments 0 reactions 0 assignees View on GitHub

@ediskandarov is already working on this.

Since Nov 22, 2026.

  • #245 by @ediskandarov — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c
Domain
backend

Research direction

Start by reading Draw_SetMask and the WebGL renderer path that handles GP0(E6); the issue provides a standalone C reproduction and expected framebuffer readback. Compare destination mask behavior with the GP0(E6) rules in PSX-SPX, then check drawing alongside uploads and VRAM copies, which the issue calls out as needing separate coverage. Done means protected destination pixels remain unchanged in the reproduction.

Written by the indexing model from the issue text.

Description

Masked VRAM pixels are overwritten by subsequent drawing. Draw_SetMask reports NOT_IMPLEMENTED for nonzero mask settings.

Tested on PsyZ 35c673e, Emscripten 6.0.13 / WebGL2, Chromium 157 (SwiftShader), macOS arm64.

Reproduction

Download the standalone C example (save as repro.c). No game source, executable or assets required.

All commands go through DrawOTag, deliberately avoiding the independent DrawPrim dispatch defect in #227.

  1. Send GP0(E6) with bit 0 set (0xe6000001) and draw a green square.
  2. Send GP0(E6) with bit 1 set (0xe6000002) and draw an overlapping red square.
  3. Read the framebuffer with StoreImage and DrawSync.

Expected: the overlap remains green because its destination pixels are protected.

Actual: the overlap turns red. At (110, 110), the unmodified backend returns 0x801f; our mask-support prototype returns 0x83e0.

Unmodified PsyZ on the left; mask-support prototype on the right

These are actual 320×240 VRAM readbacks, enlarged 2× with nearest-neighbour scaling. The comparison uses our local mask-support changes, without display, subpixel or perspective changes; it is not a hardware reference capture.

Building the standalone example

Save the attached file as repro.c, and place this CMakeLists.txt beside it:

cmake_minimum_required(VERSION 3.21)
project(drawprim_repro C CXX)
set(CMAKE_C_STANDARD 11)
add_compile_options(-pthread)
add_link_options(-pthread)
set(SDL_PTHREADS ON CACHE BOOL "" FORCE)
add_subdirectory("${PSYZ_ROOT}/psyz" psyz EXCLUDE_FROM_ALL)
add_executable(repro repro.c)
target_link_libraries(repro PRIVATE psyz)
target_link_options(repro PRIVATE -sASSERTIONS=1 -sPTHREAD_POOL_SIZE=2)
psyz_web_configure_target(repro OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/site")

Use a PsyZ checkout at the revision above, with its SDL submodule initialized:

emcmake cmake -S . -B build -DPSYZ_ROOT=/path/to/psyz -DCMAKE_BUILD_TYPE=Release
cmake --build build -j8

Serve build/site locally with Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp, as required by Emscripten pthreads. Open index.html. The example appends a canvas containing the VRAM readback below the normal page content; scroll down if necessary. It also logs GPU readback ready.

Compatibility considerations

Destination mask protection is separate from RGB blending and texture STP. A general implementation should also account for uploads and VRAM copies; framebuffer fill follows different rules. See GP0(E6) in PSX-SPX.

This minimal example demonstrates drawing only. Transfers, textured primitives, transparency, blending and multiple primitives in a batch need separate coverage.

Dominant language
C
Stars
107
Forks
26
Avg merge
2d 21h
Merged PRs (30d)
5

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Xeeynamo/psyz

All issues in Xeeynamo/psyz

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.