dan sinclair | 0ebbc5c | 2023-11-29 17:53:24 +0000 | [diff] [blame] | 1 | // Copyright 2023 The Dawn & Tint Authors |
| 2 | // |
| 3 | // Redistribution and use in source and binary forms, with or without |
| 4 | // modification, are permitted provided that the following conditions are met: |
| 5 | // |
| 6 | // 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | // list of conditions and the following disclaimer. |
| 8 | // |
| 9 | // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 10 | // this list of conditions and the following disclaimer in the documentation |
| 11 | // and/or other materials provided with the distribution. |
| 12 | // |
| 13 | // 3. Neither the name of the copyright holder nor the names of its |
| 14 | // contributors may be used to endorse or promote products derived from |
| 15 | // this software without specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | //////////////////////////////////////////////////////////////////////////////// |
| 29 | // MSL builtin definition file // |
Ben Clayton | e435124 | 2024-02-21 08:11:33 +0000 | [diff] [blame] | 30 | // |
| 31 | // After modifying this file, run: // |
| 32 | // tools/run gen // |
| 33 | // from the Dawn source directory. // |
| 34 | // // |
| 35 | // See docs/tint/intrinsic_definition_files.md for syntax // |
dan sinclair | 0ebbc5c | 2023-11-29 17:53:24 +0000 | [diff] [blame] | 36 | //////////////////////////////////////////////////////////////////////////////// |
| 37 | |
James Price | 0272fd2 | 2024-06-05 12:24:04 +0000 | [diff] [blame] | 38 | import "src/tint/lang/core/access.def" |
| 39 | import "src/tint/lang/core/address_space.def" |
James Price | 456cf28 | 2024-06-11 18:24:06 +0000 | [diff] [blame] | 40 | import "src/tint/lang/core/texel_format.def" |
James Price | 0272fd2 | 2024-06-05 12:24:04 +0000 | [diff] [blame] | 41 | |
| 42 | //////////////////////////////////////////////////////////////////////////////// |
| 43 | // Enum matchers // |
| 44 | //////////////////////////////////////////////////////////////////////////////// |
| 45 | |
| 46 | match read_write: access.read_write |
| 47 | |
James Price | fae957f | 2024-06-05 12:24:04 +0000 | [diff] [blame] | 48 | match function: address_space.function |
James Price | 0272fd2 | 2024-06-05 12:24:04 +0000 | [diff] [blame] | 49 | match workgroup_or_storage |
| 50 | : address_space.workgroup |
| 51 | | address_space.storage |
| 52 | |
| 53 | //////////////////////////////////////////////////////////////////////////////// |
| 54 | // Types // |
| 55 | //////////////////////////////////////////////////////////////////////////////// |
| 56 | |
James Price | fae957f | 2024-06-05 12:24:04 +0000 | [diff] [blame] | 57 | type bool |
James Price | 0272fd2 | 2024-06-05 12:24:04 +0000 | [diff] [blame] | 58 | type i32 |
dan sinclair | 0ebbc5c | 2023-11-29 17:53:24 +0000 | [diff] [blame] | 59 | type u32 |
James Price | 54883c2 | 2024-06-11 18:24:06 +0000 | [diff] [blame] | 60 | type f32 |
| 61 | type vec2<T> |
| 62 | type vec3<T> |
| 63 | type vec4<T> |
James Price | 0272fd2 | 2024-06-05 12:24:04 +0000 | [diff] [blame] | 64 | type atomic<T> |
| 65 | type ptr<S: address_space, T, A: access> |
James Price | 54883c2 | 2024-06-11 18:24:06 +0000 | [diff] [blame] | 66 | type sampler |
| 67 | type texture_1d<T> |
| 68 | type texture_2d<T> |
| 69 | type texture_2d_array<T> |
| 70 | type texture_3d<T> |
| 71 | type texture_cube<T> |
| 72 | type texture_cube_array<T> |
| 73 | type texture_depth_2d |
| 74 | type texture_depth_2d_array |
| 75 | type texture_depth_cube |
| 76 | type texture_depth_cube_array |
James Price | 456cf28 | 2024-06-11 18:24:06 +0000 | [diff] [blame] | 77 | type texture_depth_multisampled_2d |
| 78 | type texture_multisampled_2d<T> |
| 79 | type texture_storage_1d<F: texel_format, A: access> |
| 80 | type texture_storage_2d<F: texel_format, A: access> |
| 81 | type texture_storage_2d_array<F: texel_format, A: access> |
| 82 | type texture_storage_3d<F: texel_format, A: access> |
James Price | 0272fd2 | 2024-06-05 12:24:04 +0000 | [diff] [blame] | 83 | |
| 84 | //////////////////////////////////////////////////////////////////////////////// |
| 85 | // Type matchers // |
| 86 | //////////////////////////////////////////////////////////////////////////////// |
| 87 | |
| 88 | match iu32: i32 | u32 |
James Price | 456cf28 | 2024-06-11 18:24:06 +0000 | [diff] [blame] | 89 | match fiu32: f32 | i32 | u32 |
dan sinclair | 0ebbc5c | 2023-11-29 17:53:24 +0000 | [diff] [blame] | 90 | |
| 91 | //////////////////////////////////////////////////////////////////////////////// |
| 92 | // Builtin Functions // |
| 93 | //////////////////////////////////////////////////////////////////////////////// |
James Price | fae957f | 2024-06-05 12:24:04 +0000 | [diff] [blame] | 94 | @stage("fragment", "compute") fn atomic_compare_exchange_weak_explicit[T: iu32, S: workgroup_or_storage](ptr<S, atomic<T>, read_write>, ptr<function, T, read_write>, T, u32, u32) -> bool |
James Price | 0272fd2 | 2024-06-05 12:24:04 +0000 | [diff] [blame] | 95 | @stage("fragment", "compute") fn atomic_exchange_explicit[T: iu32, S: workgroup_or_storage](ptr<S, atomic<T>, read_write>, T, u32) -> T |
| 96 | @stage("fragment", "compute") fn atomic_fetch_add_explicit[T: iu32, S: workgroup_or_storage](ptr<S, atomic<T>, read_write>, T, u32) -> T |
| 97 | @stage("fragment", "compute") fn atomic_fetch_and_explicit[T: iu32, S: workgroup_or_storage](ptr<S, atomic<T>, read_write>, T, u32) -> T |
| 98 | @stage("fragment", "compute") fn atomic_fetch_max_explicit[T: iu32, S: workgroup_or_storage](ptr<S, atomic<T>, read_write>, T, u32) -> T |
| 99 | @stage("fragment", "compute") fn atomic_fetch_min_explicit[T: iu32, S: workgroup_or_storage](ptr<S, atomic<T>, read_write>, T, u32) -> T |
| 100 | @stage("fragment", "compute") fn atomic_fetch_or_explicit[T: iu32, S: workgroup_or_storage](ptr<S, atomic<T>, read_write>, T, u32) -> T |
| 101 | @stage("fragment", "compute") fn atomic_fetch_sub_explicit[T: iu32, S: workgroup_or_storage](ptr<S, atomic<T>, read_write>, T, u32) -> T |
| 102 | @stage("fragment", "compute") fn atomic_fetch_xor_explicit[T: iu32, S: workgroup_or_storage](ptr<S, atomic<T>, read_write>, T, u32) -> T |
| 103 | @stage("fragment", "compute") fn atomic_load_explicit[T: iu32, S: workgroup_or_storage](ptr<S, atomic<T>, read_write>, u32) -> T |
| 104 | @stage("fragment", "compute") fn atomic_store_explicit[T: iu32, S: workgroup_or_storage](ptr<S, atomic<T>, read_write>, T, u32) |
James Price | 54883c2 | 2024-06-11 18:24:06 +0000 | [diff] [blame] | 105 | |
James Price | 456cf28 | 2024-06-11 18:24:06 +0000 | [diff] [blame] | 106 | @member_function fn get_width[T: fiu32](texture: texture_1d<T>) -> u32 |
| 107 | @member_function fn get_width[T: fiu32](texture: texture_2d<T>, u32) -> u32 |
| 108 | @member_function fn get_width[T: fiu32](texture: texture_2d_array<T>, u32) -> u32 |
| 109 | @member_function fn get_width[T: fiu32](texture: texture_3d<T>, u32) -> u32 |
| 110 | @member_function fn get_width[T: fiu32](texture: texture_cube<T>, u32) -> u32 |
| 111 | @member_function fn get_width[T: fiu32](texture: texture_cube_array<T>, u32) -> u32 |
| 112 | @member_function fn get_width[T: fiu32](texture: texture_multisampled_2d<T>) -> u32 |
| 113 | @member_function fn get_width(texture: texture_depth_2d, u32) -> u32 |
| 114 | @member_function fn get_width(texture: texture_depth_2d_array, u32) -> u32 |
| 115 | @member_function fn get_width(texture: texture_depth_cube, u32) -> u32 |
| 116 | @member_function fn get_width(texture: texture_depth_cube_array, u32) -> u32 |
| 117 | @member_function fn get_width(texture: texture_depth_multisampled_2d) -> u32 |
| 118 | @member_function fn get_width[F: texel_format, A: access](texture: texture_storage_1d<F, A>) -> u32 |
| 119 | @member_function fn get_width[F: texel_format, A: access](texture: texture_storage_2d<F, A>, u32) -> u32 |
| 120 | @member_function fn get_width[F: texel_format, A: access](texture: texture_storage_2d_array<F, A>, u32) -> u32 |
| 121 | @member_function fn get_width[F: texel_format, A: access](texture: texture_storage_3d<F, A>, u32) -> u32 |
| 122 | |
| 123 | @member_function fn get_height[T: fiu32](texture: texture_2d<T>, u32) -> u32 |
| 124 | @member_function fn get_height[T: fiu32](texture: texture_2d_array<T>, u32) -> u32 |
| 125 | @member_function fn get_height[T: fiu32](texture: texture_3d<T>, u32) -> u32 |
| 126 | @member_function fn get_height[T: fiu32](texture: texture_cube<T>, u32) -> u32 |
| 127 | @member_function fn get_height[T: fiu32](texture: texture_cube_array<T>, u32) -> u32 |
| 128 | @member_function fn get_height[T: fiu32](texture: texture_multisampled_2d<T>) -> u32 |
| 129 | @member_function fn get_height(texture: texture_depth_2d, u32) -> u32 |
| 130 | @member_function fn get_height(texture: texture_depth_2d_array, u32) -> u32 |
| 131 | @member_function fn get_height(texture: texture_depth_cube, u32) -> u32 |
| 132 | @member_function fn get_height(texture: texture_depth_cube_array, u32) -> u32 |
| 133 | @member_function fn get_height(texture: texture_depth_multisampled_2d) -> u32 |
| 134 | @member_function fn get_height[F: texel_format, A: access](texture: texture_storage_2d<F, A>, u32) -> u32 |
| 135 | @member_function fn get_height[F: texel_format, A: access](texture: texture_storage_2d_array<F, A>, u32) -> u32 |
| 136 | @member_function fn get_height[F: texel_format, A: access](texture: texture_storage_3d<F, A>, u32) -> u32 |
| 137 | |
| 138 | @member_function fn get_depth[T: fiu32](texture: texture_3d<T>, u32) -> u32 |
| 139 | @member_function fn get_depth[F: texel_format, A: access](texture: texture_storage_3d<F, A>, u32) -> u32 |
| 140 | |
James Price | 54883c2 | 2024-06-11 18:24:06 +0000 | [diff] [blame] | 141 | @member_function @stage("fragment") fn sample(texture: texture_1d<f32>, sampler: sampler, coords: f32) -> vec4<f32> |
| 142 | @member_function @stage("fragment") fn sample(texture: texture_2d<f32>, sampler: sampler, coords: vec2<f32>) -> vec4<f32> |
| 143 | @member_function @stage("fragment") fn sample(texture: texture_2d<f32>, sampler: sampler, coords: vec2<f32>, @const offset: vec2<i32>) -> vec4<f32> |
| 144 | @member_function @stage("fragment") fn sample[A: iu32](texture: texture_2d_array<f32>, sampler: sampler, coords: vec2<f32>, array_index: A) -> vec4<f32> |
| 145 | @member_function @stage("fragment") fn sample[A: iu32](texture: texture_2d_array<f32>, sampler: sampler, coords: vec2<f32>, array_index: A, @const offset: vec2<i32>) -> vec4<f32> |
| 146 | @member_function @stage("fragment") fn sample(texture: texture_3d<f32>, sampler: sampler, coords: vec3<f32>) -> vec4<f32> |
| 147 | @member_function @stage("fragment") fn sample(texture: texture_3d<f32>, sampler: sampler, coords: vec3<f32>, @const offset: vec3<i32>) -> vec4<f32> |
| 148 | @member_function @stage("fragment") fn sample(texture: texture_cube<f32>, sampler: sampler, coords: vec3<f32>) -> vec4<f32> |
| 149 | @member_function @stage("fragment") fn sample[A: iu32](texture: texture_cube_array<f32>, sampler: sampler, coords: vec3<f32>, array_index: A) -> vec4<f32> |
| 150 | @member_function @stage("fragment") fn sample(texture: texture_depth_2d, sampler: sampler, coords: vec2<f32>) -> f32 |
| 151 | @member_function @stage("fragment") fn sample(texture: texture_depth_2d, sampler: sampler, coords: vec2<f32>, @const offset: vec2<i32>) -> f32 |
| 152 | @member_function @stage("fragment") fn sample[A: iu32](texture: texture_depth_2d_array, sampler: sampler, coords: vec2<f32>, array_index: A) -> f32 |
| 153 | @member_function @stage("fragment") fn sample[A: iu32](texture: texture_depth_2d_array, sampler: sampler, coords: vec2<f32>, array_index: A, @const offset: vec2<i32>) -> f32 |
| 154 | @member_function @stage("fragment") fn sample(texture: texture_depth_cube, sampler: sampler, coords: vec3<f32>) -> f32 |
| 155 | @member_function @stage("fragment") fn sample[A: iu32](texture: texture_depth_cube_array, sampler: sampler, coords: vec3<f32>, array_index: A) -> f32 |
| 156 | |
dan sinclair | 0ebbc5c | 2023-11-29 17:53:24 +0000 | [diff] [blame] | 157 | @stage("compute") fn threadgroup_barrier(u32) |
| 158 | |