Ben Vanik | e7c2cba | 2021-07-19 15:45:39 -0700 | [diff] [blame] | 1 | // Copyright 2021 The IREE Authors |
| 2 | // |
| 3 | // Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | |
| 7 | #ifndef IREE_HAL_DRIVERS_WEBGPU_PIPELINE_LAYOUT_H_ |
| 8 | #define IREE_HAL_DRIVERS_WEBGPU_PIPELINE_LAYOUT_H_ |
| 9 | |
| 10 | #include "experimental/webgpu/platform/webgpu.h" |
| 11 | #include "experimental/webgpu/staging_buffer.h" |
| 12 | #include "iree/base/api.h" |
| 13 | #include "iree/hal/api.h" |
| 14 | |
| 15 | #ifdef __cplusplus |
| 16 | extern "C" { |
| 17 | #endif // __cplusplus |
| 18 | |
| 19 | #define IREE_HAL_WEBGPU_MAX_DESCRIPTOR_SET_COUNT 4 |
| 20 | #define IREE_HAL_WEBGPU_MAX_PUSH_CONSTANT_COUNT 64 |
| 21 | #define IREE_HAL_WEBGPU_PARAMS_BIND_GROUP_INDEX 3 |
| 22 | |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | // iree_hal_webgpu_descriptor_set_layout_t |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | |
| 27 | // TODO(benvanik): query from runtime? almost all devices support 16+ and |
| 28 | // that's what our compiler is assuming. |
| 29 | #define IREE_HAL_WEBGPU_MAX_DESCRIPTOR_SET_BINDING_COUNT 8 |
| 30 | |
| 31 | typedef uint32_t iree_hal_webgpu_binding_mask_t; |
| 32 | static_assert(sizeof(iree_hal_webgpu_binding_mask_t) * 8 >= |
| 33 | IREE_HAL_WEBGPU_MAX_DESCRIPTOR_SET_BINDING_COUNT, |
| 34 | "mask must have capacity for one bit per binding in a group"); |
| 35 | |
| 36 | iree_status_t iree_hal_webgpu_descriptor_set_layout_create( |
| 37 | WGPUDevice device, iree_hal_descriptor_set_layout_flags_t flags, |
| 38 | iree_host_size_t binding_count, |
| 39 | const iree_hal_descriptor_set_layout_binding_t* bindings, |
| 40 | iree_allocator_t host_allocator, |
| 41 | iree_hal_descriptor_set_layout_t** out_descriptor_set_layout); |
| 42 | |
| 43 | WGPUBindGroupLayout iree_hal_webgpu_descriptor_set_layout_handle( |
| 44 | iree_hal_descriptor_set_layout_t* layout); |
| 45 | |
| 46 | iree_hal_webgpu_binding_mask_t |
| 47 | iree_hal_webgpu_descriptor_set_layout_binding_mask( |
| 48 | iree_hal_descriptor_set_layout_t* layout); |
| 49 | |
| 50 | //===----------------------------------------------------------------------===// |
| 51 | // iree_hal_webgpu_pipeline_layout_t |
| 52 | //===----------------------------------------------------------------------===// |
| 53 | |
| 54 | typedef struct iree_hal_webgpu_set_binding_info_t { |
| 55 | iree_host_size_t set_count; |
| 56 | WGPUBindGroupLayout set_layouts[IREE_HAL_WEBGPU_MAX_DESCRIPTOR_SET_COUNT]; |
| 57 | iree_hal_webgpu_binding_mask_t |
| 58 | set_masks[IREE_HAL_WEBGPU_MAX_DESCRIPTOR_SET_COUNT]; |
| 59 | } iree_hal_webgpu_set_binding_info_t; |
| 60 | |
| 61 | iree_status_t iree_hal_webgpu_pipeline_layout_create( |
| 62 | WGPUDevice device, iree_host_size_t set_layout_count, |
| 63 | iree_hal_descriptor_set_layout_t* const* set_layouts, |
Ben Vanik | e2a2b2b | 2024-08-22 11:56:59 -0700 | [diff] [blame] | 64 | iree_host_size_t constant_count, |
Ben Vanik | e7c2cba | 2021-07-19 15:45:39 -0700 | [diff] [blame] | 65 | iree_hal_webgpu_staging_buffer_t* staging_buffer, |
| 66 | iree_allocator_t host_allocator, |
| 67 | iree_hal_pipeline_layout_t** out_pipeline_layout); |
| 68 | |
| 69 | WGPUPipelineLayout iree_hal_webgpu_pipeline_layout_handle( |
| 70 | iree_hal_pipeline_layout_t* layout); |
| 71 | |
Ben Vanik | e2a2b2b | 2024-08-22 11:56:59 -0700 | [diff] [blame] | 72 | iree_host_size_t iree_hal_webgpu_pipeline_layout_constant_count( |
Ben Vanik | e7c2cba | 2021-07-19 15:45:39 -0700 | [diff] [blame] | 73 | iree_hal_pipeline_layout_t* layout); |
| 74 | |
| 75 | const iree_hal_webgpu_set_binding_info_t* |
| 76 | iree_hal_webgpu_pipeline_layout_set_binding_info( |
| 77 | iree_hal_pipeline_layout_t* layout); |
| 78 | |
| 79 | #ifdef __cplusplus |
| 80 | } // extern "C" |
| 81 | #endif // __cplusplus |
| 82 | |
| 83 | #endif // IREE_HAL_DRIVERS_WEBGPU_PIPELINE_LAYOUT_H_ |