about summary refs log tree commit diff
path: root/pkgs/tools/graphics/amber/default.nix
blob: 0d86e5c75bfb484a76cc0ea03a4ad7e4eb150d52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
{ lib, stdenv
, fetchFromGitHub
, cmake
, pkg-config
, cctools
, makeWrapper
, mesa
, python3
, runCommand
, vulkan-headers
, vulkan-loader
, vulkan-validation-layers
}:
let
  # From https://github.com/google/amber/blob/main/DEPS
  glslang = fetchFromGitHub {
    owner = "KhronosGroup";
    repo = "glslang";
    rev = "e8dd0b6903b34f1879520b444634c75ea2deedf5";
    hash = "sha256-B6jVCeoFjd2H6+7tIses+Kj8DgHS6E2dkVzQAIzDHEc=";
  };

  lodepng = fetchFromGitHub {
    owner = "lvandeve";
    repo = "lodepng";
    rev = "5601b8272a6850b7c5d693dd0c0e16da50be8d8d";
    hash = "sha256-dD8QoyOoGov6VENFNTXWRmen4nYYleoZ8+4TpICNSpo=";
  };

  shaderc = fetchFromGitHub {
    owner = "google";
    repo = "shaderc";
    rev = "f59f0d11b80fd622383199c867137ededf89d43b";
    hash = "sha256-kHz8Io5GZDWv1FjPyBWRpnKhGygKhSU4L9zl/AKXZlU=";
  };

  spirv-headers = fetchFromGitHub {
    owner = "KhronosGroup";
    repo = "SPIRV-Headers";
    rev = "5e3ad389ee56fca27c9705d093ae5387ce404df4";
    hash = "sha256-gjF5mVTXqU/GZzr2S6oKGChgvqqHcQSrEq/ePP2yJys=";
  };

  spirv-tools = fetchFromGitHub {
    owner = "KhronosGroup";
    repo = "SPIRV-Tools";
    rev = "9241a58a8028c49510bc174b6c970e3c2b4b8e51";
    hash = "sha256-0qHUpwNDJI2jV4h68QaTNPIwTPxwTt0iAUnMXqFCiJE=";
  };

in
stdenv.mkDerivation (finalAttrs: {
  pname = "amber";
  version = "unstable-2024-08-21";

  src = fetchFromGitHub {
    owner = "google";
    repo = "amber";
    rev = "66399a35927606a435bf7a59756e87e6cb5a0013";
    hash = "sha256-PCO64zI/vzp4HyGz5WpeYpCBeaWjTvz1punWsTz1yiM=";
  };

  buildInputs = [
    vulkan-headers
    vulkan-loader
  ];

  nativeBuildInputs = [
    cmake
    makeWrapper
    pkg-config
    python3
  ] ++ lib.optionals stdenv.isDarwin [
    cctools
  ];

  # Tests are disabled so we do not have to pull in googletest and more dependencies
  cmakeFlags = [ "-DAMBER_SKIP_TESTS=ON" "-DAMBER_DISABLE_WERROR=ON" ];

  prePatch = ''
    cp -r ${glslang}/ third_party/glslang
    cp -r ${lodepng}/ third_party/lodepng
    cp -r ${shaderc}/ third_party/shaderc
    cp -r ${spirv-tools}/ third_party/spirv-tools
    cp -r ${spirv-headers}/ third_party/spirv-headers
    chmod u+w -R third_party

    substituteInPlace tools/update_build_version.py \
      --replace "not os.path.exists(directory)" "True"
  '';

  installPhase = ''
    install -Dm755 -t $out/bin amber image_diff
    wrapProgram $out/bin/amber \
      --suffix VK_LAYER_PATH : ${vulkan-validation-layers}/share/vulkan/explicit_layer.d
  '';

  passthru.tests.lavapipe = runCommand "vulkan-cts-tests-lavapipe" {
    nativeBuildInputs = [ finalAttrs.finalPackage mesa.llvmpipeHook ];
  } ''
    cat > test.amber <<EOF
    #!amber
    # Simple amber compute shader.

    SHADER compute kComputeShader GLSL
    #version 450

    layout(binding = 3) buffer block {
      uvec2 values[];
    };

    void main() {
      values[gl_WorkGroupID.x + gl_WorkGroupID.y * gl_NumWorkGroups.x] =
                    gl_WorkGroupID.xy;
    }
    END  # shader

    BUFFER kComputeBuffer DATA_TYPE vec2<int32> SIZE 524288 FILL 0

    PIPELINE compute kComputePipeline
      ATTACH kComputeShader
      BIND BUFFER kComputeBuffer AS storage DESCRIPTOR_SET 0 BINDING 3
    END  # pipeline

    RUN kComputePipeline 256 256 1

    # Four corners
    EXPECT kComputeBuffer IDX 0 EQ 0 0
    EXPECT kComputeBuffer IDX 2040 EQ 255 0
    EXPECT kComputeBuffer IDX 522240 EQ 0 255
    EXPECT kComputeBuffer IDX 524280 EQ 255 255

    # Center
    EXPECT kComputeBuffer IDX 263168 EQ 128 128
    EOF

    amber test.amber
    touch $out
  '';

  meta = with lib; {
    description = "Multi-API shader test framework";
    homepage = "https://github.com/google/amber";
    license = licenses.asl20;
    maintainers = with maintainers; [ Flakebi ];
  };
})