#include "third_party/blink/renderer/modules/webgpu/gpu_buffer.h"
#include <cinttypes>
#include <utility>
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "gpu/command_buffer/client/webgpu_interface.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_gpu_buffer_descriptor.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/modules/webgpu/dawn_conversions.h"
#include "third_party/blink/renderer/modules/webgpu/gpu.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_adapter.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_device.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_queue.h"
#include "third_party/blink/renderer/platform/graphics/gpu/webgpu_callback.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
namespace blink {
namespace {
constexpr uint64_t kGuaranteedBufferOOMSize = …;
wgpu::BufferDescriptor AsDawnType(const GPUBufferDescriptor* webgpu_desc,
std::string* label) { … }
}
class GPUMappedDOMArrayBuffer : public DOMArrayBuffer { … };
GPUBuffer* GPUBuffer::Create(GPUDevice* device,
const GPUBufferDescriptor* webgpu_desc,
ExceptionState& exception_state) { … }
GPUBuffer::GPUBuffer(GPUDevice* device,
uint64_t size,
wgpu::Buffer buffer,
const String& label)
: … { … }
GPUBuffer::~GPUBuffer() { … }
void GPUBuffer::Trace(Visitor* visitor) const { … }
ScriptPromise<IDLUndefined> GPUBuffer::mapAsync(
ScriptState* script_state,
uint32_t mode,
uint64_t offset,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> GPUBuffer::mapAsync(
ScriptState* script_state,
uint32_t mode,
uint64_t offset,
uint64_t size,
ExceptionState& exception_state) { … }
DOMArrayBuffer* GPUBuffer::getMappedRange(ScriptState* script_state,
uint64_t offset,
ExceptionState& exception_state) { … }
DOMArrayBuffer* GPUBuffer::getMappedRange(ScriptState* script_state,
uint64_t offset,
uint64_t size,
ExceptionState& exception_state) { … }
void GPUBuffer::unmap(v8::Isolate* isolate) { … }
void GPUBuffer::destroy(v8::Isolate* isolate) { … }
uint64_t GPUBuffer::size() const { … }
uint32_t GPUBuffer::usage() const { … }
String GPUBuffer::mapState() const { … }
ScriptPromise<IDLUndefined> GPUBuffer::MapAsyncImpl(
ScriptState* script_state,
uint32_t mode,
uint64_t offset,
std::optional<uint64_t> size,
ExceptionState& exception_state) { … }
DOMArrayBuffer* GPUBuffer::GetMappedRangeImpl(ScriptState* script_state,
uint64_t offset,
std::optional<uint64_t> size,
ExceptionState& exception_state) { … }
void GPUBuffer::OnMapAsyncCallback(
ScriptPromiseResolver<IDLUndefined>* resolver,
wgpu::MapAsyncStatus status,
const char* message) { … }
DOMArrayBuffer* GPUBuffer::CreateArrayBufferForMappedData(v8::Isolate* isolate,
void* data,
size_t data_length) { … }
void GPUBuffer::ResetMappingState(v8::Isolate* isolate) { … }
void GPUBuffer::DetachMappedArrayBuffers(v8::Isolate* isolate) { … }
}