Skip to content

Commit

Permalink
Adding GPUQueue.writeTexture in WebGPU.
Browse files Browse the repository at this point in the history
Added a writeTexture function.

Bug: dawn:483
Change-Id: I2276553daa0c8c1491c7aebfcc63b068bdc0e93b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303394
Commit-Queue: Tomek Ponitka <tommek@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791219}
  • Loading branch information
ponitka authored and Commit Bot committed Jul 23, 2020
1 parent 6f3f496 commit fdeadea
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 8 deletions.
12 changes: 12 additions & 0 deletions third_party/blink/renderer/modules/webgpu/dawn_conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "third_party/blink/renderer/bindings/modules/v8/unsigned_long_enforce_range_sequence_or_gpu_origin_3d_dict.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_gpu_programmable_stage_descriptor.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_gpu_texture_copy_view.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_gpu_texture_data_layout.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_device.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_shader_module.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_texture.h"
Expand Down Expand Up @@ -773,6 +774,17 @@ WGPUTextureCopyView AsDawnType(const GPUTextureCopyView* webgpu_view,
return dawn_view;
}

WGPUTextureDataLayout AsDawnType(const GPUTextureDataLayout* webgpu_layout) {
DCHECK(webgpu_layout);

WGPUTextureDataLayout dawn_layout = {};
dawn_layout.offset = webgpu_layout->offset();
dawn_layout.bytesPerRow = webgpu_layout->bytesPerRow();
dawn_layout.rowsPerImage = webgpu_layout->rowsPerImage();

return dawn_layout;
}

OwnedProgrammableStageDescriptor AsDawnType(
const GPUProgrammableStageDescriptor* webgpu_stage) {
DCHECK(webgpu_stage);
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/renderer/modules/webgpu/dawn_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DoubleSequenceOrGPUColorDict;
class GPUColorDict;
class GPUProgrammableStageDescriptor;
class GPUTextureCopyView;
class GPUTextureDataLayout;
class UnsignedLongEnforceRangeSequenceOrGPUExtent3DDict;
class UnsignedLongEnforceRangeSequenceOrGPUOrigin3DDict;

Expand All @@ -48,6 +49,7 @@ WGPUOrigin3D AsDawnType(
const UnsignedLongEnforceRangeSequenceOrGPUOrigin3DDict*);
WGPUTextureCopyView AsDawnType(const GPUTextureCopyView* webgpu_view,
GPUDevice* device);
WGPUTextureDataLayout AsDawnType(const GPUTextureDataLayout* webgpu_layout);
using OwnedProgrammableStageDescriptor =
std::tuple<WGPUProgrammableStageDescriptor, std::unique_ptr<char[]>>;
OwnedProgrammableStageDescriptor AsDawnType(
Expand Down
43 changes: 43 additions & 0 deletions third_party/blink/renderer/modules/webgpu/gpu_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,49 @@ void GPUQueue::WriteBufferImpl(GPUBuffer* buffer,
data_ptr, static_cast<size_t>(write_byte_size));
}

void GPUQueue::writeTexture(
GPUTextureCopyView* destination,
const MaybeShared<DOMArrayBufferView>& data,
GPUTextureDataLayout* data_layout,
UnsignedLongEnforceRangeSequenceOrGPUExtent3DDict& write_size,
ExceptionState& exception_state) {
WriteTextureImpl(destination, data->BaseAddressMaybeShared(),
data->byteLengthAsSizeT(), data_layout, write_size,
exception_state);
}

void GPUQueue::writeTexture(
GPUTextureCopyView* destination,
const DOMArrayBufferBase* data,
GPUTextureDataLayout* data_layout,
UnsignedLongEnforceRangeSequenceOrGPUExtent3DDict& write_size,
ExceptionState& exception_state) {
WriteTextureImpl(destination, data->DataMaybeShared(),
data->ByteLengthAsSizeT(), data_layout, write_size,
exception_state);
}

void GPUQueue::WriteTextureImpl(
GPUTextureCopyView* destination,
const void* data,
size_t data_size,
GPUTextureDataLayout* data_layout,
UnsignedLongEnforceRangeSequenceOrGPUExtent3DDict& write_size,
ExceptionState& exception_state) {
if (!ValidateCopySize(write_size, exception_state) ||
!ValidateTextureCopyView(destination, exception_state)) {
return;
}

WGPUTextureCopyView dawn_destination = AsDawnType(destination, device_);
WGPUTextureDataLayout dawn_data_layout = AsDawnType(data_layout);
WGPUExtent3D dawn_write_size = AsDawnType(&write_size);

GetProcs().queueWriteTexture(GetHandle(), &dawn_destination, data, data_size,
&dawn_data_layout, &dawn_write_size);
return;
}

// TODO(shaobo.yan@intel.com): Implement this function
void GPUQueue::copyImageBitmapToTexture(
GPUImageBitmapCopyView* source,
Expand Down
36 changes: 28 additions & 8 deletions third_party/blink/renderer/modules/webgpu/gpu_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GPUFence;
class GPUFenceDescriptor;
class GPUImageBitmapCopyView;
class GPUTextureCopyView;
class GPUTextureDataLayout;
class StaticBitmapImage;
class UnsignedLongEnforceRangeSequenceOrGPUExtent3DDict;

Expand Down Expand Up @@ -56,14 +57,18 @@ class GPUQueue : public DawnObject<WGPUQueue> {
uint64_t data_byte_offset,
uint64_t byte_size,
ExceptionState& exception_state);
void WriteBufferImpl(GPUBuffer* buffer,
uint64_t buffer_offset,
uint64_t data_byte_length,
const void* data_base_ptr,
unsigned data_bytes_per_element,
uint64_t data_byte_offset,
base::Optional<uint64_t> byte_size,
ExceptionState& exception_state);
void writeTexture(
GPUTextureCopyView* destination,
const MaybeShared<DOMArrayBufferView>& data,
GPUTextureDataLayout* data_layout,
UnsignedLongEnforceRangeSequenceOrGPUExtent3DDict& write_size,
ExceptionState& exception_state);
void writeTexture(
GPUTextureCopyView* destination,
const DOMArrayBufferBase* data,
GPUTextureDataLayout* data_layout,
UnsignedLongEnforceRangeSequenceOrGPUExtent3DDict& write_size,
ExceptionState& exception_state);
void copyImageBitmapToTexture(
GPUImageBitmapCopyView* source,
GPUTextureCopyView* destination,
Expand All @@ -81,6 +86,21 @@ class GPUQueue : public DawnObject<WGPUQueue> {
const WGPUOrigin3D& origin,
const WGPUExtent3D& copy_size,
const WGPUTextureCopyView& destination);
void WriteBufferImpl(GPUBuffer* buffer,
uint64_t buffer_offset,
uint64_t data_byte_length,
const void* data_base_ptr,
unsigned data_bytes_per_element,
uint64_t data_byte_offset,
base::Optional<uint64_t> byte_size,
ExceptionState& exception_state);
void WriteTextureImpl(
GPUTextureCopyView* destination,
const void* data,
size_t dataSize,
GPUTextureDataLayout* data_layout,
UnsignedLongEnforceRangeSequenceOrGPUExtent3DDict& write_size,
ExceptionState& exception_state);

scoped_refptr<DawnTextureFromImageBitmap> produce_dawn_texture_handler_;

Expand Down
11 changes: 11 additions & 0 deletions third_party/blink/renderer/modules/webgpu/gpu_queue.idl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
optional GPUSize64 dataByteOffset = 0,
optional GPUSize64 byteSize);

[RaisesException] void writeTexture(
GPUTextureCopyView destination,
[AllowShared] ArrayBufferView data,
GPUTextureDataLayout dataLayout,
GPUExtent3D size);
[RaisesException] void writeTexture(
GPUTextureCopyView destination,
ArrayBuffer data,
GPUTextureDataLayout dataLayout,
GPUExtent3D size);

[RaisesException] void copyImageBitmapToTexture(
GPUImageBitmapCopyView source,
GPUTextureCopyView destination,
Expand Down

0 comments on commit fdeadea

Please sign in to comment.