WebGL renders triangles that exceed the PS1 polygon size limit

Open
#229 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by tracing how DrawOTag submits polygon packets and how the WebGL backend clips or rejects their vertices; use the attached standalone C reproduction to confirm the current behavior. Check every polygon packet type, quad component, boundary value, and texture-state side effect against the signed 11-bit coordinate limits in PSX-SPX. Done means oversized polygons are rejected while valid polygons still clip normally.

Written by the indexing model from the issue text.

Description

An oversized polygon is clipped to the viewport and rendered, whereas the PS1 should reject it. In a game this can appear as stretched geometry near the camera.

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.

It submits a red POLY_F3 with vertices (-700, 40), (400, 40), (80, 200): the horizontal span is 1100 pixels. A separate small green triangle is a valid control. Both are submitted through DrawOTag.

Expected: only the green control is visible.

Actual: the red triangle covers a large portion of the framebuffer.

Unmodified PsyZ on the left; packet-level polygon rejection on the right

These are actual 320×240 VRAM readbacks, enlarged 2× with nearest-neighbour scaling. The right-hand image uses our packet-level rejection wrapper; the underlying PsyZ backend is otherwise unchanged. It is a local comparison, 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

The restriction applies to signed 11-bit vertex coordinates: a horizontal span of 1024 or a vertical span of 512 is already too large. Ordinary clipping of valid polygons should remain intact. See vertex restrictions in PSX-SPX.

This example tests one flat triangle. A general fix should also cover textured/Gouraud packets, boundary values, both component triangles of a quad, and texture-state side effects.

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.