1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

fix(webgpu): Fix GPUAdapter#isFallbackAdapter and GPUAdapter#info properties (#24914)

Fixed `GPUAdapter` bugs:

* `GPUAdapter#isFallbackAdapter` being `undefined`
* `GPUAdapter#info` throwing `TypeError`
  * introduced by #24783
* `GPUAdapter#info` closing adapter resources
  * introduced by #23752
This commit is contained in:
Kenta Moriuchi 2024-08-07 18:17:33 +09:00 committed by GitHub
parent fe64cbd88b
commit fade3136ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 19 deletions

View file

@ -137,6 +137,8 @@ const _mappingRange = Symbol("[[mapping_range]]");
const _mappedRanges = Symbol("[[mapped_ranges]]"); const _mappedRanges = Symbol("[[mapped_ranges]]");
const _mapMode = Symbol("[[map_mode]]"); const _mapMode = Symbol("[[map_mode]]");
const _adapter = Symbol("[[adapter]]"); const _adapter = Symbol("[[adapter]]");
const _adapterInfo = Symbol("[[adapterInfo]]");
const _invalid = Symbol("[[invalid]]");
const _cleanup = Symbol("[[cleanup]]"); const _cleanup = Symbol("[[cleanup]]");
const _vendor = Symbol("[[vendor]]"); const _vendor = Symbol("[[vendor]]");
const _architecture = Symbol("[[architecture]]"); const _architecture = Symbol("[[architecture]]");
@ -414,17 +416,18 @@ function createGPUAdapter(inner) {
features: createGPUSupportedFeatures(inner.features), features: createGPUSupportedFeatures(inner.features),
limits: createGPUSupportedLimits(inner.limits), limits: createGPUSupportedLimits(inner.limits),
}; };
adapter[_adapterInfo] = undefined;
adapter[_invalid] = false;
return adapter; return adapter;
} }
const _invalid = Symbol("[[invalid]]");
class GPUAdapter { class GPUAdapter {
/** @type {InnerGPUAdapter} */ /** @type {InnerGPUAdapter} */
[_adapter]; [_adapter];
/** @type {bool} */
[_invalid];
/** @type {GPUAdapterInfo | undefined} */ /** @type {GPUAdapterInfo | undefined} */
#adapterInfo; [_adapterInfo];
/** @type {boolean} */
[_invalid];
/** @returns {GPUSupportedFeatures} */ /** @returns {GPUSupportedFeatures} */
get features() { get features() {
@ -439,7 +442,7 @@ class GPUAdapter {
/** @returns {boolean} */ /** @returns {boolean} */
get isFallbackAdapter() { get isFallbackAdapter() {
webidl.assertBranded(this, GPUAdapterPrototype); webidl.assertBranded(this, GPUAdapterPrototype);
return this[_adapter].isFallbackAdapter; return this[_adapter].isFallback;
} }
constructor() { constructor() {
@ -509,16 +512,16 @@ class GPUAdapter {
get info() { get info() {
webidl.assertBranded(this, GPUAdapterPrototype); webidl.assertBranded(this, GPUAdapterPrototype);
if (this[_adapterInfo] !== undefined) {
return this[_adapterInfo];
}
if (this[_invalid]) { if (this[_invalid]) {
throw new TypeError( throw new TypeError(
"The adapter cannot be reused, as it has been invalidated by a device creation", "The adapter cannot be reused, as it has been invalidated by a device creation",
); );
} }
if (this.#adapterInfo !== undefined) {
return this.#adapterInfo;
}
const { const {
vendor, vendor,
architecture, architecture,
@ -531,7 +534,7 @@ class GPUAdapter {
adapterInfo[_architecture] = architecture; adapterInfo[_architecture] = architecture;
adapterInfo[_device] = device; adapterInfo[_device] = device;
adapterInfo[_description] = description; adapterInfo[_description] = description;
this.#adapterInfo = adapterInfo; this[_adapterInfo] = adapterInfo;
return adapterInfo; return adapterInfo;
} }
@ -543,6 +546,7 @@ class GPUAdapter {
keys: [ keys: [
"features", "features",
"limits", "limits",
"info",
"isFallbackAdapter", "isFallbackAdapter",
], ],
}), }),
@ -937,7 +941,6 @@ function GPUObjectBaseMixin(name, type) {
* @property {number | undefined} rid * @property {number | undefined} rid
* @property {GPUSupportedFeatures} features * @property {GPUSupportedFeatures} features
* @property {GPUSupportedLimits} limits * @property {GPUSupportedLimits} limits
* @property {GPUDevice} device
*/ */
class InnerGPUDevice { class InnerGPUDevice {

View file

@ -382,7 +382,7 @@ pub struct GpuAdapterRes {
rid: ResourceId, rid: ResourceId,
limits: wgpu_types::Limits, limits: wgpu_types::Limits,
features: Vec<&'static str>, features: Vec<&'static str>,
is_software: bool, is_fallback: bool,
} }
#[derive(Serialize)] #[derive(Serialize)]
@ -392,7 +392,6 @@ pub struct GpuDeviceRes {
queue_rid: ResourceId, queue_rid: ResourceId,
limits: wgpu_types::Limits, limits: wgpu_types::Limits,
features: Vec<&'static str>, features: Vec<&'static str>,
is_software: bool,
} }
#[op2] #[op2]
@ -462,7 +461,8 @@ pub fn op_webgpu_request_adapter(
rid, rid,
features, features,
limits: adapter_limits, limits: adapter_limits,
is_software: false, // TODO(lucacasonato): report correctly from wgpu
is_fallback: false,
})) }))
} }
@ -712,8 +712,6 @@ pub fn op_webgpu_request_device(
queue_rid, queue_rid,
features, features,
limits, limits,
// TODO(lucacasonato): report correctly from wgpu
is_software: false,
}) })
} }
@ -732,14 +730,13 @@ pub fn op_webgpu_request_adapter_info(
state: Rc<RefCell<OpState>>, state: Rc<RefCell<OpState>>,
#[smi] adapter_rid: ResourceId, #[smi] adapter_rid: ResourceId,
) -> Result<GPUAdapterInfo, AnyError> { ) -> Result<GPUAdapterInfo, AnyError> {
let mut state = state.borrow_mut(); let state = state.borrow_mut();
let adapter_resource = let adapter_resource =
state.resource_table.take::<WebGpuAdapter>(adapter_rid)?; state.resource_table.get::<WebGpuAdapter>(adapter_rid)?;
let adapter = adapter_resource.1; let adapter = adapter_resource.1;
let instance = state.borrow::<Instance>(); let instance = state.borrow::<Instance>();
let info = gfx_select!(adapter => instance.adapter_get_info(adapter))?; let info = gfx_select!(adapter => instance.adapter_get_info(adapter))?;
adapter_resource.close();
Ok(GPUAdapterInfo { Ok(GPUAdapterInfo {
vendor: info.vendor.to_string(), vendor: info.vendor.to_string(),