Bug 1827421 - wgpu api changes. r=webgpu-reviewers,webidl,teoxoy,smaug

Differential Revision: https://phabricator.services.mozilla.com/D175262
This commit is contained in:
Nicolas Silva 2023-04-19 21:53:19 +00:00
Родитель cb9fb9e70d
Коммит 1fe9277420
6 изменённых файлов: 71 добавлений и 31 удалений

Просмотреть файл

@ -25,8 +25,18 @@ void CommandEncoder::ConvertTextureDataLayoutToFFI(
ffi::WGPUImageDataLayout* aLayoutFFI) {
*aLayoutFFI = {};
aLayoutFFI->offset = aLayout.mOffset;
aLayoutFFI->bytes_per_row = aLayout.mBytesPerRow;
aLayoutFFI->rows_per_image = aLayout.mRowsPerImage;
if (aLayout.mBytesPerRow.WasPassed()) {
aLayoutFFI->bytes_per_row = &aLayout.mBytesPerRow.Value();
} else {
aLayoutFFI->bytes_per_row = nullptr;
}
if (aLayout.mRowsPerImage.WasPassed()) {
aLayoutFFI->rows_per_image = &aLayout.mRowsPerImage.Value();
} else {
aLayoutFFI->rows_per_image = nullptr;
}
}
void CommandEncoder::ConvertTextureCopyViewToFFI(
@ -71,14 +81,6 @@ void CommandEncoder::ConvertExtent3DToFFI(const dom::GPUExtent3D& aExtent,
}
}
static ffi::WGPUImageCopyBuffer ConvertBufferCopyView(
const dom::GPUImageCopyBuffer& aCopy) {
ffi::WGPUImageCopyBuffer view = {};
view.buffer = aCopy.mBuffer->mId;
CommandEncoder::ConvertTextureDataLayoutToFFI(aCopy, &view.layout);
return view;
}
static ffi::WGPUImageCopyTexture ConvertTextureCopyView(
const dom::GPUImageCopyTexture& aCopy) {
ffi::WGPUImageCopyTexture view = {};
@ -127,8 +129,10 @@ void CommandEncoder::CopyBufferToTexture(
const dom::GPUExtent3D& aCopySize) {
if (mValid && mBridge->IsOpen()) {
ipc::ByteBuf bb;
ffi::WGPUImageDataLayout src_layout = {};
CommandEncoder::ConvertTextureDataLayoutToFFI(aSource, &src_layout);
ffi::wgpu_command_encoder_copy_buffer_to_texture(
ConvertBufferCopyView(aSource), ConvertTextureCopyView(aDestination),
aSource.mBuffer->mId, &src_layout, ConvertTextureCopyView(aDestination),
ConvertExtent(aCopySize), ToFFI(&bb));
mBridge->SendCommandEncoderAction(mId, mParent->mId, std::move(bb));
@ -144,8 +148,10 @@ void CommandEncoder::CopyTextureToBuffer(
const dom::GPUExtent3D& aCopySize) {
if (mValid && mBridge->IsOpen()) {
ipc::ByteBuf bb;
ffi::WGPUImageDataLayout dstLayout = {};
CommandEncoder::ConvertTextureDataLayoutToFFI(aDestination, &dstLayout);
ffi::wgpu_command_encoder_copy_texture_to_buffer(
ConvertTextureCopyView(aSource), ConvertBufferCopyView(aDestination),
ConvertTextureCopyView(aSource), aDestination.mBuffer->mId, &dstLayout,
ConvertExtent(aCopySize), ToFFI(&bb));
mBridge->SendCommandEncoderAction(mId, mParent->mId, std::move(bb));
}

Просмотреть файл

@ -438,8 +438,10 @@ void Queue::CopyExternalImageToTexture(
aSource.mFlipY ? gl::OriginPos::BottomLeft : gl::OriginPos::TopLeft;
bool wasTrivial;
auto dstStrideVal = dstStride.value();
if (!ConvertImage(dstWidth, dstHeight, srcBegin, srcStride, srcOriginPos,
srcFormat, srcPremultiplied, dstBegin, dstStride.value(),
srcFormat, srcPremultiplied, dstBegin, dstStrideVal,
dstOriginPos, dstFormat, aDestination.mPremultipliedAlpha,
&wasTrivial)) {
MOZ_ASSERT_UNREACHABLE("ConvertImage failed!");
@ -450,7 +452,7 @@ void Queue::CopyExternalImageToTexture(
return;
}
ffi::WGPUImageDataLayout dataLayout = {0, dstStride.value(), dstHeight};
ffi::WGPUImageDataLayout dataLayout = {0, &dstStrideVal, &dstHeight};
ffi::WGPUImageCopyTexture copyView = {};
CommandEncoder::ConvertTextureCopyViewToFFI(aDestination, &copyView);
ipc::ByteBuf bb;

Просмотреть файл

@ -935,8 +935,8 @@ ipc::IPCResult WebGPUParent::RecvSwapChainPresent(
};
const ffi::WGPUImageDataLayout bufLayout = {
0,
data->mSourcePitch,
0,
&data->mSourcePitch,
nullptr,
};
const ffi::WGPUImageCopyBuffer bufView = {
bufferId,

Просмотреть файл

@ -790,8 +790,8 @@ dictionary GPUVertexAttribute {
dictionary GPUImageDataLayout {
GPUSize64 offset = 0;
required GPUSize32 bytesPerRow;
GPUSize32 rowsPerImage = 0;
GPUSize32 bytesPerRow;
GPUSize32 rowsPerImage;
};
dictionary GPUImageCopyBuffer : GPUImageDataLayout {

Просмотреть файл

@ -16,7 +16,7 @@ use parking_lot::Mutex;
use nsstring::nsACString;
use std::{borrow::Cow, num::NonZeroU8, ptr};
use std::{borrow::Cow, ptr};
// we can't call `from_raw_parts` unconditionally because the caller
// may not even have a valid pointer (e.g. NULL) if the `length` is zero.
@ -233,7 +233,7 @@ pub struct SamplerDescriptor<'a> {
lod_min_clamp: f32,
lod_max_clamp: f32,
compare: Option<&'a wgt::CompareFunction>,
anisotropy_clamp: Option<NonZeroU8>,
anisotropy_clamp: Option<&'a u16>,
}
#[repr(C)]
@ -558,7 +558,7 @@ pub extern "C" fn wgpu_client_create_sampler(
lod_min_clamp: desc.lod_min_clamp,
lod_max_clamp: desc.lod_max_clamp,
compare: desc.compare.cloned(),
anisotropy_clamp: desc.anisotropy_clamp,
anisotropy_clamp: *desc.anisotropy_clamp.unwrap_or(&1),
border_color: None,
};
let action = DeviceAction::CreateSampler(id, wgpu_desc);
@ -1029,22 +1029,38 @@ pub unsafe extern "C" fn wgpu_command_encoder_copy_buffer_to_buffer(
#[no_mangle]
pub unsafe extern "C" fn wgpu_command_encoder_copy_texture_to_buffer(
src: wgc::command::ImageCopyTexture,
dst: wgc::command::ImageCopyBuffer,
dst_buffer: wgc::id::BufferId,
dst_layout: &ImageDataLayout,
size: wgt::Extent3d,
bb: &mut ByteBuf,
) {
let action = CommandEncoderAction::CopyTextureToBuffer { src, dst, size };
let action = CommandEncoderAction::CopyTextureToBuffer {
src,
dst: wgc::command::ImageCopyBuffer {
buffer: dst_buffer,
layout: dst_layout.into_wgt(),
},
size,
};
*bb = make_byte_buf(&action);
}
#[no_mangle]
pub unsafe extern "C" fn wgpu_command_encoder_copy_buffer_to_texture(
src: wgc::command::ImageCopyBuffer,
src_buffer: wgc::id::BufferId,
src_layout: &ImageDataLayout,
dst: wgc::command::ImageCopyTexture,
size: wgt::Extent3d,
bb: &mut ByteBuf,
) {
let action = CommandEncoderAction::CopyBufferToTexture { src, dst, size };
let action = CommandEncoderAction::CopyBufferToTexture {
src: wgc::command::ImageCopyBuffer {
buffer: src_buffer,
layout: src_layout.into_wgt(),
},
dst,
size,
};
*bb = make_byte_buf(&action);
}
@ -1092,13 +1108,33 @@ pub unsafe extern "C" fn wgpu_queue_write_buffer(
*bb = make_byte_buf(&action);
}
#[repr(C)]
pub struct ImageDataLayout<'a> {
pub offset: wgt::BufferAddress,
pub bytes_per_row: Option<&'a u32>,
pub rows_per_image: Option<&'a u32>,
}
impl<'a> ImageDataLayout<'a> {
fn into_wgt(&self) -> wgt::ImageDataLayout {
wgt::ImageDataLayout {
offset: self.offset,
bytes_per_row: self.bytes_per_row.map(|bpr| *bpr),
rows_per_image: self.rows_per_image.map(|rpi| *rpi),
}
}
}
#[no_mangle]
pub unsafe extern "C" fn wgpu_queue_write_texture(
dst: wgt::ImageCopyTexture<id::TextureId>,
layout: wgt::ImageDataLayout,
layout: ImageDataLayout,
size: wgt::Extent3d,
bb: &mut ByteBuf,
) {
let layout = layout.into_wgt();
let action = QueueWriteAction::Texture { dst, layout, size };
*bb = make_byte_buf(&action);
}

Просмотреть файл

@ -328,11 +328,7 @@ pub extern "C" fn wgpu_server_device_create_buffer(
) {
let utf8_label = label.map(|utf16| utf16.to_string());
let label = utf8_label.as_ref().map(|s| Cow::from(&s[..]));
// This is actually not unsafe, the bitflags crate never ended up relying on the bit
// patterns for safety, and the next version will replace this method with an equivalent
// that isn't marked unsafe.
let usage = unsafe { wgt::BufferUsages::from_bits_unchecked(usage) };
let usage = wgt::BufferUsages::from_bits_retain(usage);
// Don't trust the graphics driver with buffer sizes larger than our conservative max texture size.
if size > MAX_BUFFER_SIZE {