File: WebGPUTypes.h

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (123 lines) | stat: -rw-r--r-- 3,470 bytes parent folder | download | duplicates (5)
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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef WEBGPU_TYPES_H_
#define WEBGPU_TYPES_H_

#include <cstdint>

#include "mozilla/GfxMessageUtils.h"
#include "mozilla/Maybe.h"
#include "mozilla/ParamTraits_STL.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/ipc/IPDLParamTraits.h"
#include "mozilla/layers/LayersSurfaces.h"
#include "nsString.h"

namespace mozilla::dom {
enum class GPUErrorFilter : uint8_t;
}  // namespace mozilla::dom

namespace mozilla::webgpu {

using RawId = uint64_t;
using BufferAddress = uint64_t;

struct ErrorScope {
  dom::GPUErrorFilter filter;
  Maybe<nsCString> firstMessage;
};

enum class PopErrorScopeResultType : uint8_t {
  NoError,
  ThrowOperationError,
  ValidationError,
  OutOfMemory,
  InternalError,
  DeviceLost,
  _LAST = DeviceLost,
};

struct PopErrorScopeResult {
  PopErrorScopeResultType resultType;
  nsCString message;
};

enum class WebGPUCompilationMessageType { Error, Warning, Info };

// TODO: Better name? CompilationMessage alread taken by the dom object.
/// The serializable counterpart of the dom object CompilationMessage.
struct WebGPUCompilationMessage {
  nsString message;
  uint64_t lineNum = 0;
  uint64_t linePos = 0;
  // In utf16 code units.
  uint64_t offset = 0;
  // In utf16 code units.
  uint64_t length = 0;
  WebGPUCompilationMessageType messageType =
      WebGPUCompilationMessageType::Error;
};

/// A helper to reduce the boiler plate of turning the many Optional<nsAString>
/// we get from the dom to the nullable nsACString* we pass to the wgpu ffi.
class StringHelper {
 public:
  explicit StringHelper(const nsString& aWide) {
    if (!aWide.IsEmpty()) {
      mNarrow = Some(NS_ConvertUTF16toUTF8(aWide));
    }
  }

  const nsACString* Get() const {
    if (mNarrow.isSome()) {
      return mNarrow.ptr();
    }
    return nullptr;
  }

 private:
  Maybe<NS_ConvertUTF16toUTF8> mNarrow;
};

// Used to create an ExternalTextureSourceHost.
struct ExternalTextureSourceDescriptor {
  std::array<RawId, 3> mTextureIds;
  std::array<RawId, 3> mViewIds;
  layers::SurfaceDescriptor mSurfaceDescriptor;
  gfx::IntSize mSize;
  std::array<float, 6> mSampleTransform;
  std::array<float, 6> mLoadTransform;
};

}  // namespace mozilla::webgpu

namespace IPC {
template <>
struct ParamTraits<mozilla::webgpu::ExternalTextureSourceDescriptor> {
  using ParamType = mozilla::webgpu::ExternalTextureSourceDescriptor;

  static void Write(MessageWriter* aWriter, const ParamType& aParam) {
    WriteParam(aWriter, aParam.mTextureIds);
    WriteParam(aWriter, aParam.mViewIds);
    WriteParam(aWriter, aParam.mSurfaceDescriptor);
    WriteParam(aWriter, aParam.mSize);
    WriteParam(aWriter, aParam.mSampleTransform);
    WriteParam(aWriter, aParam.mLoadTransform);
  }

  static bool Read(MessageReader* aReader, ParamType* aResult) {
    return ReadParam(aReader, &aResult->mTextureIds) &&
           ReadParam(aReader, &aResult->mViewIds) &&
           ReadParam(aReader, &aResult->mSurfaceDescriptor) &&
           ReadParam(aReader, &aResult->mSize) &&
           ReadParam(aReader, &aResult->mSampleTransform) &&
           ReadParam(aReader, &aResult->mLoadTransform);
  }
};

}  // namespace IPC

#endif  // WEBGPU_TYPES_H_