Bug 1917513 - Add a way to expose if webgpu::Adapter and webgpu::Device support ExternalTexture usage in SwapChain r=webgpu-reviewers,nical

This is a preparation for Bug 1708022 and Bug 1917512.

Current webgpu::Adapter and webgpu::Device do not expose if they support ExternalTexture usage in SwapChain. Then  CanvasContext could not dynamically detect if the Device supports ExternalTexture usage in SwapChain.

The change add a capability to check it.

Differential Revision: https://phabricator.services.mozilla.com/D221423
This commit is contained in:
sotaro 2024-09-09 12:56:07 +00:00
Родитель 6de509c8ab
Коммит 630f1e6556
8 изменённых файлов: 25 добавлений и 10 удалений

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

@ -217,6 +217,10 @@ bool Adapter::IsFallbackAdapter() const {
return mInfo->device_type == ffi::WGPUDeviceType::WGPUDeviceType_Cpu;
}
bool Adapter::SupportExternalTextureInSwapChain() const {
return mInfo->support_use_external_texture_in_swap_chain;
}
static std::string_view ToJsKey(const Limit limit) {
switch (limit) {
case Limit::MaxTextureDimension1D:

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

@ -96,6 +96,7 @@ class Adapter final : public ObjectBase, public ChildOf<Instance> {
const RefPtr<SupportedFeatures>& Features() const;
const RefPtr<SupportedLimits>& Limits() const;
bool IsFallbackAdapter() const;
bool SupportExternalTextureInSwapChain() const;
nsCString LabelOrId() const {
nsCString ret = this->CLabel();

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

@ -124,8 +124,9 @@ void CanvasContext::Configure(const dom::GPUCanvasConfiguration& aConfig) {
mConfig.reset(new dom::GPUCanvasConfiguration(aConfig));
mRemoteTextureOwnerId = Some(layers::RemoteTextureOwnerId::GetNext());
mUseExternalTextureInSwapChain =
aConfig.mDevice->mSupportExternalTextureInSwapChain &&
wgpu_client_use_external_texture_in_swapChain(
aConfig.mDevice->mId, ConvertTextureFormat(aConfig.mFormat));
ConvertTextureFormat(aConfig.mFormat));
if (!gfx::gfxVars::AllowWebGPUPresentWithoutReadback()) {
mUseExternalTextureInSwapChain = false;
}

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

@ -63,6 +63,8 @@ Device::Device(Adapter* const aParent, RawId aDeviceId, RawId aQueueId,
// features are filled in Adapter::RequestDevice
mFeatures(new SupportedFeatures(aParent)),
mLimits(new SupportedLimits(aParent, aRawLimits)),
mSupportExternalTextureInSwapChain(
aParent->SupportExternalTextureInSwapChain()),
mBridge(aParent->mBridge),
mQueue(new class Queue(this, aParent->mBridge, aQueueId)) {
mBridge->RegisterDevice(this);

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

@ -89,6 +89,7 @@ class Device final : public DOMEventTargetHelper, public SupportsWeakPtr {
const RawId mId;
RefPtr<SupportedFeatures> mFeatures;
RefPtr<SupportedLimits> mLimits;
const bool mSupportExternalTextureInSwapChain;
static CheckedInt<uint32_t> BufferStrideWithMask(
const gfx::IntSize& aSize, const gfx::SurfaceFormat& aFormat);

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

@ -489,6 +489,7 @@ pub extern "C" fn wgpu_client_adapter_extract_info(
limits,
name,
vendor,
support_use_external_texture_in_swap_chain,
} = bincode::deserialize::<AdapterInformation<String>>(unsafe { byte_buf.as_slice() }).unwrap();
let nss = |s: &str| {
@ -507,6 +508,7 @@ pub extern "C" fn wgpu_client_adapter_extract_info(
limits,
name: nss(&name),
vendor,
support_use_external_texture_in_swap_chain,
};
}
@ -1495,13 +1497,8 @@ pub extern "C" fn wgpu_texture_format_block_size_single_aspect(format: wgt::Text
#[no_mangle]
pub extern "C" fn wgpu_client_use_external_texture_in_swapChain(
device_id: id::DeviceId,
format: wgt::TextureFormat,
) -> bool {
if device_id.backend() != wgt::Backend::Dx12 {
return false;
}
let supported = match format {
wgt::TextureFormat::Bgra8Unorm => true,
_ => false,

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

@ -104,6 +104,7 @@ pub struct AdapterInformation<S> {
driver: S,
driver_info: S,
backend: wgt::Backend,
support_use_external_texture_in_swap_chain: bool,
}
#[derive(serde::Serialize, serde::Deserialize)]

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

@ -241,11 +241,12 @@ pub unsafe extern "C" fn wgpu_server_adapter_pack_info(
backend,
} = global.adapter_get_info(id).unwrap();
let is_hardware = match device_type {
wgt::DeviceType::IntegratedGpu | wgt::DeviceType::DiscreteGpu => true,
_ => false,
};
if static_prefs::pref!("dom.webgpu.testing.assert-hardware-adapter") {
let is_hardware = match device_type {
wgt::DeviceType::IntegratedGpu | wgt::DeviceType::DiscreteGpu => true,
_ => false,
};
assert!(
is_hardware,
"Expected a hardware gpu adapter, got {:?}",
@ -253,6 +254,12 @@ pub unsafe extern "C" fn wgpu_server_adapter_pack_info(
);
}
let support_use_external_texture_in_swap_chain = if cfg!(target_os = "windows") {
id.backend() == wgt::Backend::Dx12 && is_hardware
} else {
false
};
let info = AdapterInformation {
id,
limits: restrict_limits(global.adapter_limits(id).unwrap()),
@ -264,6 +271,7 @@ pub unsafe extern "C" fn wgpu_server_adapter_pack_info(
driver,
driver_info,
backend,
support_use_external_texture_in_swap_chain,
};
bincode::serialize_into(&mut data, &info).unwrap();
}