homebrew-core/Formula/naga-cli.rb

159 lines
5.6 KiB
Ruby

class NagaCli < Formula
desc "Shader translation command-line tool"
homepage "https://github.com/gfx-rs/naga"
url "https://github.com/gfx-rs/naga/archive/refs/tags/v0.10.0.tar.gz"
sha256 "9ad07283157af424d130f598be636211188e3ee553bcdf5a9809a40ee28d57c3"
license any_of: ["Apache-2.0", "MIT"]
head "https://github.com/gfx-rs/naga.git", branch: "master"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any_skip_relocation, arm64_ventura: "5b2a425164a8b6531c39abe2ed61a8d4e68e4cc81ec55e35ebd0ae5c410d6f60"
sha256 cellar: :any_skip_relocation, arm64_monterey: "cdf4bdd0201d8e49ad56e2482767ea9a435f09928e08862a378aabc5fab04f4c"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "3c03399f669b226f7764ac52eac2c17093a577f54900b36620fb88f3e7a55c58"
sha256 cellar: :any_skip_relocation, ventura: "d5c34518cb374e9487375355206b707a2203479f7071af8c9df96bb9d14e0bdc"
sha256 cellar: :any_skip_relocation, monterey: "061ad1c5059d6723fc6ea2fac894702233b6c9dc3badb6fb98237392a7e6c960"
sha256 cellar: :any_skip_relocation, big_sur: "ec17d75dda52b03a7f856c42d5b2c45a36068cf94218fc7d4e5c004f577e0751"
sha256 cellar: :any_skip_relocation, x86_64_linux: "4de71885af471ff620f01b29438fb210d63a37cf9de0fe5a6e923f09f2cd9af7"
end
depends_on "rust" => :build
conflicts_with "naga", because: "both install `naga` binary"
def install
system "cargo", "install", *std_cargo_args(path: "cli")
end
test do
# sample taken from the Naga test suite
test_wgsl = testpath/"test.wgsl"
test_wgsl.write <<~EOF
@fragment
fn derivatives(@builtin(position) foo: vec4<f32>) -> @location(0) vec4<f32> {
let x = dpdx(foo);
let y = dpdy(foo);
let z = fwidth(foo);
return (x + y) * z;
}
EOF
assert_equal "Validation successful", shell_output("#{bin/"naga"} #{test_wgsl}").strip
test_out_wgsl = testpath/"test_out.wgsl"
test_out_frag = testpath/"test_out.frag"
test_out_metal = testpath/"test_out.metal"
test_out_hlsl = testpath/"test_out.hlsl"
test_out_dot = testpath/"test_out.dot"
system bin/"naga", test_wgsl, test_out_wgsl, test_out_frag, test_out_metal, test_out_hlsl, test_out_dot,
"--profile", "es310", "--entry-point", "derivatives"
assert_equal test_out_wgsl.read, <<~EOF
@fragment#{" "}
fn derivatives(@builtin(position) foo: vec4<f32>) -> @location(0) vec4<f32> {
let x = dpdx(foo);
let y = dpdy(foo);
let z = fwidth(foo);
return ((x + y) * z);
}
EOF
assert_equal test_out_frag.read, <<~EOF
#version 310 es
precision highp float;
precision highp int;
layout(location = 0) out vec4 _fs2p_location0;
void main() {
vec4 foo = gl_FragCoord;
vec4 x = dFdx(foo);
vec4 y = dFdy(foo);
vec4 z = fwidth(foo);
_fs2p_location0 = ((x + y) * z);
return;
}
EOF
assert_equal test_out_metal.read, <<~EOF
// language: metal2.0
#include <metal_stdlib>
#include <simd/simd.h>
using metal::uint;
struct derivativesInput {
};
struct derivativesOutput {
metal::float4 member [[color(0)]];
};
fragment derivativesOutput derivatives(
metal::float4 foo [[position]]
) {
metal::float4 x = metal::dfdx(foo);
metal::float4 y = metal::dfdy(foo);
metal::float4 z = metal::fwidth(foo);
return derivativesOutput { (x + y) * z };
}
EOF
assert_equal test_out_hlsl.read, <<~EOF
struct FragmentInput_derivatives {
float4 foo_1 : SV_Position;
};
float4 derivatives(FragmentInput_derivatives fragmentinput_derivatives) : SV_Target0
{
float4 foo = fragmentinput_derivatives.foo_1;
float4 x = ddx(foo);
float4 y = ddy(foo);
float4 z = fwidth(foo);
return ((x + y) * z);
}
EOF
assert_equal test_out_dot.read, <<~EOF
digraph Module {
subgraph cluster_globals {
label="Globals"
}
subgraph cluster_ep0 {
label="Fragment/'derivatives'"
node [ style=filled ]
ep0_e0 [ color="#8dd3c7" label="[1] Argument[0]" ]
ep0_e1 [ color="#fccde5" label="[2] dX" ]
ep0_e0 -> ep0_e1 [ label="" ]
ep0_e2 [ color="#fccde5" label="[3] dY" ]
ep0_e0 -> ep0_e2 [ label="" ]
ep0_e3 [ color="#fccde5" label="[4] dWidth" ]
ep0_e0 -> ep0_e3 [ label="" ]
ep0_e4 [ color="#fdb462" label="[5] Add" ]
ep0_e2 -> ep0_e4 [ label="right" ]
ep0_e1 -> ep0_e4 [ label="left" ]
ep0_e5 [ color="#fdb462" label="[6] Multiply" ]
ep0_e3 -> ep0_e5 [ label="right" ]
ep0_e4 -> ep0_e5 [ label="left" ]
ep0_s0 [ shape=square label="Root" ]
ep0_s1 [ shape=square label="Emit" ]
ep0_s2 [ shape=square label="Emit" ]
ep0_s3 [ shape=square label="Emit" ]
ep0_s4 [ shape=square label="Emit" ]
ep0_s5 [ shape=square label="Return" ]
ep0_s0 -> ep0_s1 [ arrowhead=tee label="" ]
ep0_s1 -> ep0_s2 [ arrowhead=tee label="" ]
ep0_s2 -> ep0_s3 [ arrowhead=tee label="" ]
ep0_s3 -> ep0_s4 [ arrowhead=tee label="" ]
ep0_s4 -> ep0_s5 [ arrowhead=tee label="" ]
ep0_e5 -> ep0_s5 [ label="value" ]
ep0_s1 -> ep0_e1 [ style=dotted ]
ep0_s2 -> ep0_e2 [ style=dotted ]
ep0_s3 -> ep0_e3 [ style=dotted ]
ep0_s4 -> ep0_e4 [ style=dotted ]
ep0_s4 -> ep0_e5 [ style=dotted ]
}
}
EOF
end
end