Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sysgpu_backend build option #1264

Merged
merged 2 commits into from
Sep 8, 2024
Merged

Fix sysgpu_backend build option #1264

merged 2 commits into from
Sep 8, 2024

Conversation

Tatskaari
Copy link
Contributor

@Tatskaari Tatskaari commented Sep 7, 2024

The sysgpu backend build option was treating the build option as the wrong enum type. This type is defined in build.zig and is exposed through the generated build_options struct. This is really nasty, but I think this is the correct way to do this.

The generated code for @import("build_options") for reference:

pub const want_mach: bool = true;
pub const want_core: bool = true;
pub const want_sysaudio: bool = true;
pub const want_sysgpu: bool = true;
pub const @"build.SysgpuBackend" = enum (u3) {
    default = 0,
    webgpu = 1,
    d3d12 = 2,
    metal = 3,
    vulkan = 4,
    opengl = 5,
};
pub const sysgpu_backend: @"build.SysgpuBackend" = .opengl;
pub const @"build.Platform" = enum (u3) {
    wasm = 0,
    linux = 1,
    windows = 2,
    darwin = 3,
    null = 4,
};
pub const core_platform: @"build.Platform" = .linux;
  • By selecting this checkbox, I agree to license my contributions to this project under the license(s) described in the LICENSE file, and I have the right to do so or have received permission to do so by an employer or client I am producing work for whom has this right.

@@ -23,6 +17,24 @@ const impl = switch (backend_type) {
var inited = false;
var allocator: std.mem.Allocator = undefined;

fn backendFromBuildOption(comptime opt: build_options.@"build.SysgpuBackend") sysgpu.BackendType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This being named build_options.@"build.SysgpuBackend" looks weird and wrong to me.

We have other options in build_options that don't have to be written that way, for example here you can see we have build_options.want_sysaudio as a boolean: https://github.com/hexops/mach/blob/main/src/main.zig#L18

I think we do something similar for core.PlatformType: https://github.com/hexops/mach/blob/main/build.zig#L48

Can you look into making it work similar to that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the solution might be writing something like:

const backend_type: sysgpu.BackendType = switch(build_options.sysgpu_backend) {
    // ... all the cases ...
};

And then don't have a backendFromBuildOption function at all.

Copy link
Contributor Author

@Tatskaari Tatskaari Sep 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah that would be nicer. I've updated the PR. I've just learnt the .value syntax so it didn't occur to me that you can avoid specifying the type entirely via inference here.

Copy link
Member

@slimsag slimsag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you for fixing this!

@slimsag slimsag merged commit 0a04a3c into hexops:main Sep 8, 2024
3 checks passed
fautore pushed a commit to fautore/mach that referenced this pull request Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants