Skip to content

virtio-gpu: 3D (Shader) Capabilities & track a dirty rect so Swap() only transfers/flushes what changed - #3253

Draft
Epiczhul wants to merge 2 commits into
CosmosOS:gen3from
Epiczhul:gen3
Draft

Epiczhul wants to merge 2 commits into
CosmosOS:gen3from
Epiczhul:gen3

Conversation

@Epiczhul

@Epiczhul Epiczhul commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Swap() used to send TRANSFER_TO_HOST_2D and RESOURCE_FLUSH for the scanout on every frame even when only a small part of the framebuffer had changed...
Now VirtioGpu has MarkDirty(x, y, width, height) which keeps track of the bounding box of all writes since the Swap().
Functions like ClearScreen, DrawPixel and both CopyBuffer overloads call MarkDirty internally. Additionally VirtioGpuCanvas.DrawFilledRectangle calls it directly because it writes to the framebuffer and skips the usual driver methods.

Also VirtioGpu now supports 3D rendering using VirGL, with Virtio3DEngine and Virtio3DCanvas implementing the 3D rendering functionality. It also adds CosmSL, a shader language with its own lexer, parser and AST, which can be compiled to TGSI using TgsiEmitter.

The cool thing about VirtIO + VirGL is:
You compile the shaders on the guest to TGSI and than you just send it to the host and qemu calculates and renders it on the host GPU (Special QEMU builds needed if using Microsoft Windows, because most of the time VirGL is missing)

There are no API changes.

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Fat Tests

Cell x64 arm64
all ✅ 42/42 ✅ 42/42

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 File Tests

Cell x64 arm64
all ✅ 37/37 ✅ 37/37

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Graphic Tests

Cell x64 arm64
all ✅ 55/75, 20 skip ✅ 31/50, 19 skip
bare ✅ 15/25, 10 skip ✅ 15/25, 10 skip
virtio-gpu ✅ 16/25, 9 skip ✅ 16/25, 9 skip
vmware-svga ✅ 24/25, 1 skip n/a

Skipped

  • x64: 20 skipped: VMware SVGA II adapter not present, needs the vmware-svga profile (18), no virtio-gpu device on this cell, needs the virtio-gpu profile (2)
  • arm64: 19 skipped: VMware SVGA II adapter not present, needs the vmware-svga profile (18), no virtio-gpu device on this cell, needs the virtio-gpu profile (1)

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 HelloWorld Tests

Cell x64 arm64
all ✅ 3/3 ✅ 3/3

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Interrupts Tests

Cell x64 arm64
all ✅ 16/16 ✅ 27/48, 21 skip
bare ✅ 16/16 ⚠️ 7/16, 9 skip
bare+gicv2 n/a ✅ 9/16, 7 skip
bare+gicv3 n/a ✅ 11/16, 5 skip

Skipped

  • arm64: 21 skipped: needs MSI routing and an MSI-X function no driver has enabled (arm64: virtio-net owns the only one) (6), no MSI routing in this cell (GICv2 has no ITS) (4), self-IPI harness is x64-only (3), LAPIC MSI address contract is x64-only (3), LAPIC timer vector is x64-only (3), gic-version not pinned by this cell (2)

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Math Tests

Cell x64 arm64
all ✅ 30/30 ✅ 30/30

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Memory Tests

Cell x64 arm64
all ✅ 71/71 ✅ 71/71

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Network Tests

Cell x64 arm64
all ✅ 48/48 ✅ 48/48
e1000e ✅ 24/24 n/a
virtio-net-mmio n/a ✅ 24/24
virtio-net-pci ✅ 24/24 ✅ 24/24

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Pci Tests

Cell x64 arm64
all ✅ 8/8 ✅ 8/8

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Power Tests

Cell x64 arm64
all ✅ 4/4 ✅ 4/4

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Runtime Tests

Cell x64 arm64
all ✅ 103/103 ✅ 103/103

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Storage Tests

Cell x64 arm64
all ✅ 886/996, 110 skip ✅ 3065/3486, 421 skip
ahci ✅ 70/83, 13 skip ✅ 70/83, 13 skip
ahci+acpi-off ✅ 70/83, 13 skip ✅ 70/83, 13 skip
ahci+gicv2 n/a ✅ 70/83, 13 skip
ahci+gicv2+acpi-off n/a ✅ 70/83, 13 skip
ahci+gicv3 n/a ✅ 70/83, 13 skip
ahci+gicv3+acpi-off n/a ✅ 70/83, 13 skip
nvme ✅ 73/83, 10 skip ✅ 70/83, 13 skip
nvme+acpi-off ✅ 73/83, 10 skip ✅ 71/83, 12 skip
nvme+gicv2 n/a ✅ 71/83, 12 skip
nvme+gicv2+acpi-off n/a ✅ 71/83, 12 skip
nvme+gicv3 n/a ✅ 71/83, 12 skip
nvme+gicv3+acpi-off n/a ✅ 71/83, 12 skip
usb ✅ 75/83, 8 skip ✅ 75/83, 8 skip
usb+acpi-off ✅ 75/83, 8 skip ✅ 75/83, 8 skip
usb+gicv2 n/a ✅ 75/83, 8 skip
usb+gicv2+acpi-off n/a ✅ 75/83, 8 skip
usb+gicv3 n/a ✅ 75/83, 8 skip
usb+gicv3+acpi-off n/a ✅ 75/83, 8 skip
usb-ehci ✅ 75/83, 8 skip ✅ 75/83, 8 skip
usb-ehci+acpi-off ✅ 75/83, 8 skip ✅ 75/83, 8 skip
usb-ehci+gicv2 n/a ✅ 75/83, 8 skip
usb-ehci+gicv2+acpi-off n/a ✅ 75/83, 8 skip
usb-ehci+gicv3 n/a ✅ 75/83, 8 skip
usb-ehci+gicv3+acpi-off n/a ✅ 75/83, 8 skip
usb-ohci ✅ 75/83, 8 skip ✅ 75/83, 8 skip
usb-ohci+acpi-off ✅ 75/83, 8 skip ✅ 75/83, 8 skip
usb-ohci+gicv2 n/a ✅ 75/83, 8 skip
usb-ohci+gicv2+acpi-off n/a ✅ 75/83, 8 skip
usb-ohci+gicv3 n/a ✅ 75/83, 8 skip
usb-ohci+gicv3+acpi-off n/a ✅ 75/83, 8 skip
virtio-blk-mmio n/a ✅ 70/83, 13 skip
virtio-blk-mmio+acpi-off n/a ✅ 70/83, 13 skip
virtio-blk-mmio+gicv2 n/a ✅ 70/83, 13 skip
virtio-blk-mmio+gicv2+acpi-off n/a ✅ 70/83, 13 skip
virtio-blk-mmio+gicv3 n/a ✅ 70/83, 13 skip
virtio-blk-mmio+gicv3+acpi-off n/a ✅ 70/83, 13 skip
virtio-blk-pci ✅ 75/83, 8 skip ✅ 75/83, 8 skip
virtio-blk-pci+acpi-off ✅ 75/83, 8 skip ✅ 75/83, 8 skip
virtio-blk-pci+gicv2 n/a ✅ 75/83, 8 skip
virtio-blk-pci+gicv2+acpi-off n/a ✅ 75/83, 8 skip
virtio-blk-pci+gicv3 n/a ✅ 75/83, 8 skip
virtio-blk-pci+gicv3+acpi-off n/a ✅ 75/83, 8 skip

Skipped

  • x64: 110 skipped: no hot-pluggable PCI disk on this cell (50), not a USB profile (30), 64-bit BAR relocation probe is nvme-profile only (20), not an NVMe profile (10)
  • arm64: 421 skipped: no hot-pluggable PCI disk on this cell (180), not a USB profile (120), x64 mapper cell; arm64 installs Device mappings via DeviceMapper (42), BAR relocation probe is x64-only (same harness as the mapper cell) (42), not an NVMe profile (36), interrupt mode not pinned by this cell (1)

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Threading Tests

Cell x64 arm64
all ✅ 78/78 ✅ 78/78

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 TypeCasting Tests

Cell x64 arm64
all ✅ 26/26 ✅ 26/26

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🧪 Virtio Tests

Cell x64 arm64
all ✅ 10/10 ✅ 17/20, 3 skip
virtio-mmio n/a ✅ 7/10, 3 skip
virtio-pci ✅ 10/10 ✅ 10/10

Skipped

  • arm64: 3 skipped: this cell presents virtio over MMIO (3)

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@Epiczhul Epiczhul changed the title virtio-gpu: track a dirty rect so Swap() only transfers/flushes what changed 🐛virtio-gpu: track a dirty rect so Swap() only transfers/flushes what changed Sep 22, 2026
@Epiczhul Epiczhul changed the title 🐛virtio-gpu: track a dirty rect so Swap() only transfers/flushes what changed 🐛✨virtio-gpu: track a dirty rect so Swap() only transfers/flushes what changed Sep 22, 2026
@valentinbreiz valentinbreiz changed the title 🐛✨virtio-gpu: track a dirty rect so Swap() only transfers/flushes what changed virtio-gpu: track a dirty rect so Swap() only transfers/flushes what changed Sep 22, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

🧪 GarbageCollector Tests

Cell x64 arm64
all ✅ 50/50 ✅ 50/50

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

🧪 Timer Tests

Cell x64 arm64
all ✅ 26/26 ✅ 20/20

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@Epiczhul

Epiczhul commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Can be merged if Okey or Closed if not, 3D will take a few days still.

@Epiczhul
Epiczhul marked this pull request as draft October 14, 2026 15:32
@Epiczhul Epiczhul changed the title virtio-gpu: track a dirty rect so Swap() only transfers/flushes what changed virtio-gpu: track a dirty rect so Swap() only transfers/flushes what changed & 3D Capabilities Oct 14, 2026
@Epiczhul Epiczhul closed this Oct 14, 2026
Implemented VirGL command protocol and Virtio gpu 3D resource management

Add a 3D rendering engine with mesh, texture, shader and framebuffer operations

integrate Virtio3DCanvas with Canvas3D and add the CosmSL lexer, parser, AST and TGSI emitter

Extended graphics engine interfaces and update public API declarations
@Epiczhul Epiczhul reopened this Oct 14, 2026
@github-actions

Copy link
Copy Markdown

🧪 Audio Tests

Cell x64 arm64
all ✅ 25/44, 19 skip ✅ 25/44, 19 skip
bare ⚠️ 5/22, 17 skip ⚠️ 5/22, 17 skip
hda ✅ 20/22, 2 skip ✅ 20/22, 2 skip

Skipped

  • x64: 19 skipped: no HD Audio controller on this cell, needs the hda profile (17), an output is published on this cell (2)
  • arm64: 19 skipped: no HD Audio controller on this cell, needs the hda profile (17), an output is published on this cell (2)

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🧪 Drivers Tests

Cell x64 arm64
all ✅ 355/504, 149 skip ✅ 326/567, 241 skip
bare ✅ 41/63, 22 skip ⚠️ 30/63, 33 skip
usb-kbd ✅ 47/63, 16 skip ✅ 37/63, 26 skip
usb-kbd-ehci ✅ 43/63, 20 skip ✅ 37/63, 26 skip
usb-kbd-ehci-ohci ✅ 44/63, 19 skip ✅ 38/63, 25 skip
usb-kbd-ohci ✅ 43/63, 20 skip ✅ 37/63, 26 skip
usb-kbd-ohci-hub ✅ 43/63, 20 skip ✅ 37/63, 26 skip
usb-mouse ✅ 44/63, 19 skip ✅ 35/63, 28 skip
virtio-blk-mmio n/a ✅ 36/63, 27 skip
virtio-blk-pci ✅ 50/63, 13 skip ✅ 39/63, 24 skip

Skipped

  • x64: 149 skipped: no virtio-blk device on this cell (42), no PCI Express root port on this cell (21), no USB host controller on this cell (20), no USB mouse on this cell (20), no e1000e on this machine (16), no xHCI controller on this cell (6), no EHCI controller on this cell (6), no USB keyboard on this cell (6), no OHCI controller on this cell (5), a usb-kbd on this cell takes the host's keys (5), a usb-mouse on this cell takes the host's pointer events (2)
  • arm64: 241 skipped: no 8042 on this cell (63), no virtio-blk device on this cell (42), no e1000e on this machine (36), no USB host controller on this cell (30), no PCI Express root port on this cell (24), no USB mouse on this cell (20), no xHCI controller on this cell (7), no EHCI controller on this cell (7), no OHCI controller on this cell (6), no USB keyboard on this cell (6)

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🧪 Random Tests

Cell x64 arm64
all ✅ 16/16 ✅ 16/16

📎 Artifacts

Architecture Test Results UART Log Kernel ISO
x64 XML Log ISO
arm64 XML Log ISO

📋 View full test summary | 📄 Kernel.cs

@Epiczhul

Copy link
Copy Markdown
Contributor Author

CosmSL (how to use it)

CosmSL is a little HLSL-style shader language, that I added in this pull request.
You write a shader as a string
(or read a file, for example .cosl file yourself and pass its text, the compiler only takes strings), hand it to CosmCompiler.Parse(source) and get a ShaderProgramNode AST back, which the 3D driver will turn into the GPUs native format (TGSI for virtio/virgl).
Invalid sources throw CosmSlException with the line number.

Types: float int bool vec2 vec3 vec4 mat4 sampler2D

Vertex shader example:

struct VertexInput {
    vec4 position : POSITION; // explicit semantics after the colon
    vec4 color : COLOR;
};

struct VertexOutput {
    vec4 position : SV_POSITION; // clip space position for the rasterizer
    vec4 color : COLOR; // interpolator passed to the fragment stage
};

uniform mat4 u_mvp;

VertexOutput main(VertexInput input) {
    VertexOutput output;
    output.position = mul(u_mvp, input.position);
    output.color = input.color;
    return output;
}

Fragment shader example:

struct FragmentInput {
    vec4 color;   // no colon = auto semantic: vec4 -> COLOR, vec2 -> TEXCOORD0, ...
};

uniform sampler2D u_tex;

vec4 main(FragmentInput input) : SV_TARGET {   // SV_TARGET = out pixel color
    return tex2D(u_tex, input.uv) * input.color;
}

What you can use: + - * /, unary minus, swizzles (.xyzw / .rgba, e.g. input.color.rgb), local vars, assignments incl. += -= *= /=, return. Intrinsics: vec2()/vec3()/vec4() constructors, mul, dot, tex2D, saturate, abs, floor, frac, round, sqrt, rsq, exp2, log2, sin, cos, min, max, clamp, lerp.

Thats the whole language on purpose because its a shader description and not a general language: no if/loops/UDT functions yet.

Notes: every program needs a main and uniforms become constants/samplers (mat4 = 4 vec4s in the UBO, sampler2D binds a texture). semantics we know are POSITION COLOR SV_POSITION SV_TARGET TEXCOORDn.

The virtio 3D engine ships its 4 built-in shaders (colored/textured × vertex/fragment) written in CosmSL Virtio3DEngine.cs bottom is the reference. The AST is public (Cosmos.Kernel.System.Graphics.CosmSl), the TGSI lowering lives driver side, so on the canvas API you just draw meshes (Canvas3D) and the builtins render them custom shader upload through the canvas comes next.

@Epiczhul

Copy link
Copy Markdown
Contributor Author

(The syntax was designed with the help of @SammaWasTaken in the #nativeaot-dev channel on the CosmosOS Discord-Server)

@Epiczhul Epiczhul changed the title virtio-gpu: track a dirty rect so Swap() only transfers/flushes what changed & 3D Capabilities virtio-gpu: 3D (Shader) Capabilities & track a dirty rect so Swap() only transfers/flushes what changed Oct 15, 2026
@Epiczhul

Copy link
Copy Markdown
Contributor Author
image Fully rendering now!

@Epiczhul

Epiczhul commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Cosmos VirtIO 3D Capability Checklist

Done (verified)

  • CosmSL pipeline: lexer / parser / compiler -> TGSI text emission
  • 18 shader builtins: mul, dot, tex2D, saturate, abs, floor, frac, round, sqrt, rsq, exp2, log2, sin, cos, min, max, clamp, lerp
  • Swizzles (.xyz etc.), writable swizzles
  • Uniforms: sampler2D, float, mat4 (inline via SET_CONSTANT_BUFFER)
  • Indexed meshes + per-vertex colors + UVs + textures
  • Depth buffer (Z32Float), depth test + write (LESS)
  • Camera view/projection matrices (transposed, DP4 chain)
  • Blend / rasterizer / DSA objects created and bound
  • QEMU proof: geometry, colors, grid, scanout readback all correct

Fixed-function state control (biggest practical gap)

  • Alpha blending: blend object+ exists but its hard disabled, no transparency possible
  • Face culling: rasterizer culling off, closed meshes waste ~2x fragment work
  • Stencil buffer none (Z32Float has no stencil bits, no stencil ops in DSA)
  • Depth compare modes: hardcoded
  • LESS (no Equal/Greater/ LEqual/…)
  • Scissor test: not implemented
  • MRT: single color target only (no multiple render targets)

CosmSL language gaps

  • if/else parser only handles declare/assign/return
  • for/while loops
  • discard (fragment shader early exit/clip)
  • Arrays
  • Additional struct types (beyond a single input struct)
  • Missing builtins: pow, cross, normalize, reflect
  • vec4 x mat4 operator: mat4 uniform exists but cant be multiplied in shader code

Texture/sampler features

  • Mipmaps: no generation, no selection
  • Per texture wrap/filter modes: one hardcoded sampler state
  • Wider format list: narrow supported set today

Engine-level

  • Instanced drawing: instance count pinned to 1
  • Render to texture/float render targets
  • Multiple virgl contexts + context reset recovery: single context, no recovery path
  • Batching/perf headroom: per-mesh shader rebinds, synchronous transfers, no command batching

Driver coverage ("universal engine")

  • Software rasterizer fallback: machine without virtio-gpu/virgl gets no 3D through the new layer

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant