Bug 1730014 - Avoid ASCII intermediate for WGSL shader code r=jgilbert,webidl,emilio

we were doing UTF16 -> ASCII null term -> UTF8, and we were losing information on the way.
Now we go UTF16 -> UTF8 -> UTF8 null term
Also, we no longer accept SPIR-V

Differential Revision: https://phabricator.services.mozilla.com/D125123
This commit is contained in:
Dzmitry Malyshau 2021-09-10 17:19:41 +00:00
Родитель 8d7ad39477
Коммит 56f4d4bdc1
4 изменённых файлов: 10 добавлений и 18 удалений

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

@ -11,6 +11,7 @@
#include "mozilla/HoldDropJSObjects.h"
#include "mozilla/ipc/Shmem.h"
#include "ipc/WebGPUChild.h"
#include "js/ArrayBuffer.h"
#include "js/RootingAPI.h"
#include "nsContentUtils.h"
#include "nsWrapperCache.h"

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

@ -603,16 +603,8 @@ RawId WebGPUChild::DeviceCreateShaderModule(
RawId aSelfId, const dom::GPUShaderModuleDescriptor& aDesc) {
ffi::WGPUShaderModuleDescriptor desc = {};
nsCString wgsl;
if (aDesc.mCode.IsUSVString()) {
LossyCopyUTF16toASCII(aDesc.mCode.GetAsUSVString(), wgsl);
desc.wgsl_chars = wgsl.get();
} else {
const auto& code = aDesc.mCode.GetAsUint32Array();
code.ComputeState();
desc.spirv_words = code.Data();
desc.spirv_words_length = code.Length();
}
desc.code = reinterpret_cast<const uint8_t*>(aDesc.mCode.get());
desc.code_length = aDesc.mCode.Length();
ByteBuf bb;
RawId id = ffi::wgpu_client_create_shader_module(mClient, aSelfId, &desc,

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

@ -612,11 +612,10 @@ interface GPUCompilationInfo {
};
// ShaderModule
//TODO: remove the `Uint32Array` variant, it's used for SPIR-V
typedef (Uint32Array or USVString) GPUShaderCode;
dictionary GPUShaderModuleDescriptor : GPUObjectDescriptorBase {
required GPUShaderCode code;
// UTF8String is not observably different from USVString
required UTF8String code;
object sourceMap;
};

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

@ -38,9 +38,8 @@ fn make_byte_buf<T: serde::Serialize>(data: &T) -> ByteBuf {
#[repr(C)]
pub struct ShaderModuleDescriptor {
label: RawString,
spirv_words: *const u32,
spirv_words_length: usize,
wgsl_chars: RawString,
code: *const u8,
code_length: usize,
}
#[repr(C)]
@ -913,12 +912,13 @@ pub unsafe extern "C" fn wgpu_client_create_shader_module(
.shader_modules
.alloc(backend);
let code = cow_label(&desc.wgsl_chars).unwrap_or_default();
let code =
std::str::from_utf8_unchecked(std::slice::from_raw_parts(desc.code, desc.code_length));
let desc = wgc::pipeline::ShaderModuleDescriptor {
label: cow_label(&desc.label),
};
let action = DeviceAction::CreateShaderModule(id, desc, code);
let action = DeviceAction::CreateShaderModule(id, desc, Cow::Borrowed(code));
*bb = make_byte_buf(&action);
id
}