diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/webgpu/gpu_device.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/modules/webgpu/gpu_device.cc | 114 |
1 files changed, 36 insertions, 78 deletions
diff --git a/chromium/third_party/blink/renderer/modules/webgpu/gpu_device.cc b/chromium/third_party/blink/renderer/modules/webgpu/gpu_device.cc index e05039330f1..eb67079bbeb 100644 --- a/chromium/third_party/blink/renderer/modules/webgpu/gpu_device.cc +++ b/chromium/third_party/blink/renderer/modules/webgpu/gpu_device.cc @@ -7,6 +7,8 @@ #include "gpu/command_buffer/client/webgpu_interface.h" #include "third_party/blink/public/platform/platform.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_gpu_device_descriptor.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_gpu_uncaptured_error_event_init.h" #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/modules/event_target_modules.h" @@ -17,7 +19,6 @@ #include "third_party/blink/renderer/modules/webgpu/gpu_buffer.h" #include "third_party/blink/renderer/modules/webgpu/gpu_command_encoder.h" #include "third_party/blink/renderer/modules/webgpu/gpu_compute_pipeline.h" -#include "third_party/blink/renderer/modules/webgpu/gpu_device_descriptor.h" #include "third_party/blink/renderer/modules/webgpu/gpu_device_lost_info.h" #include "third_party/blink/renderer/modules/webgpu/gpu_pipeline_layout.h" #include "third_party/blink/renderer/modules/webgpu/gpu_queue.h" @@ -27,37 +28,30 @@ #include "third_party/blink/renderer/modules/webgpu/gpu_shader_module.h" #include "third_party/blink/renderer/modules/webgpu/gpu_texture.h" #include "third_party/blink/renderer/modules/webgpu/gpu_uncaptured_error_event.h" -#include "third_party/blink/renderer/modules/webgpu/gpu_uncaptured_error_event_init.h" +#include "third_party/blink/renderer/platform/heap/heap.h" namespace blink { -// static -GPUDevice* GPUDevice::Create( - ExecutionContext* execution_context, - scoped_refptr<DawnControlClientHolder> dawn_control_client, - GPUAdapter* adapter, - const GPUDeviceDescriptor* descriptor) { - return MakeGarbageCollected<GPUDevice>( - execution_context, std::move(dawn_control_client), adapter, descriptor); -} - // TODO(enga): Handle adapter options and device descriptor GPUDevice::GPUDevice(ExecutionContext* execution_context, scoped_refptr<DawnControlClientHolder> dawn_control_client, GPUAdapter* adapter, + uint64_t client_id, const GPUDeviceDescriptor* descriptor) - : ContextClient(execution_context), + : ExecutionContextClient(execution_context), DawnObject(dawn_control_client, - dawn_control_client->GetInterface()->GetDefaultDevice()), + dawn_control_client->GetInterface()->GetDevice(client_id)), adapter_(adapter), - queue_(GPUQueue::Create(this, GetProcs().deviceCreateQueue(GetHandle()))), - lost_property_(MakeGarbageCollected<LostProperty>(execution_context, - this, - LostProperty::kLost)), + queue_(MakeGarbageCollected<GPUQueue>( + this, + GetProcs().deviceCreateQueue(GetHandle()))), + lost_property_(MakeGarbageCollected<LostProperty>(execution_context)), error_callback_( BindRepeatingDawnCallback(&GPUDevice::OnUncapturedError, WrapWeakPersistent(this), - WrapWeakPersistent(execution_context))) { + WrapWeakPersistent(execution_context))), + client_id_(client_id) { + DCHECK(dawn_control_client->GetInterface()->GetDevice(client_id)); GetProcs().deviceSetUncapturedErrorCallback( GetHandle(), error_callback_->UnboundRepeatingCallback(), error_callback_->AsUserdata()); @@ -67,7 +61,13 @@ GPUDevice::~GPUDevice() { if (IsDawnControlClientDestroyed()) { return; } + queue_ = nullptr; GetProcs().deviceRelease(GetHandle()); + GetInterface()->RemoveDevice(client_id_); +} + +uint64_t GPUDevice::GetClientID() const { + return client_id_; } void GPUDevice::OnUncapturedError(ExecutionContext* execution_context, @@ -76,22 +76,22 @@ void GPUDevice::OnUncapturedError(ExecutionContext* execution_context, if (execution_context) { DCHECK_NE(errorType, WGPUErrorType_NoError); LOG(ERROR) << "GPUDevice: " << message; - ConsoleMessage* console_message = - ConsoleMessage::Create(mojom::ConsoleMessageSource::kRendering, - mojom::ConsoleMessageLevel::kWarning, message); + auto* console_message = MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kRendering, + mojom::ConsoleMessageLevel::kWarning, message); execution_context->AddConsoleMessage(console_message); } // TODO: Use device lost callback instead of uncaptured error callback. if (errorType == WGPUErrorType_DeviceLost && - lost_property_->GetState() == ScriptPromisePropertyBase::kPending) { - GPUDeviceLostInfo* device_lost_info = GPUDeviceLostInfo::Create(message); + lost_property_->GetState() == LostProperty::kPending) { + auto* device_lost_info = MakeGarbageCollected<GPUDeviceLostInfo>(message); lost_property_->Resolve(device_lost_info); } GPUUncapturedErrorEventInit* init = GPUUncapturedErrorEventInit::Create(); if (errorType == WGPUErrorType_Validation) { - GPUValidationError* error = GPUValidationError::Create(message); + auto* error = MakeGarbageCollected<GPUValidationError>(message); init->setError( GPUOutOfMemoryErrorOrGPUValidationError::FromGPUValidationError(error)); } else if (errorType == WGPUErrorType_OutOfMemory) { @@ -122,59 +122,16 @@ GPUBuffer* GPUDevice::createBuffer(const GPUBufferDescriptor* descriptor) { return GPUBuffer::Create(this, descriptor); } -HeapVector<ScriptValue> GPUDevice::createBufferMapped( - ScriptState* script_state, +HeapVector<GPUBufferOrArrayBuffer> GPUDevice::createBufferMapped( const GPUBufferDescriptor* descriptor, ExceptionState& exception_state) { GPUBuffer* gpu_buffer; DOMArrayBuffer* array_buffer; std::tie(gpu_buffer, array_buffer) = GPUBuffer::CreateMapped(this, descriptor, exception_state); - - v8::Isolate* isolate = script_state->GetIsolate(); - v8::Local<v8::Object> creation_context = script_state->GetContext()->Global(); - - return HeapVector<ScriptValue>({ - ScriptValue(isolate, ToV8(gpu_buffer, creation_context, isolate)), - ScriptValue(isolate, ToV8(array_buffer, creation_context, isolate)), - }); -} - -ScriptPromise GPUDevice::createBufferMappedAsync( - ScriptState* script_state, - const GPUBufferDescriptor* descriptor, - ExceptionState& exception_state) { - GPUBuffer* gpu_buffer; - DOMArrayBuffer* array_buffer; - std::tie(gpu_buffer, array_buffer) = - GPUBuffer::CreateMapped(this, descriptor, exception_state); - - v8::Isolate* isolate = script_state->GetIsolate(); - v8::Local<v8::Object> creation_context = script_state->GetContext()->Global(); - - v8::Local<v8::Value> elements[] = { - ToV8(gpu_buffer, creation_context, isolate), - ToV8(array_buffer, creation_context, isolate), - }; - - ScriptValue result(isolate, v8::Array::New(isolate, elements, 2)); - - auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); - ScriptPromise promise = resolver->Promise(); - // TODO(enga): CreateBufferMappedAsync is intended to spend more time to - // create an optimal mapping for the buffer. It resolves the promise when the - // mapping is complete. Currently, there is always a staging buffer in the - // wire so this is already the optimal path and the promise is immediately - // resolved. When we can create a buffer such that the memory is mapped - // directly in the renderer process, this promise should be resolved - // asynchronously. - - if (exception_state.HadException()) { - resolver->Reject(exception_state); - } else { - resolver->Resolve(result); - } - return promise; + return HeapVector<GPUBufferOrArrayBuffer>( + {GPUBufferOrArrayBuffer::FromGPUBuffer(gpu_buffer), + GPUBufferOrArrayBuffer::FromArrayBuffer(array_buffer)}); } GPUTexture* GPUDevice::createTexture(const GPUTextureDescriptor* descriptor, @@ -202,8 +159,9 @@ GPUPipelineLayout* GPUDevice::createPipelineLayout( } GPUShaderModule* GPUDevice::createShaderModule( - const GPUShaderModuleDescriptor* descriptor) { - return GPUShaderModule::Create(this, descriptor); + const GPUShaderModuleDescriptor* descriptor, + ExceptionState& exception_state) { + return GPUShaderModule::Create(this, descriptor, exception_state); } GPURenderPipeline* GPUDevice::createRenderPipeline( @@ -269,7 +227,7 @@ void GPUDevice::OnPopErrorScopeCallback(ScriptPromiseResolver* resolver, resolver->Resolve(GPUOutOfMemoryError::Create()); break; case WGPUErrorType_Validation: - resolver->Resolve(GPUValidationError::Create(message)); + resolver->Resolve(MakeGarbageCollected<GPUValidationError>(message)); break; case WGPUErrorType_Unknown: case WGPUErrorType_DeviceLost: @@ -282,18 +240,18 @@ void GPUDevice::OnPopErrorScopeCallback(ScriptPromiseResolver* resolver, } ExecutionContext* GPUDevice::GetExecutionContext() const { - return ContextClient::GetExecutionContext(); + return ExecutionContextClient::GetExecutionContext(); } const AtomicString& GPUDevice::InterfaceName() const { return event_target_names::kGPUDevice; } -void GPUDevice::Trace(blink::Visitor* visitor) { +void GPUDevice::Trace(Visitor* visitor) { visitor->Trace(adapter_); visitor->Trace(queue_); visitor->Trace(lost_property_); - ContextClient::Trace(visitor); + ExecutionContextClient::Trace(visitor); EventTargetWithInlineData::Trace(visitor); } |