Skip to content

Instantly share code, notes, and snippets.

Avatar

Michaël Larouche mlarouche

View GitHub Profile
@mlarouche
mlarouche / command_list.zig
Last active Mar 13, 2022
free function to Self wrapper
View command_list.zig
const std = @import("std");
const platform = @import("../platforms/platform.zig").platform;
const GpuResource = @import("gpu_resource.zig").GpuResource;
pub const CommandListKind = enum {
Graphics,
Compute,
Copy,
};
@mlarouche
mlarouche / zig_d3d12.zig
Last active Sep 14, 2020
Direct3D12 Sample in Zig
View zig_d3d12.zig
const std = @import("std");
const win32 = @import("win32.zig");
const d3d12 = @import("d3d12.zig");
const dxgi = @import("dxgi1_4.zig");
const d3dcompiler = @import("d3dcompiler.zig");
const windows = std.os.windows;
const L = std.unicode.utf8ToUtf16LeStringLiteral;
@mlarouche
mlarouche / build.json
Created Aug 15, 2020
Build platform optionally
View build.json
{
"os": "windows",
"libraries": [
"c",
"d3d12",
"dxgi",
"d3dcompiler",
"dxguid"
],
"include_dirs": [],
@mlarouche
mlarouche / d3d11.zig
Created Apr 14, 2020
Direct3D sample usage in one of my projects
View d3d11.zig
const DxContext = struct {
device: ?*dx.ID3D11Device = null,
deviceContext: ?*dx.ID3D11DeviceContext = null,
swapChain: ?*dx.IDXGISwapChain = null,
mainRenderTargetView: ?*dx.ID3D11RenderTargetView = null,
};
var dxContext: DxContext = undefined;
@mlarouche
mlarouche / debug_ir.log
Created Mar 6, 2020
zigimg test Debug IR crash Linux
View debug_ir.log
This file has been truncated, but you can view the full file.
; ModuleID = 'test'
source_filename = "test"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"[]u8" = type { i8*, i64 }
%std.builtin.StackTrace = type { i64, %"[]usize" }
%"[]usize" = type { i64*, i64 }
%std.target.LinuxVersionRange = type { %std.builtin.Range, %std.builtin.Version }
%std.builtin.Range = type { %std.builtin.Version, %std.builtin.Version }
@mlarouche
mlarouche / final_result.zig
Last active Feb 26, 2020
How to call a function via reflection?
View final_result.zig
fn findImageFormat(inStream: *ImageInStream, seekStream: *ImageSeekStream) !ImageFormat {
const allFuncs = comptime blk: {
// TODO: Use ArrayList when Zig support compile-time allocator
var result:[16]fn(inStream: *ImageInStream, seekStream: *ImageSeekStream) anyerror!ImageFormat = undefined;
var index:usize = 0;
inline for (std.meta.declarations(AllImageFormats)) |decl| {
switch(decl.data) {
.Type => |entryType| {
const entryTypeInfo = @typeInfo(entryType);
if (entryTypeInfo== .Struct) {
@mlarouche
mlarouche / com_call.zig
Last active Feb 24, 2020
Generic COM call
View com_call.zig
fn comFindReturnType(comptime vTableType: type, comptime name: []const u8) type {
for (@typeInfo(vTableType).Struct.fields) |field| {
if (std.mem.eql(u8, field.name, name)) {
const funcType = @typeInfo(@typeInfo(field.field_type).Optional.child);
return funcType.Fn.return_type.?;
}
}
return void;
}
View win32_helloworld.zig
usingnamespace @import("std").os.windows;
extern "user32" fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) callconv(.Stdcall) c_int;
pub export fn WinMain(hInstance: ?HINSTANCE, hPrevInstance: ?HINSTANCE, lpCmdLine: ?LPWSTR, nShowCmd: INT) callconv(.Stdcall) INT {
_ = MessageBoxA(null, "Zig is pretty great!", "Wow much exposure", 4);
return 0;
}
@mlarouche
mlarouche / Result_PC
Created Feb 9, 2020
__divsi3 and __udivsi3 issues on Thumb1
View Result_PC
fixed=2048
fixed2=640
result=3.51 / 819
@mlarouche
mlarouche / rawobjcopy.zig
Created Jan 24, 2020
objcopy -O binary clone in Zig
View rawobjcopy.zig
const Allocator = @import("std").mem.Allocator;
const ArenaAllocator = @import("std").heap.ArenaAllocator;
const ArrayList = @import("std").ArrayList;
const File = @import("std").fs.File;
const HeapAllocator = @import("std").heap.HeapAllocator;
const elf = @import("std").elf;
const fs = @import("std").fs;
const io = @import("std").io;
const sort = @import("std").sort;