Repository navigation
Conversation
🧪 Graphic Tests
Skipped
📎 Artifacts
|
🧪 Interrupts Tests
Skipped
📎 Artifacts
|
🧪 Storage Tests
Skipped
📎 Artifacts
|
|
Can be merged if Okey or Closed if not, 3D will take a few days still. |
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
🧪 Audio Tests
Skipped
📎 Artifacts
|
🧪 Drivers Tests
Skipped
📎 Artifacts
|
|
CosmSL (how to use it) CosmSL is a little HLSL-style shader language, that I added in this pull request. 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. |
|
(The syntax was designed with the help of @SammaWasTaken in the #nativeaot-dev channel on the CosmosOS Discord-Server) |
Cosmos VirtIO 3D Capability ChecklistDone (verified)
Fixed-function state control (biggest practical gap)
CosmSL language gaps
Texture/sampler features
Engine-level
Driver coverage ("universal engine")
|

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.