add new win32 platform implementation (#1224)
* Buffer resources from swap chain were not being released. * sysgpu Texture.getWidth() should return width not height. * d3d12: Fixing issues with d3d12 on sysgpu. * Initial win32 platform
This commit is contained in:
parent
3fa889b136
commit
c32e763e11
12 changed files with 3329 additions and 18 deletions
|
|
@ -5,6 +5,9 @@ const gfx = mach.gfx;
|
|||
|
||||
const math = mach.math;
|
||||
const vec2 = math.vec2;
|
||||
const vec3 = math.vec3;
|
||||
const vec4 = math.vec4;
|
||||
const mat4x4 = math.mat4x4;
|
||||
const Vec2 = math.Vec2;
|
||||
const Vec3 = math.Vec3;
|
||||
const Mat3x3 = math.Mat3x3;
|
||||
|
|
@ -87,8 +90,14 @@ fn updatePipeline(
|
|||
// that all entities with the same pipeline value are stored in contiguous memory, and
|
||||
// skip this copy.
|
||||
if (sprite_pipeline_id == pipeline_id) {
|
||||
const uv = uv_transform;
|
||||
gfx.SpritePipeline.cp_transforms[i] = transform;
|
||||
gfx.SpritePipeline.cp_uv_transforms[i] = uv_transform;
|
||||
// TODO(d3d12): #1217
|
||||
// changed the uv_transform to 4x4. The 3x3 causes issues with d3d12/hlsl
|
||||
gfx.SpritePipeline.cp_uv_transforms[i].v[0] = vec4(uv.v[0].x(), uv.v[0].y(), uv.v[0].z(), 0.0);
|
||||
gfx.SpritePipeline.cp_uv_transforms[i].v[1] = vec4(uv.v[1].x(), uv.v[1].y(), uv.v[1].z(), 0.0);
|
||||
gfx.SpritePipeline.cp_uv_transforms[i].v[2] = vec4(uv.v[2].x(), uv.v[2].y(), uv.v[2].z(), 0.0);
|
||||
gfx.SpritePipeline.cp_uv_transforms[i].v[3] = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
gfx.SpritePipeline.cp_sizes[i] = size;
|
||||
i += 1;
|
||||
num_sprites += 1;
|
||||
|
|
@ -98,8 +107,10 @@ fn updatePipeline(
|
|||
|
||||
// Sort sprites back-to-front for draw order, alpha blending
|
||||
const Context = struct {
|
||||
// TODO(d3d12): #1217
|
||||
// changed the uv_transform to 4x4. The 3x3 causes issues with d3d12/hlsl
|
||||
transforms: []Mat4x4,
|
||||
uv_transforms: []Mat3x3,
|
||||
uv_transforms: []Mat4x4,
|
||||
sizes: []Vec2,
|
||||
|
||||
pub fn lessThan(ctx: @This(), a: usize, b: usize) bool {
|
||||
|
|
@ -111,7 +122,9 @@ fn updatePipeline(
|
|||
|
||||
pub fn swap(ctx: @This(), a: usize, b: usize) void {
|
||||
std.mem.swap(Mat4x4, &ctx.transforms[a], &ctx.transforms[b]);
|
||||
std.mem.swap(Mat3x3, &ctx.uv_transforms[a], &ctx.uv_transforms[b]);
|
||||
// TODO(d3d12): #1217
|
||||
// changed the uv_transform to 4x4. The 3x3 causes issues with d3d12/hlsl
|
||||
std.mem.swap(Mat4x4, &ctx.uv_transforms[a], &ctx.uv_transforms[b]);
|
||||
std.mem.swap(Vec2, &ctx.sizes[a], &ctx.sizes[b]);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -110,7 +110,9 @@ const sprite_buffer_cap = 1024 * 512; // TODO(sprite): allow user to specify pre
|
|||
// TODO(sprite): eliminate these, see Sprite.updatePipeline for details on why these exist
|
||||
// currently.
|
||||
pub var cp_transforms: [sprite_buffer_cap]math.Mat4x4 = undefined;
|
||||
pub var cp_uv_transforms: [sprite_buffer_cap]math.Mat3x3 = undefined;
|
||||
// TODO(d3d12): #1217
|
||||
// changed the uv_transform to 4x4. The 3x3 causes issues with d3d12/hlsl
|
||||
pub var cp_uv_transforms: [sprite_buffer_cap]math.Mat4x4 = undefined;
|
||||
pub var cp_sizes: [sprite_buffer_cap]math.Vec2 = undefined;
|
||||
|
||||
/// Which render pass should be used during .render
|
||||
|
|
@ -209,7 +211,9 @@ fn buildPipeline(
|
|||
const uv_transforms = device.createBuffer(&.{
|
||||
.label = label ++ " uv_transforms",
|
||||
.usage = .{ .storage = true, .copy_dst = true },
|
||||
.size = @sizeOf(math.Mat3x3) * sprite_buffer_cap,
|
||||
// TODO(d3d12): #1217
|
||||
// changed the uv_transform to 4x4. The 3x3 causes issues with d3d12/hlsl
|
||||
.size = @sizeOf(math.Mat4x4) * sprite_buffer_cap,
|
||||
.mapped_at_creation = .false,
|
||||
});
|
||||
const sizes = device.createBuffer(&.{
|
||||
|
|
|
|||
|
|
@ -273,6 +273,9 @@ fn updatePipeline(
|
|||
).divScalar(px_density),
|
||||
.size = size.divScalar(px_density),
|
||||
.text_index = num_texts,
|
||||
// TODO(d3d12): #1217
|
||||
// Added padding for d3d12/hlsl. Having 7 floats before the color vec caused and error.
|
||||
.text_padding = 0,
|
||||
.uv_pos = vec2(@floatFromInt(r.x), @floatFromInt(r.y)),
|
||||
.color = font_color,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -134,6 +134,9 @@ pub const Glyph = extern struct {
|
|||
|
||||
/// Which text this glyph belongs to; this is the index for transforms[i], colors[i].
|
||||
text_index: u32,
|
||||
// TODO(d3d12): #1217
|
||||
// Added padding for d3d12/hlsl. Having 7 floats before the color vec caused and error.
|
||||
text_padding: u32,
|
||||
|
||||
/// Color of the glyph
|
||||
color: math.Vec4,
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ struct Uniforms {
|
|||
|
||||
// Sprite UV coordinate transformation matrices. Sprite UV coordinates are (0, 0) at the top-left
|
||||
// corner, and in pixels.
|
||||
@group(0) @binding(2) var<storage, read> sprite_uv_transforms: array<mat3x3<f32>>;
|
||||
// TODO(d3d12): #1217
|
||||
// changed the uv_transform to 4x4. The 3x3 ca@group(0) @binding(2) var<storage, read> sprite_uv_transforms: array<mat4x4<f32>>;
|
||||
@group(0) @binding(2) var<storage, read> sprite_uv_transforms: array<mat4x4<f32>>;
|
||||
|
||||
// Sprite sizes, in pixels.
|
||||
@group(0) @binding(3) var<storage, read> sprite_sizes: array<vec2<f32>>;
|
||||
|
|
@ -70,12 +72,12 @@ fn vertMain(
|
|||
// Currently, our pos_2d and uv coordinates describe a card that covers 1px by 1px; and the UV
|
||||
// coordinates describe using the entire texture. We alter the coordinates to describe the
|
||||
// desired sprite location, size, and apply a subset of the texture instead of the entire texture.
|
||||
var pos = vec4<f32>(pos_2d * sprite_size, 0, 1); // normalized -> pixels
|
||||
var pos = vec4<f32>(pos_2d * sprite_size, 0, 1); // normalized -> pixels
|
||||
pos = sprite_transform * pos; // apply sprite transform (pixels)
|
||||
pos = uniforms.view_projection * pos; // pixels -> normalized
|
||||
|
||||
uv *= sprite_size; // normalized -> pixels
|
||||
uv = (sprite_uv_transform * vec3<f32>(uv, 1)).xy; // apply sprite UV transform (pixels)
|
||||
uv = (sprite_uv_transform * vec4<f32>(uv, 1, 0)).xy; // apply sprite UV transform (pixels)
|
||||
uv /= uniforms.texture_size; // pixels -> normalized
|
||||
|
||||
var output : VertexOutput;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ struct Glyph {
|
|||
// Which text this glyph belongs to; this is the index for transforms[i], colors[i]
|
||||
text_index: u32,
|
||||
|
||||
// TODO(d3d12): #1217
|
||||
// Added padding for d3d12/hlsl. Having 7 floats before the color vec caused and error.
|
||||
text_index2: u32, // Padding for struct alignment
|
||||
|
||||
// Color of the glyph
|
||||
color: vec4<f32>,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue