tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SupportedLimits.cpp (7977B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #include "SupportedLimits.h"
      7 
      8 #include "Adapter.h"
      9 #include "mozilla/dom/WebGPUBinding.h"
     10 
     11 namespace mozilla::webgpu {
     12 
     13 GPU_IMPL_CYCLE_COLLECTION(SupportedLimits, mParent)
     14 GPU_IMPL_JS_WRAP(SupportedLimits)
     15 
     16 SupportedLimits::SupportedLimits(Adapter* const aParent,
     17                                 const ffi::WGPULimits& aLimits)
     18    : ChildOf(aParent), mFfi(std::make_unique<ffi::WGPULimits>(aLimits)) {}
     19 
     20 SupportedLimits::~SupportedLimits() = default;
     21 
     22 uint64_t GetLimit(const ffi::WGPULimits& limits, const Limit limit) {
     23  switch (limit) {
     24    case Limit::MaxTextureDimension1D:
     25      return limits.max_texture_dimension_1d;
     26    case Limit::MaxTextureDimension2D:
     27      return limits.max_texture_dimension_2d;
     28    case Limit::MaxTextureDimension3D:
     29      return limits.max_texture_dimension_3d;
     30    case Limit::MaxTextureArrayLayers:
     31      return limits.max_texture_array_layers;
     32    case Limit::MaxBindGroups:
     33      return limits.max_bind_groups;
     34    case Limit::MaxBindGroupsPlusVertexBuffers:
     35      // Not in ffi::WGPULimits, so synthesize:
     36      return GetLimit(limits, Limit::MaxBindGroups) +
     37             GetLimit(limits, Limit::MaxVertexBuffers);
     38    case Limit::MaxBindingsPerBindGroup:
     39      return limits.max_bindings_per_bind_group;
     40    case Limit::MaxDynamicUniformBuffersPerPipelineLayout:
     41      return limits.max_dynamic_uniform_buffers_per_pipeline_layout;
     42    case Limit::MaxDynamicStorageBuffersPerPipelineLayout:
     43      return limits.max_dynamic_storage_buffers_per_pipeline_layout;
     44    case Limit::MaxSampledTexturesPerShaderStage:
     45      return limits.max_sampled_textures_per_shader_stage;
     46    case Limit::MaxSamplersPerShaderStage:
     47      return limits.max_samplers_per_shader_stage;
     48    case Limit::MaxStorageBuffersPerShaderStage:
     49      return limits.max_storage_buffers_per_shader_stage;
     50    case Limit::MaxStorageTexturesPerShaderStage:
     51      return limits.max_storage_textures_per_shader_stage;
     52    case Limit::MaxUniformBuffersPerShaderStage:
     53      return limits.max_uniform_buffers_per_shader_stage;
     54    case Limit::MaxUniformBufferBindingSize:
     55      return limits.max_uniform_buffer_binding_size;
     56    case Limit::MaxStorageBufferBindingSize:
     57      return limits.max_storage_buffer_binding_size;
     58    case Limit::MinUniformBufferOffsetAlignment:
     59      return limits.min_uniform_buffer_offset_alignment;
     60    case Limit::MinStorageBufferOffsetAlignment:
     61      return limits.min_storage_buffer_offset_alignment;
     62    case Limit::MaxVertexBuffers:
     63      return limits.max_vertex_buffers;
     64    case Limit::MaxBufferSize:
     65      return limits.max_buffer_size;
     66    case Limit::MaxVertexAttributes:
     67      return limits.max_vertex_attributes;
     68    case Limit::MaxVertexBufferArrayStride:
     69      return limits.max_vertex_buffer_array_stride;
     70    case Limit::MaxInterStageShaderVariables:
     71      return 16;  // From the spec. (not in ffi::WGPULimits)
     72    case Limit::MaxColorAttachments:
     73      return 8;  // From the spec. (not in ffi::WGPULimits)
     74    case Limit::MaxColorAttachmentBytesPerSample:
     75      return 32;  // From the spec. (not in ffi::WGPULimits)
     76    case Limit::MaxComputeWorkgroupStorageSize:
     77      return limits.max_compute_workgroup_storage_size;
     78    case Limit::MaxComputeInvocationsPerWorkgroup:
     79      return limits.max_compute_invocations_per_workgroup;
     80    case Limit::MaxComputeWorkgroupSizeX:
     81      return limits.max_compute_workgroup_size_x;
     82    case Limit::MaxComputeWorkgroupSizeY:
     83      return limits.max_compute_workgroup_size_y;
     84    case Limit::MaxComputeWorkgroupSizeZ:
     85      return limits.max_compute_workgroup_size_z;
     86    case Limit::MaxComputeWorkgroupsPerDimension:
     87      return limits.max_compute_workgroups_per_dimension;
     88  }
     89  MOZ_CRASH("Bad Limit");
     90 }
     91 
     92 void SetLimit(ffi::WGPULimits* const limits, const Limit limit,
     93              const double val) {
     94  const auto autoVal = LazyAssertedCast(static_cast<uint64_t>(val));
     95  switch (limit) {
     96    case Limit::MaxTextureDimension1D:
     97      limits->max_texture_dimension_1d = autoVal;
     98      return;
     99    case Limit::MaxTextureDimension2D:
    100      limits->max_texture_dimension_2d = autoVal;
    101      return;
    102    case Limit::MaxTextureDimension3D:
    103      limits->max_texture_dimension_3d = autoVal;
    104      return;
    105    case Limit::MaxTextureArrayLayers:
    106      limits->max_texture_array_layers = autoVal;
    107      return;
    108    case Limit::MaxBindGroups:
    109      limits->max_bind_groups = autoVal;
    110      return;
    111    case Limit::MaxBindGroupsPlusVertexBuffers:
    112      // Not in ffi::WGPULimits, and we're allowed to give back better
    113      // limits than requested.
    114      return;
    115    case Limit::MaxBindingsPerBindGroup:
    116      limits->max_bindings_per_bind_group = autoVal;
    117      return;
    118    case Limit::MaxDynamicUniformBuffersPerPipelineLayout:
    119      limits->max_dynamic_uniform_buffers_per_pipeline_layout = autoVal;
    120      return;
    121    case Limit::MaxDynamicStorageBuffersPerPipelineLayout:
    122      limits->max_dynamic_storage_buffers_per_pipeline_layout = autoVal;
    123      return;
    124    case Limit::MaxSampledTexturesPerShaderStage:
    125      limits->max_sampled_textures_per_shader_stage = autoVal;
    126      return;
    127    case Limit::MaxSamplersPerShaderStage:
    128      limits->max_samplers_per_shader_stage = autoVal;
    129      return;
    130    case Limit::MaxStorageBuffersPerShaderStage:
    131      limits->max_storage_buffers_per_shader_stage = autoVal;
    132      return;
    133    case Limit::MaxStorageTexturesPerShaderStage:
    134      limits->max_storage_textures_per_shader_stage = autoVal;
    135      return;
    136    case Limit::MaxUniformBuffersPerShaderStage:
    137      limits->max_uniform_buffers_per_shader_stage = autoVal;
    138      return;
    139    case Limit::MaxUniformBufferBindingSize:
    140      limits->max_uniform_buffer_binding_size = autoVal;
    141      return;
    142    case Limit::MaxStorageBufferBindingSize:
    143      limits->max_storage_buffer_binding_size = autoVal;
    144      return;
    145    case Limit::MinUniformBufferOffsetAlignment:
    146      limits->min_uniform_buffer_offset_alignment = autoVal;
    147      return;
    148    case Limit::MinStorageBufferOffsetAlignment:
    149      limits->min_storage_buffer_offset_alignment = autoVal;
    150      return;
    151    case Limit::MaxVertexBuffers:
    152      limits->max_vertex_buffers = autoVal;
    153      return;
    154    case Limit::MaxBufferSize:
    155      limits->max_buffer_size = autoVal;
    156      return;
    157    case Limit::MaxVertexAttributes:
    158      limits->max_vertex_attributes = autoVal;
    159      return;
    160    case Limit::MaxVertexBufferArrayStride:
    161      limits->max_vertex_buffer_array_stride = autoVal;
    162      return;
    163    case Limit::MaxInterStageShaderVariables:
    164      // Not in ffi::WGPULimits, and we're allowed to give back better
    165      // limits than requested.
    166      return;
    167    case Limit::MaxColorAttachments:
    168      // Not in ffi::WGPULimits, and we're allowed to give back better
    169      // limits than requested.
    170      return;
    171    case Limit::MaxColorAttachmentBytesPerSample:
    172      // Not in ffi::WGPULimits, and we're allowed to give back better
    173      // limits than requested.
    174      return;
    175    case Limit::MaxComputeWorkgroupStorageSize:
    176      limits->max_compute_workgroup_storage_size = autoVal;
    177      return;
    178    case Limit::MaxComputeInvocationsPerWorkgroup:
    179      limits->max_compute_invocations_per_workgroup = autoVal;
    180      return;
    181    case Limit::MaxComputeWorkgroupSizeX:
    182      limits->max_compute_workgroup_size_x = autoVal;
    183      return;
    184    case Limit::MaxComputeWorkgroupSizeY:
    185      limits->max_compute_workgroup_size_y = autoVal;
    186      return;
    187    case Limit::MaxComputeWorkgroupSizeZ:
    188      limits->max_compute_workgroup_size_z = autoVal;
    189      return;
    190    case Limit::MaxComputeWorkgroupsPerDimension:
    191      limits->max_compute_workgroups_per_dimension = autoVal;
    192      return;
    193  }
    194  MOZ_CRASH("Bad Limit");
    195 }
    196 
    197 }  // namespace mozilla::webgpu