[GPU/UI] XeSL readability improvements + float suffix
Use the _xe suffix instead of the xesl_ prefix for quicker visual recognition of identifiers, also switch to snake_case for consistency. Also add the f suffix to float32 literals because the Metal Shading Language is based on C++.
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
|
||||
#include "../../ui/shaders/xesl.xesli"
|
||||
|
||||
int XeTextureTiledOffset2D(xesl_int2 p, uint pitch_aligned, uint bpb_log2) {
|
||||
int XeTextureTiledOffset2D(int2_xe p, uint pitch_aligned, uint bpb_log2) {
|
||||
// https://github.com/gildor2/UModel/blob/de8fbd3bc922427ea056b7340202dcdcc19ccff5/Unreal/UnTexture.cpp#L489
|
||||
// Top bits of coordinates.
|
||||
int macro =
|
||||
@@ -29,7 +29,7 @@ int XeTextureTiledOffset2D(xesl_int2 p, uint pitch_aligned, uint bpb_log2) {
|
||||
(offset & 0x3F); // Lower 6 bits (offset bits [5-0]).
|
||||
}
|
||||
|
||||
int XeTextureTiledOffset3D(xesl_int3 p, uint pitch_aligned, uint height_aligned,
|
||||
int XeTextureTiledOffset3D(int3_xe p, uint pitch_aligned, uint height_aligned,
|
||||
uint bpb_log2) {
|
||||
// Reconstructed from disassembly of XGRAPHICS::TileVolume.
|
||||
int macro_outer = ((p.y >> 4) + (p.z >> 2) * int(height_aligned >> 4u)) *
|
||||
@@ -89,33 +89,33 @@ uint XeTextureTiledOddConsecutiveBlocksOffset(uint bpb_log2) {
|
||||
// This function is used only for non-negative positions within a texture, so
|
||||
// for simplicity, especially of the division involved, assuming everything is
|
||||
// unsigned.
|
||||
uint XeTextureScaledTiledOffset(bool is_3d, xesl_uint3 p, uint pitch_aligned,
|
||||
uint XeTextureScaledTiledOffset(bool is_3d, uint3_xe p, uint pitch_aligned,
|
||||
uint height_aligned, uint bpb_log2,
|
||||
xesl_uint2 scale) {
|
||||
uint2_xe scale) {
|
||||
uint unit_width_log2 = XeTextureTiledConsecutiveBlocksLog2(bpb_log2);
|
||||
// Global host X coordinate in host Nx1 sub-units.
|
||||
uint x_subunits = p.x >> unit_width_log2;
|
||||
// Global guest XY coordinate in guest Nx1 units.
|
||||
xesl_uint2 xy_unit_guest = xesl_uint2(x_subunits, p.y) / scale;
|
||||
uint2_xe xy_unit_guest = uint2_xe(x_subunits, p.y) / scale;
|
||||
// Global guest XYZ coordinate of the beginning of the Nx1 unit.
|
||||
xesl_uint3 unit_guest_origin =
|
||||
xesl_uint3(xy_unit_guest.x << unit_width_log2, xy_unit_guest.y, p.z);
|
||||
uint3_xe unit_guest_origin =
|
||||
uint3_xe(xy_unit_guest.x << unit_width_log2, xy_unit_guest.y, p.z);
|
||||
// Global guest linear address of the beginning of Nx1 unit in bytes.
|
||||
uint unit_guest_address;
|
||||
xesl_dont_flatten if (is_3d) {
|
||||
dont_flatten_xe if (is_3d) {
|
||||
unit_guest_address =
|
||||
uint(XeTextureTiledOffset3D(xesl_int3(unit_guest_origin), pitch_aligned,
|
||||
uint(XeTextureTiledOffset3D(int3_xe(unit_guest_origin), pitch_aligned,
|
||||
height_aligned, bpb_log2));
|
||||
} else {
|
||||
unit_guest_address =
|
||||
uint(XeTextureTiledOffset2D(xesl_int2(unit_guest_origin.xy),
|
||||
uint(XeTextureTiledOffset2D(int2_xe(unit_guest_origin.xy),
|
||||
pitch_aligned, bpb_log2));
|
||||
}
|
||||
// Unit-local host XY index of the host Nx1 sub-unit.
|
||||
// Also see XeTextureScaledRightSubUnitOffsetInConsecutivePair for common
|
||||
// subexpression elimination information as this remainder calculation is done
|
||||
// there too.
|
||||
xesl_uint2 unit_subunit = xesl_uint2(x_subunits, p.y) - xy_unit_guest * scale;
|
||||
uint2_xe unit_subunit = uint2_xe(x_subunits, p.y) - xy_unit_guest * scale;
|
||||
// Combine:
|
||||
// - Guest global unit address.
|
||||
// - Host unit-local sub-unit index.
|
||||
@@ -133,11 +133,11 @@ uint XeTextureScaledTiledOffset(bool is_3d, xesl_uint3 p, uint pitch_aligned,
|
||||
// go from one pair of consecutive blocks to another, full tiled offset
|
||||
// recalculation is required.
|
||||
uint XeTextureScaledRightSubUnitOffsetInConsecutivePair(uint x, uint bpb_log2,
|
||||
xesl_uint2 scale) {
|
||||
uint2_xe scale) {
|
||||
uint right_sub_unit_offset_columns;
|
||||
uint tiled_consecutive_offset =
|
||||
XeTextureTiledOddConsecutiveBlocksOffset(bpb_log2);
|
||||
xesl_dont_flatten if (scale.x > 1u) {
|
||||
dont_flatten_xe if (scale.x > 1u) {
|
||||
uint subunit_width_log2 = XeTextureTiledConsecutiveBlocksLog2(bpb_log2);
|
||||
uint subunit_size_log2 = subunit_width_log2 + bpb_log2;
|
||||
// While % can be used here to take the modulo, for better common
|
||||
@@ -161,12 +161,12 @@ uint XeTextureScaledRightSubUnitOffsetInConsecutivePair(uint x, uint bpb_log2,
|
||||
return right_sub_unit_offset_columns * scale.y;
|
||||
}
|
||||
|
||||
int XeTextureGuestLinearOffset(xesl_int3 p, uint pitch, uint height_aligned,
|
||||
int XeTextureGuestLinearOffset(int3_xe p, uint pitch, uint height_aligned,
|
||||
uint bpb) {
|
||||
return p.x * int(bpb) + (p.z * int(height_aligned) + p.y) * int(pitch);
|
||||
}
|
||||
|
||||
int XeTextureHostLinearOffset(xesl_int3 p, uint pitch, uint height, uint bpb) {
|
||||
int XeTextureHostLinearOffset(int3_xe p, uint pitch, uint height, uint bpb) {
|
||||
return p.x * int(bpb) + (p.z * int(height) + p.y) * int(pitch);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user