summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/webgpu/gpu_shader_module.cc
blob: c9f4e024d1bcf40808f905996a349728d0935a96 (plain)
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
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/webgpu/gpu_shader_module.h"

#include "third_party/blink/renderer/modules/webgpu/gpu_device.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_shader_module_descriptor.h"

namespace blink {

namespace {

WGPUShaderModuleDescriptor AsDawnType(
    const GPUShaderModuleDescriptor* webgpu_desc) {
  WGPUShaderModuleDescriptor dawn_desc = {};

  dawn_desc.nextInChain = nullptr;
  dawn_desc.code = webgpu_desc->code().View()->Data();
  dawn_desc.codeSize = webgpu_desc->code().View()->deprecatedLengthAsUnsigned();
  if (webgpu_desc->hasLabel()) {
    dawn_desc.label = webgpu_desc->label().Utf8().data();
  }

  return dawn_desc;
}

}  // anonymous namespace

// static
GPUShaderModule* GPUShaderModule::Create(
    GPUDevice* device,
    const GPUShaderModuleDescriptor* webgpu_desc) {
  DCHECK(device);
  DCHECK(webgpu_desc);
  WGPUShaderModuleDescriptor dawn_desc = AsDawnType(webgpu_desc);
  return MakeGarbageCollected<GPUShaderModule>(
      device, device->GetProcs().deviceCreateShaderModule(device->GetHandle(),
                                                          &dawn_desc));
}

GPUShaderModule::GPUShaderModule(GPUDevice* device,
                                 WGPUShaderModule shader_module)
    : DawnObject<WGPUShaderModule>(device, shader_module) {}

GPUShaderModule::~GPUShaderModule() {
  if (IsDawnControlClientDestroyed()) {
    return;
  }
  GetProcs().shaderModuleRelease(GetHandle());
}

}  // namespace blink