Skip to content

Commit

Permalink
zig fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <[email protected]>
  • Loading branch information
slimsag committed Aug 25, 2024
1 parent b4f74af commit fc90dbf
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 72 deletions.
43 changes: 11 additions & 32 deletions src/core/win32.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn init(
self.events = EventQueue.init(self.allocator);
self.size = options.size;
self.input_state = .{};
self.saved_window_rect = .{.top = 0, .left = 0, .right = 0, .bottom = 0};
self.saved_window_rect = .{ .top = 0, .left = 0, .right = 0, .bottom = 0 };

const hInstance = w.GetModuleHandleW(null);
const class_name = w.L("mach");
Expand Down Expand Up @@ -180,20 +180,20 @@ pub fn setDisplayMode(self: *Win32, mode: DisplayMode) void {

switch (mode) {
.windowed => {
const window_style: w.WINDOW_STYLE = if (self.border) w.WS_OVERLAPPEDWINDOW else w.WS_POPUPWINDOW;
const window_style: w.WINDOW_STYLE = if (self.border) w.WS_OVERLAPPEDWINDOW else w.WS_POPUPWINDOW;
const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };

_ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
_ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));

restoreWindowPosition(self);
},
.fullscreen => {
.fullscreen => {
// TODO (win32) - change to use exclusive fullscreen using ChangeDisplaySetting

_ = w.GetWindowRect(self.window, &self.saved_window_rect);

const window_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1};
const window_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1 };
const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };

_ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
Expand All @@ -203,20 +203,13 @@ pub fn setDisplayMode(self: *Win32, mode: DisplayMode) void {
var monitor_info: w.MONITORINFO = undefined;
monitor_info.cbSize = @sizeOf(w.MONITORINFO);
if (w.GetMonitorInfoW(monitor, &monitor_info) == w.TRUE) {
_ = w.SetWindowPos(self.window,
null,
monitor_info.rcMonitor.left,
monitor_info.rcMonitor.top,
monitor_info.rcMonitor.right - monitor_info.rcMonitor.left,
monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top,
w.SWP_NOZORDER
);
_ = w.SetWindowPos(self.window, null, monitor_info.rcMonitor.left, monitor_info.rcMonitor.top, monitor_info.rcMonitor.right - monitor_info.rcMonitor.left, monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top, w.SWP_NOZORDER);
}
},
.borderless => {
_ = w.GetWindowRect(self.window, &self.saved_window_rect);

const window_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1};
const window_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1 };
const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };

_ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
Expand All @@ -226,14 +219,7 @@ pub fn setDisplayMode(self: *Win32, mode: DisplayMode) void {
var monitor_info: w.MONITORINFO = undefined;
monitor_info.cbSize = @sizeOf(w.MONITORINFO);
if (w.GetMonitorInfoW(monitor, &monitor_info) == w.TRUE) {
_ = w.SetWindowPos(self.window,
null,
monitor_info.rcMonitor.left,
monitor_info.rcMonitor.top,
monitor_info.rcMonitor.right - monitor_info.rcMonitor.left,
monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top,
w.SWP_NOZORDER
);
_ = w.SetWindowPos(self.window, null, monitor_info.rcMonitor.left, monitor_info.rcMonitor.top, monitor_info.rcMonitor.right - monitor_info.rcMonitor.left, monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top, w.SWP_NOZORDER);
}
},
}
Expand Down Expand Up @@ -341,14 +327,7 @@ fn restoreWindowPosition(self: *Win32) void {
if (self.saved_window_rect.right - self.saved_window_rect.left == 0) {
_ = w.ShowWindow(self.window, w.SW_RESTORE);
} else {
_ = w.SetWindowPos(self.window,
null,
self.saved_window_rect.left,
self.saved_window_rect.top,
self.saved_window_rect.right - self.saved_window_rect.left,
self.saved_window_rect.bottom - self.saved_window_rect.top,
w.SWP_SHOWWINDOW
);
_ = w.SetWindowPos(self.window, null, self.saved_window_rect.left, self.saved_window_rect.top, self.saved_window_rect.right - self.saved_window_rect.left, self.saved_window_rect.bottom - self.saved_window_rect.top, w.SWP_SHOWWINDOW);
}
}

Expand All @@ -370,7 +349,7 @@ fn getKeyboardModifiers() mach.Core.KeyMods {
.control = w.GetKeyState(@as(i32, @intFromEnum(w.VK_CONTROL))) < 0, // & 0x8000 == 0x8000,
.alt = w.GetKeyState(@as(i32, @intFromEnum(w.VK_MENU))) < 0, // & 0x8000 == 0x8000,
.super = (w.GetKeyState(@as(i32, @intFromEnum(w.VK_LWIN)))) < 0 // & 0x8000 == 0x8000)
or (w.GetKeyState(@as(i32, @intFromEnum(w.VK_RWIN)))) < 0, // & 0x8000 == 0x8000),
or (w.GetKeyState(@as(i32, @intFromEnum(w.VK_RWIN)))) < 0, // & 0x8000 == 0x8000),
.caps_lock = w.GetKeyState(@as(i32, @intFromEnum(w.VK_CAPITAL))) & 1 == 1,
.num_lock = w.GetKeyState(@as(i32, @intFromEnum(w.VK_NUMLOCK))) & 1 == 1,
};
Expand All @@ -391,7 +370,7 @@ fn wndProc(wnd: w.HWND, msg: u32, wParam: w.WPARAM, lParam: w.LPARAM) callconv(w
w.WM_SIZE => {
const width: u32 = @as(u32, @intCast(lParam & 0xFFFF));
const height: u32 = @as(u32, @intCast((lParam >> 16) & 0xFFFF));
self.size = .{.width = width, .height = height};
self.size = .{ .width = width, .height = height };

// TODO (win32): only send resize event when sizing is done.
// the main mach loops does not run while resizing.
Expand Down Expand Up @@ -653,7 +632,7 @@ fn keyFromScancode(scancode: u9) Key {
//0x73 => .international1,
//0x76 => .lang5,
0x73 => .international1,
0x76 => .f24,
0x76 => .f24,
//0x77 => .lang4,
//0x78 => .lang3,
//0x79 => .international4,
Expand Down
36 changes: 15 additions & 21 deletions src/core/win32/win32.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub const HICON = w.HICON;
pub const HCURSOR = w.HCURSOR;
pub const HBRUSH = w.HBRUSH;
pub const HMENU = w.HMENU;
pub const HMONITOR = *opaque{};
pub const HMONITOR = *opaque {};
pub const HDC = w.HDC;
pub const WINAPI = w.WINAPI;
pub const TRUE = w.TRUE;
Expand Down Expand Up @@ -650,7 +650,6 @@ pub const IDirectInput8W = extern struct {
pub usingnamespace MethodMixin(@This());
};


pub const IID_IDirectInputDevice8W = GUID{ .Data1 = 1423184001, .Data2 = 56341, .Data3 = 18483, .Data4 = .{ 164, 27, 116, 143, 115, 163, 129, 121 } };
pub const IDirectInputDevice8W = extern struct {
lpVtbl: *VTable,
Expand Down Expand Up @@ -1348,11 +1347,11 @@ pub const WS_EX_WINDOWEDGE = WINDOW_EX_STYLE{ .WINDOWEDGE = 1 };
pub const WS_EX_CLIENTEDGE = WINDOW_EX_STYLE{ .CLIENTEDGE = 1 };
pub const WS_EX_CONTEXTHELP = WINDOW_EX_STYLE{ .CONTEXTHELP = 1 };
pub const WS_EX_RIGHT = WINDOW_EX_STYLE{ .RIGHT = 1 };
pub const WS_EX_LEFT = WINDOW_EX_STYLE{ };
pub const WS_EX_LEFT = WINDOW_EX_STYLE{};
pub const WS_EX_RTLREADING = WINDOW_EX_STYLE{ .RTLREADING = 1 };
pub const WS_EX_LTRREADING = WINDOW_EX_STYLE{ };
pub const WS_EX_LTRREADING = WINDOW_EX_STYLE{};
pub const WS_EX_LEFTSCROLLBAR = WINDOW_EX_STYLE{ .LEFTSCROLLBAR = 1 };
pub const WS_EX_RIGHTSCROLLBAR = WINDOW_EX_STYLE{ };
pub const WS_EX_RIGHTSCROLLBAR = WINDOW_EX_STYLE{};
pub const WS_EX_CONTROLPARENT = WINDOW_EX_STYLE{ .CONTROLPARENT = 1 };
pub const WS_EX_STATICEDGE = WINDOW_EX_STYLE{ .STATICEDGE = 1 };
pub const WS_EX_APPWINDOW = WINDOW_EX_STYLE{ .APPWINDOW = 1 };
Expand Down Expand Up @@ -2305,12 +2304,10 @@ pub const VK_OEM_CLEAR = VIRTUAL_KEY.OEM_CLEAR;
// Keyboard and mouse
// ---------------------------
// TODO: this type is limited to platform 'windows5.0'
pub extern "user32" fn GetFocus(
) callconv(@import("std").os.windows.WINAPI) ?HWND;
pub extern "user32" fn GetFocus() callconv(@import("std").os.windows.WINAPI) ?HWND;

// TODO: this type is limited to platform 'windows5.0'
pub extern "user32" fn GetKBCodePage(
) callconv(@import("std").os.windows.WINAPI) u32;
pub extern "user32" fn GetKBCodePage() callconv(@import("std").os.windows.WINAPI) u32;

// TODO: this type is limited to platform 'windows5.0'
pub extern "user32" fn GetKeyState(
Expand All @@ -2327,28 +2324,25 @@ pub extern "user32" fn GetKeyboardState(
lpKeyState: *[256]u8,
) callconv(@import("std").os.windows.WINAPI) BOOL;

pub extern "user32" fn GetCapture(
) callconv(@import("std").os.windows.WINAPI) ?HWND;
pub extern "user32" fn GetCapture() callconv(@import("std").os.windows.WINAPI) ?HWND;

// TODO: this type is limited to platform 'windows5.0'
pub extern "user32" fn SetCapture(
hWnd: ?HWND,
) callconv(@import("std").os.windows.WINAPI) ?HWND;

// TODO: this type is limited to platform 'windows5.0'
pub extern "user32" fn ReleaseCapture(
) callconv(@import("std").os.windows.WINAPI) BOOL;

pub extern "user32" fn ReleaseCapture() callconv(@import("std").os.windows.WINAPI) BOOL;

// --------------------------
// GDI
// --------------------------
pub const MONITORENUMPROC = *const fn(
param0: ?HMONITOR,
param1: ?HDC,
param2: ?*RECT,
param3: LPARAM,
) callconv(@import("std").os.windows.WINAPI) BOOL;
pub const MONITORENUMPROC = *const fn (
param0: ?HMONITOR,
param1: ?HDC,
param2: ?*RECT,
param3: LPARAM,
) callconv(@import("std").os.windows.WINAPI) BOOL;

pub const MONITORINFO = extern struct {
cbSize: u32,
Expand Down Expand Up @@ -2402,4 +2396,4 @@ pub extern "user32" fn EnumDisplayMonitors(
lprcClip: ?*RECT,
lpfnEnum: ?MONITORENUMPROC,
dwData: LPARAM,
) callconv(@import("std").os.windows.WINAPI) BOOL;
) callconv(@import("std").os.windows.WINAPI) BOOL;
2 changes: 1 addition & 1 deletion src/gfx/Sprite.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn updatePipeline(
// TODO(d3d12): #1217
// changed the uv_transform to 4x4. The 3x3 causes issues with d3d12/hlsl
transforms: []Mat4x4,
uv_transforms: []Mat4x4,
uv_transforms: []Mat4x4,
sizes: []Vec2,

pub fn lessThan(ctx: @This(), a: usize, b: usize) bool {
Expand Down
27 changes: 10 additions & 17 deletions src/sysgpu/d3d12.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,9 @@ pub const Instance = struct {
);
if (hr == c.DXGI_ERROR_INVALID_CALL) {
const hr_prev = hr;
hr = c.CreateDXGIFactory2(
0,
&c.IID_IDXGIFactory4,
@ptrCast(&dxgi_factory));
hr = c.CreateDXGIFactory2(0, &c.IID_IDXGIFactory4, @ptrCast(&dxgi_factory));
if (hr == c.S_OK) {
log.info("note: D3D12 debug layers disabled (couldn't enable, error: {x}), see https://machengine.org/about/faq/#how-to-enable-direct3d-debug-layers",
.{@as(u32, @bitCast(hr_prev))});
log.info("note: D3D12 debug layers disabled (couldn't enable, error: {x}), see https://machengine.org/about/faq/#how-to-enable-direct3d-debug-layers", .{@as(u32, @bitCast(hr_prev))});
} else {
return error.CreateDXGIFactoryFailed;
}
Expand Down Expand Up @@ -209,8 +205,8 @@ pub const Adapter = struct {
description[l] = 0;

if ((dxgi_desc.Flags & c.DXGI_ADAPTER_FLAG_SOFTWARE) != 0) {
_ = dxgi_adapter.lpVtbl.*.Release.?(dxgi_adapter);
continue;
_ = dxgi_adapter.lpVtbl.*.Release.?(dxgi_adapter);
continue;
}

const adapter_type: sysgpu.Adapter.Type = blk: {
Expand All @@ -231,7 +227,7 @@ pub const Adapter = struct {
} else {
break :blk .integrated_gpu;
}
}
}
break :blk .unknown;
};

Expand All @@ -245,11 +241,10 @@ pub const Adapter = struct {
// Select the last discrete_gpu if power preference is high performance.
// Select the last integrated_gpu if power preference is not high performance.
// TOOD: Other selection criterias?
if ((options.power_preference == .high_performance and adapter_type == .discrete_gpu)
or (options.power_preference == .low_power and adapter_type != .discrete_gpu)) {
if ((options.power_preference == .high_performance and adapter_type == .discrete_gpu) or (options.power_preference == .low_power and adapter_type != .discrete_gpu)) {
if (last_dxgi_adapter) |adapter| {
_ = adapter.lpVtbl.*.Release.?(adapter);
}
}
last_dxgi_adapter = dxgi_adapter;
last_dxgi_desc = dxgi_desc;
last_adapter_type = adapter_type;
Expand Down Expand Up @@ -281,7 +276,6 @@ pub const Adapter = struct {
}
}


return error.NoAdapterFound;
}

Expand All @@ -298,7 +292,7 @@ pub const Adapter = struct {
}

pub fn getProperties(adapter: *Adapter) sysgpu.Adapter.Properties {
const dxgi_desc = adapter.dxgi_desc;
const dxgi_desc = adapter.dxgi_desc;
return .{
.vendor_id = dxgi_desc.VendorId,
.vendor_name = "", // TODO
Expand Down Expand Up @@ -478,7 +472,6 @@ pub const Device = struct {

try device.mem_allocator_textures.init(device);


return device;
}

Expand Down Expand Up @@ -768,7 +761,7 @@ pub const MemoryAllocator = struct {
.rtv_dsv_texture => c.D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES,
.other_texture => c.D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES,
},
};
};
var heap: ?*c.ID3D12Heap = null;
const d3d_device = group.owning_pool.device.d3d_device;
const hr = d3d_device.lpVtbl.*.CreateHeap.?(
Expand Down Expand Up @@ -1747,7 +1740,7 @@ pub const Texture = struct {
&clear_value
else
null,
// TODO: #1225: check if different textures need different resource categories.
// TODO: #1225: check if different textures need different resource categories.
.resource_category = .other_texture,
.initial_state = initial_state,
};
Expand Down
2 changes: 1 addition & 1 deletion src/sysgpu/shader/codegen/hlsl.zig
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ fn emitBinary(hlsl: *Hlsl, inst: Inst.Binary) !void {
const rhs_type = hlsl.air.getInst(inst.rhs_type);

if (lhs_type == .matrix or rhs_type == .matrix) {
// TODO(d3d12):
// TODO(d3d12):
// Changed to column major storage because dxc does not apply same ordering to Storage Buffers.
// matrices are in column major storage
try hlsl.writeAll("mul");
Expand Down

0 comments on commit fc90dbf

Please sign in to comment.