sysgpu: implement texture getWidth/getHeight

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-04-29 11:58:15 -07:00 committed by Stephen Gutekanst
parent 44f950a7f3
commit 8089d3356e
5 changed files with 38 additions and 6 deletions

View file

@ -1728,6 +1728,14 @@ pub const Texture = struct {
return TextureView.init(texture, desc); return TextureView.init(texture, desc);
} }
pub fn getWidth(texture: *Texture) u32 {
return texture.size.width;
}
pub fn getHeight(texture: *Texture) u32 {
return texture.size.height;
}
// Internal // Internal
pub fn calcSubresource(texture: *Texture, mip_level: u32, array_slice: u32) u32 { pub fn calcSubresource(texture: *Texture, mip_level: u32, array_slice: u32) u32 {
return mip_level + (array_slice * texture.mip_level_count); return mip_level + (array_slice * texture.mip_level_count);

View file

@ -1295,9 +1295,9 @@ pub const Impl = sysgpu.Interface(struct {
@panic("unimplemented"); @panic("unimplemented");
} }
pub inline fn textureGetHeight(texture: *sysgpu.Texture) u32 { pub inline fn textureGetHeight(texture_raw: *sysgpu.Texture) u32 {
_ = texture; const texture: *impl.Texture = @ptrCast(@alignCast(texture_raw));
@panic("unimplemented"); return texture.getHeight();
} }
pub inline fn textureGetMipLevelCount(texture: *sysgpu.Texture) u32 { pub inline fn textureGetMipLevelCount(texture: *sysgpu.Texture) u32 {
@ -1315,9 +1315,9 @@ pub const Impl = sysgpu.Interface(struct {
@panic("unimplemented"); @panic("unimplemented");
} }
pub inline fn textureGetWidth(texture: *sysgpu.Texture) u32 { pub inline fn textureGetWidth(texture_raw: *sysgpu.Texture) u32 {
_ = texture; const texture: *impl.Texture = @ptrCast(@alignCast(texture_raw));
@panic("unimplemented"); return texture.getHeight();
} }
pub inline fn textureSetLabel(texture: *sysgpu.Texture, label: [*:0]const u8) void { pub inline fn textureSetLabel(texture: *sysgpu.Texture, label: [*:0]const u8) void {

View file

@ -636,6 +636,14 @@ pub const Texture = struct {
allocator.destroy(texture); allocator.destroy(texture);
} }
pub fn getWidth(texture: *Texture) u32 {
return @intCast(texture.mtl_texture.width());
}
pub fn getHeight(texture: *Texture) u32 {
return @intCast(texture.mtl_texture.height());
}
pub fn createView(texture: *Texture, desc: *const sysgpu.TextureView.Descriptor) !*TextureView { pub fn createView(texture: *Texture, desc: *const sysgpu.TextureView.Descriptor) !*TextureView {
return TextureView.init(texture, desc); return TextureView.init(texture, desc);
} }

View file

@ -808,6 +808,14 @@ pub const Texture = struct {
allocator.destroy(texture); allocator.destroy(texture);
} }
pub fn getWidth(texture: *Texture) u32 {
return texture.size.width;
}
pub fn getHeight(texture: *Texture) u32 {
return texture.size.height;
}
pub fn createView(texture: *Texture, desc: *const sysgpu.TextureView.Descriptor) !*TextureView { pub fn createView(texture: *Texture, desc: *const sysgpu.TextureView.Descriptor) !*TextureView {
return TextureView.init(texture, desc); return TextureView.init(texture, desc);
} }

View file

@ -1440,6 +1440,14 @@ pub const Texture = struct {
allocator.destroy(texture); allocator.destroy(texture);
} }
pub fn getWidth(texture: *Texture) u32 {
return texture.size.width;
}
pub fn getHeight(texture: *Texture) u32 {
return texture.size.height;
}
pub fn createView(texture: *Texture, desc: *const sysgpu.TextureView.Descriptor) !*TextureView { pub fn createView(texture: *Texture, desc: *const sysgpu.TextureView.Descriptor) !*TextureView {
return TextureView.init(texture, desc, texture.extent); return TextureView.init(texture, desc, texture.extent);
} }