mirror of
https://github.com/denoland/deno.git
synced 2025-01-20 20:42:19 -05:00
move object wrap back to ext root
This commit is contained in:
parent
c26512f72b
commit
eb21c7682a
22 changed files with 191 additions and 197 deletions
|
@ -12,8 +12,8 @@ use deno_core::WebIDL;
|
|||
use tokio::sync::Mutex;
|
||||
|
||||
use super::device::GPUDevice;
|
||||
use crate::wrap::webidl::features_to_feature_names;
|
||||
use crate::wrap::webidl::GPUFeatureName;
|
||||
use crate::webidl::features_to_feature_names;
|
||||
use crate::webidl::GPUFeatureName;
|
||||
use crate::Instance;
|
||||
|
||||
#[derive(WebIDL)]
|
|
@ -14,9 +14,9 @@ use deno_core::webidl::WebIdlInterfaceConverter;
|
|||
use deno_core::GarbageCollected;
|
||||
use deno_core::WebIDL;
|
||||
|
||||
use crate::wrap::buffer::GPUBuffer;
|
||||
use crate::wrap::sampler::GPUSampler;
|
||||
use crate::wrap::texture::GPUTextureView;
|
||||
use crate::buffer::GPUBuffer;
|
||||
use crate::sampler::GPUSampler;
|
||||
use crate::texture::GPUTextureView;
|
||||
use crate::Instance;
|
||||
|
||||
pub struct GPUBindGroup {
|
|
@ -4,7 +4,7 @@ use deno_core::op2;
|
|||
use deno_core::GarbageCollected;
|
||||
use deno_core::WebIDL;
|
||||
|
||||
use crate::wrap::texture::GPUTextureViewDimension;
|
||||
use crate::texture::GPUTextureViewDimension;
|
||||
use crate::Instance;
|
||||
|
||||
pub struct GPUBindGroupLayout {
|
|
@ -11,14 +11,14 @@ use deno_error::JsErrorBox;
|
|||
use wgpu_core::command::ImageCopyBuffer;
|
||||
use wgpu_core::command::PassChannel;
|
||||
|
||||
use crate::wrap::buffer::GPUBuffer;
|
||||
use crate::wrap::command_buffer::GPUCommandBuffer;
|
||||
use crate::wrap::compute_pass::GPUComputePassEncoder;
|
||||
use crate::wrap::queue::GPUTexelCopyTextureInfo;
|
||||
use crate::wrap::render_pass::GPULoadOp;
|
||||
use crate::wrap::render_pass::GPURenderPassEncoder;
|
||||
use crate::wrap::render_pass::GPUStoreOp;
|
||||
use crate::wrap::webidl::GPUExtent3D;
|
||||
use crate::buffer::GPUBuffer;
|
||||
use crate::command_buffer::GPUCommandBuffer;
|
||||
use crate::compute_pass::GPUComputePassEncoder;
|
||||
use crate::queue::GPUTexelCopyTextureInfo;
|
||||
use crate::render_pass::GPULoadOp;
|
||||
use crate::render_pass::GPURenderPassEncoder;
|
||||
use crate::render_pass::GPUStoreOp;
|
||||
use crate::webidl::GPUExtent3D;
|
||||
use crate::Instance;
|
||||
|
||||
pub struct GPUCommandEncoder {
|
||||
|
@ -54,7 +54,7 @@ impl GPUCommandEncoder {
|
|||
#[cppgc]
|
||||
fn begin_render_pass(
|
||||
&self,
|
||||
#[webidl] descriptor: crate::wrap::render_pass::GPURenderPassDescriptor,
|
||||
#[webidl] descriptor: crate::render_pass::GPURenderPassDescriptor,
|
||||
) -> Result<GPURenderPassEncoder, JsErrorBox> {
|
||||
let color_attachments = Cow::Owned(
|
||||
descriptor
|
||||
|
@ -149,7 +149,7 @@ impl GPUCommandEncoder {
|
|||
#[cppgc]
|
||||
fn begin_compute_pass(
|
||||
&self,
|
||||
#[webidl] descriptor: crate::wrap::compute_pass::GPUComputePassDescriptor,
|
||||
#[webidl] descriptor: crate::compute_pass::GPUComputePassDescriptor,
|
||||
) -> GPUComputePassEncoder {
|
||||
let timestamp_writes =
|
||||
descriptor.timestamp_writes.map(|timestamp_writes| {
|
||||
|
@ -348,8 +348,7 @@ impl GPUCommandEncoder {
|
|||
#[cppgc]
|
||||
fn finish(
|
||||
&self,
|
||||
#[webidl]
|
||||
descriptor: crate::wrap::command_buffer::GPUCommandBufferDescriptor,
|
||||
#[webidl] descriptor: crate::command_buffer::GPUCommandBufferDescriptor,
|
||||
) -> GPUCommandBuffer {
|
||||
let wgpu_descriptor = wgpu_types::CommandBufferDescriptor {
|
||||
label: Some(Cow::Owned(descriptor.label.clone())),
|
|
@ -40,7 +40,7 @@ impl GPUComputePassEncoder {
|
|||
|
||||
fn set_pipeline(
|
||||
&self,
|
||||
#[webidl] pipeline: Ptr<crate::wrap::compute_pipeline::GPUComputePipeline>,
|
||||
#[webidl] pipeline: Ptr<crate::compute_pipeline::GPUComputePipeline>,
|
||||
) {
|
||||
let err = self
|
||||
.instance
|
||||
|
@ -74,7 +74,7 @@ impl GPUComputePassEncoder {
|
|||
|
||||
fn dispatch_workgroups_indirect(
|
||||
&self,
|
||||
#[webidl] indirect_buffer: Ptr<crate::wrap::buffer::GPUBuffer>,
|
||||
#[webidl] indirect_buffer: Ptr<crate::buffer::GPUBuffer>,
|
||||
#[webidl(options(enforce_range = true))] indirect_offset: u64,
|
||||
) {
|
||||
let err = self
|
||||
|
@ -134,7 +134,7 @@ impl GPUComputePassEncoder {
|
|||
&self,
|
||||
scope: &mut v8::HandleScope<'a>,
|
||||
#[webidl(options(enforce_range = true))] index: u32,
|
||||
#[webidl] bind_group: Nullable<Ptr<crate::wrap::bind_group::GPUBindGroup>>,
|
||||
#[webidl] bind_group: Nullable<Ptr<crate::bind_group::GPUBindGroup>>,
|
||||
dynamic_offsets: v8::Local<'a, v8::Value>,
|
||||
dynamic_offsets_data_start: v8::Local<'a, v8::Value>,
|
||||
dynamic_offsets_data_length: v8::Local<'a, v8::Value>,
|
||||
|
@ -225,7 +225,7 @@ pub(crate) struct GPUComputePassDescriptor {
|
|||
#[derive(WebIDL)]
|
||||
#[webidl(dictionary)]
|
||||
pub(crate) struct GPUComputePassTimestampWrites {
|
||||
pub query_set: Ptr<crate::wrap::query_set::GPUQuerySet>,
|
||||
pub query_set: Ptr<crate::query_set::GPUQuerySet>,
|
||||
#[options(enforce_range = true)]
|
||||
pub beginning_of_pass_write_index: Option<u32>,
|
||||
#[options(enforce_range = true)]
|
|
@ -7,9 +7,9 @@ use deno_core::GarbageCollected;
|
|||
use deno_core::WebIDL;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use crate::wrap::bind_group_layout::GPUBindGroupLayout;
|
||||
use crate::wrap::shader::GPUShaderModule;
|
||||
use crate::wrap::webidl::GPUPipelineLayoutOrGPUAutoLayoutMode;
|
||||
use crate::bind_group_layout::GPUBindGroupLayout;
|
||||
use crate::shader::GPUShaderModule;
|
||||
use crate::webidl::GPUPipelineLayoutOrGPUAutoLayoutMode;
|
||||
use crate::Instance;
|
||||
|
||||
pub struct GPUComputePipeline {
|
|
@ -22,14 +22,14 @@ use super::queue::GPUQueue;
|
|||
use super::sampler::GPUSampler;
|
||||
use super::shader::GPUShaderModule;
|
||||
use super::texture::GPUTexture;
|
||||
use crate::wrap::adapter::GPUAdapterInfo;
|
||||
use crate::wrap::adapter::GPUSupportedFeatures;
|
||||
use crate::wrap::adapter::GPUSupportedLimits;
|
||||
use crate::wrap::command_encoder::GPUCommandEncoder;
|
||||
use crate::wrap::query_set::GPUQuerySet;
|
||||
use crate::wrap::render_bundle::GPURenderBundleEncoder;
|
||||
use crate::wrap::render_pipeline::GPURenderPipeline;
|
||||
use crate::wrap::webidl::features_to_feature_names;
|
||||
use crate::adapter::GPUAdapterInfo;
|
||||
use crate::adapter::GPUSupportedFeatures;
|
||||
use crate::adapter::GPUSupportedLimits;
|
||||
use crate::command_encoder::GPUCommandEncoder;
|
||||
use crate::query_set::GPUQuerySet;
|
||||
use crate::render_bundle::GPURenderBundleEncoder;
|
||||
use crate::render_pipeline::GPURenderPipeline;
|
||||
use crate::webidl::features_to_feature_names;
|
||||
use crate::Instance;
|
||||
|
||||
pub struct GPUDevice {
|
||||
|
@ -554,7 +554,7 @@ impl GPUDevice {
|
|||
#[cppgc]
|
||||
fn create_query_set(
|
||||
&self,
|
||||
#[webidl] descriptor: crate::wrap::query_set::GPUQuerySetDescriptor,
|
||||
#[webidl] descriptor: crate::query_set::GPUQuerySetDescriptor,
|
||||
) -> GPUQuerySet {
|
||||
let wgpu_descriptor = wgpu_core::resource::QuerySetDescriptor {
|
||||
label: Some(Cow::Owned(descriptor.label.clone())),
|
|
@ -2,48 +2,152 @@
|
|||
#![cfg(not(target_arch = "wasm32"))]
|
||||
#![warn(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use deno_core::cppgc::SameObject;
|
||||
use deno_core::op2;
|
||||
use deno_core::GarbageCollected;
|
||||
use deno_core::OpState;
|
||||
pub use wgpu_core;
|
||||
pub use wgpu_types;
|
||||
use wgpu_types::PowerPreference;
|
||||
|
||||
mod adapter;
|
||||
mod bind_group;
|
||||
mod bind_group_layout;
|
||||
mod buffer;
|
||||
mod command_buffer;
|
||||
mod command_encoder;
|
||||
mod compute_pass;
|
||||
mod compute_pipeline;
|
||||
mod device;
|
||||
mod error;
|
||||
mod pipeline_layout;
|
||||
mod query_set;
|
||||
mod queue;
|
||||
mod render_bundle;
|
||||
mod render_pass;
|
||||
mod render_pipeline;
|
||||
mod sampler;
|
||||
mod shader;
|
||||
mod texture;
|
||||
mod webidl;
|
||||
|
||||
pub const UNSTABLE_FEATURE_NAME: &str = "webgpu";
|
||||
|
||||
//pub mod byow;
|
||||
//pub mod surface;
|
||||
mod wrap;
|
||||
|
||||
pub type Instance = std::sync::Arc<wgpu_core::global::Global>;
|
||||
pub type Instance = Arc<wgpu_core::global::Global>;
|
||||
|
||||
deno_core::extension!(
|
||||
deno_webgpu,
|
||||
deps = [deno_webidl, deno_web],
|
||||
ops = [wrap::create_gpu],
|
||||
ops = [create_gpu],
|
||||
objects = [
|
||||
wrap::GPU,
|
||||
wrap::adapter::GPUAdapter,
|
||||
wrap::adapter::GPUAdapterInfo,
|
||||
wrap::bind_group::GPUBindGroup,
|
||||
wrap::bind_group_layout::GPUBindGroupLayout,
|
||||
wrap::buffer::GPUBuffer,
|
||||
wrap::command_buffer::GPUCommandBuffer,
|
||||
wrap::command_encoder::GPUCommandEncoder,
|
||||
wrap::compute_pass::GPUComputePassEncoder,
|
||||
wrap::compute_pipeline::GPUComputePipeline,
|
||||
wrap::device::GPUDevice,
|
||||
wrap::device::GPUDeviceLostInfo,
|
||||
wrap::pipeline_layout::GPUPipelineLayout,
|
||||
wrap::query_set::GPUQuerySet,
|
||||
wrap::queue::GPUQueue,
|
||||
wrap::render_bundle::GPURenderBundle,
|
||||
wrap::render_bundle::GPURenderBundleEncoder,
|
||||
wrap::render_pass::GPURenderPassEncoder,
|
||||
wrap::render_pipeline::GPURenderPipeline,
|
||||
wrap::sampler::GPUSampler,
|
||||
wrap::shader::GPUShaderModule,
|
||||
wrap::adapter::GPUSupportedFeatures,
|
||||
wrap::adapter::GPUSupportedLimits,
|
||||
wrap::texture::GPUTexture,
|
||||
wrap::texture::GPUTextureView,
|
||||
GPU,
|
||||
adapter::GPUAdapter,
|
||||
adapter::GPUAdapterInfo,
|
||||
bind_group::GPUBindGroup,
|
||||
bind_group_layout::GPUBindGroupLayout,
|
||||
buffer::GPUBuffer,
|
||||
command_buffer::GPUCommandBuffer,
|
||||
command_encoder::GPUCommandEncoder,
|
||||
compute_pass::GPUComputePassEncoder,
|
||||
compute_pipeline::GPUComputePipeline,
|
||||
device::GPUDevice,
|
||||
device::GPUDeviceLostInfo,
|
||||
pipeline_layout::GPUPipelineLayout,
|
||||
query_set::GPUQuerySet,
|
||||
queue::GPUQueue,
|
||||
render_bundle::GPURenderBundle,
|
||||
render_bundle::GPURenderBundleEncoder,
|
||||
render_pass::GPURenderPassEncoder,
|
||||
render_pipeline::GPURenderPipeline,
|
||||
sampler::GPUSampler,
|
||||
shader::GPUShaderModule,
|
||||
adapter::GPUSupportedFeatures,
|
||||
adapter::GPUSupportedLimits,
|
||||
texture::GPUTexture,
|
||||
texture::GPUTextureView,
|
||||
],
|
||||
esm = ["00_init.js"],
|
||||
lazy_loaded_esm = ["01_webgpu.js"],
|
||||
);
|
||||
|
||||
#[op2]
|
||||
#[cppgc]
|
||||
pub fn create_gpu() -> GPU {
|
||||
GPU
|
||||
}
|
||||
|
||||
pub struct GPU;
|
||||
|
||||
impl GarbageCollected for GPU {}
|
||||
|
||||
#[op2]
|
||||
impl GPU {
|
||||
#[async_method]
|
||||
#[cppgc]
|
||||
async fn request_adapter(
|
||||
&self,
|
||||
state: Rc<RefCell<OpState>>,
|
||||
#[webidl] options: adapter::GPURequestAdapterOptions,
|
||||
) -> Option<adapter::GPUAdapter> {
|
||||
let mut state = state.borrow_mut();
|
||||
|
||||
let backends = std::env::var("DENO_WEBGPU_BACKEND").map_or_else(
|
||||
|_| wgpu_types::Backends::all(),
|
||||
|s| wgpu_core::instance::parse_backends_from_comma_list(&s),
|
||||
);
|
||||
let instance = if let Some(instance) = state.try_borrow::<Instance>() {
|
||||
instance
|
||||
} else {
|
||||
state.put(Arc::new(wgpu_core::global::Global::new(
|
||||
"webgpu",
|
||||
wgpu_types::InstanceDescriptor {
|
||||
backends,
|
||||
flags: wgpu_types::InstanceFlags::from_build_config(),
|
||||
dx12_shader_compiler: wgpu_types::Dx12Compiler::Fxc,
|
||||
gles_minor_version: wgpu_types::Gles3MinorVersion::default(),
|
||||
},
|
||||
)));
|
||||
state.borrow::<Instance>()
|
||||
};
|
||||
|
||||
let descriptor = wgpu_core::instance::RequestAdapterOptions {
|
||||
power_preference: options
|
||||
.power_preference
|
||||
.map(|pp| match pp {
|
||||
adapter::GPUPowerPreference::LowPower => PowerPreference::LowPower,
|
||||
adapter::GPUPowerPreference::HighPerformance => {
|
||||
PowerPreference::HighPerformance
|
||||
}
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
force_fallback_adapter: options.force_fallback_adapter,
|
||||
compatible_surface: None, // windowless
|
||||
};
|
||||
let id = instance.request_adapter(&descriptor, backends, None).ok()?;
|
||||
|
||||
Some(adapter::GPUAdapter {
|
||||
instance: instance.clone(),
|
||||
features: SameObject::new(),
|
||||
limits: SameObject::new(),
|
||||
info: Rc::new(SameObject::new()),
|
||||
id,
|
||||
})
|
||||
}
|
||||
|
||||
#[string]
|
||||
fn getPreferredCanvasFormat(&self) -> &'static str {
|
||||
// https://github.com/mozilla/gecko-dev/blob/b75080bb8b11844d18cb5f9ac6e68a866ef8e243/dom/webgpu/Instance.h#L42-L47
|
||||
if cfg!(target_os = "android") {
|
||||
texture::GPUTextureFormat::Rgba8unorm.as_str()
|
||||
} else {
|
||||
texture::GPUTextureFormat::Bgra8unorm.as_str()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,12 @@ use deno_core::GarbageCollected;
|
|||
use deno_core::WebIDL;
|
||||
use deno_error::JsErrorBox;
|
||||
|
||||
use crate::wrap::buffer::GPUBuffer;
|
||||
use crate::wrap::command_buffer::GPUCommandBuffer;
|
||||
use crate::wrap::texture::GPUTexture;
|
||||
use crate::wrap::texture::GPUTextureAspect;
|
||||
use crate::wrap::webidl::GPUExtent3D;
|
||||
use crate::wrap::webidl::GPUOrigin3D;
|
||||
use crate::buffer::GPUBuffer;
|
||||
use crate::command_buffer::GPUCommandBuffer;
|
||||
use crate::texture::GPUTexture;
|
||||
use crate::texture::GPUTextureAspect;
|
||||
use crate::webidl::GPUExtent3D;
|
||||
use crate::webidl::GPUOrigin3D;
|
||||
use crate::Instance;
|
||||
|
||||
pub struct GPUQueue {
|
|
@ -16,8 +16,8 @@ use deno_core::GarbageCollected;
|
|||
use deno_core::WebIDL;
|
||||
use deno_error::JsErrorBox;
|
||||
|
||||
use crate::wrap::buffer::GPUBuffer;
|
||||
use crate::wrap::texture::GPUTextureFormat;
|
||||
use crate::buffer::GPUBuffer;
|
||||
use crate::texture::GPUTextureFormat;
|
||||
use crate::Instance;
|
||||
|
||||
pub struct GPURenderBundleEncoder {
|
||||
|
@ -121,7 +121,7 @@ impl GPURenderBundleEncoder {
|
|||
&self,
|
||||
scope: &mut v8::HandleScope<'a>,
|
||||
#[webidl(options(enforce_range = true))] index: u32,
|
||||
#[webidl] bind_group: Nullable<Ptr<crate::wrap::bind_group::GPUBindGroup>>,
|
||||
#[webidl] bind_group: Nullable<Ptr<crate::bind_group::GPUBindGroup>>,
|
||||
dynamic_offsets: v8::Local<'a, v8::Value>,
|
||||
dynamic_offsets_data_start: v8::Local<'a, v8::Value>,
|
||||
dynamic_offsets_data_length: v8::Local<'a, v8::Value>,
|
||||
|
@ -202,7 +202,7 @@ impl GPURenderBundleEncoder {
|
|||
|
||||
fn set_pipeline(
|
||||
&self,
|
||||
#[webidl] pipeline: Ptr<crate::wrap::render_pipeline::GPURenderPipeline>,
|
||||
#[webidl] pipeline: Ptr<crate::render_pipeline::GPURenderPipeline>,
|
||||
) -> Result<(), JsErrorBox> {
|
||||
let mut encoder = self.encoder.borrow_mut();
|
||||
let encoder = encoder.as_mut().ok_or_else(|| {
|
||||
|
@ -220,7 +220,7 @@ impl GPURenderBundleEncoder {
|
|||
fn set_index_buffer(
|
||||
&self,
|
||||
#[webidl] buffer: Ptr<GPUBuffer>,
|
||||
#[webidl] index_format: crate::wrap::render_pipeline::GPUIndexFormat,
|
||||
#[webidl] index_format: crate::render_pipeline::GPUIndexFormat,
|
||||
#[webidl(default = 0, options(enforce_range = true))] offset: u64,
|
||||
#[webidl(options(enforce_range = true))] size: Option<u64>,
|
||||
) -> Result<(), JsErrorBox> {
|
|
@ -14,10 +14,10 @@ use deno_core::webidl::WebIdlError;
|
|||
use deno_core::GarbageCollected;
|
||||
use deno_core::WebIDL;
|
||||
|
||||
use crate::wrap::buffer::GPUBuffer;
|
||||
use crate::wrap::render_bundle::GPURenderBundle;
|
||||
use crate::wrap::texture::GPUTextureView;
|
||||
use crate::wrap::webidl::GPUColor;
|
||||
use crate::buffer::GPUBuffer;
|
||||
use crate::render_bundle::GPURenderBundle;
|
||||
use crate::texture::GPUTextureView;
|
||||
use crate::webidl::GPUColor;
|
||||
use crate::Instance;
|
||||
|
||||
pub struct GPURenderPassEncoder {
|
||||
|
@ -201,7 +201,7 @@ impl GPURenderPassEncoder {
|
|||
&self,
|
||||
scope: &mut v8::HandleScope<'a>,
|
||||
#[webidl(options(enforce_range = true))] index: u32,
|
||||
#[webidl] bind_group: Nullable<Ptr<crate::wrap::bind_group::GPUBindGroup>>,
|
||||
#[webidl] bind_group: Nullable<Ptr<crate::bind_group::GPUBindGroup>>,
|
||||
dynamic_offsets: v8::Local<'a, v8::Value>,
|
||||
dynamic_offsets_data_start: v8::Local<'a, v8::Value>,
|
||||
dynamic_offsets_data_length: v8::Local<'a, v8::Value>,
|
||||
|
@ -281,7 +281,7 @@ impl GPURenderPassEncoder {
|
|||
|
||||
fn set_pipeline(
|
||||
&self,
|
||||
#[webidl] pipeline: Ptr<crate::wrap::render_pipeline::GPURenderPipeline>,
|
||||
#[webidl] pipeline: Ptr<crate::render_pipeline::GPURenderPipeline>,
|
||||
) {
|
||||
let err = self
|
||||
.instance
|
||||
|
@ -294,7 +294,7 @@ impl GPURenderPassEncoder {
|
|||
fn set_index_buffer(
|
||||
&self,
|
||||
#[webidl] buffer: Ptr<GPUBuffer>,
|
||||
#[webidl] index_format: crate::wrap::render_pipeline::GPUIndexFormat,
|
||||
#[webidl] index_format: crate::render_pipeline::GPUIndexFormat,
|
||||
#[webidl(default = 0, options(enforce_range = true))] offset: u64,
|
||||
#[webidl(options(enforce_range = true))] size: Option<u64>,
|
||||
) {
|
||||
|
@ -419,7 +419,7 @@ pub(crate) struct GPURenderPassDescriptor {
|
|||
|
||||
pub color_attachments: Vec<Nullable<GPURenderPassColorAttachment>>,
|
||||
pub depth_stencil_attachment: Option<GPURenderPassDepthStencilAttachment>,
|
||||
pub occlusion_query_set: Option<Ptr<crate::wrap::query_set::GPUQuerySet>>,
|
||||
pub occlusion_query_set: Option<Ptr<crate::query_set::GPUQuerySet>>,
|
||||
pub timestamp_writes: Option<GPURenderPassTimestampWrites>,
|
||||
#[webidl(default = 50000000)]
|
||||
#[options(enforce_range = true)]
|
||||
|
@ -489,7 +489,7 @@ pub(crate) struct GPURenderPassDepthStencilAttachment {
|
|||
#[derive(WebIDL)]
|
||||
#[webidl(dictionary)]
|
||||
pub(crate) struct GPURenderPassTimestampWrites {
|
||||
pub query_set: Ptr<crate::wrap::query_set::GPUQuerySet>,
|
||||
pub query_set: Ptr<crate::query_set::GPUQuerySet>,
|
||||
#[options(enforce_range = true)]
|
||||
pub beginning_of_pass_write_index: Option<u32>,
|
||||
#[options(enforce_range = true)]
|
|
@ -8,11 +8,11 @@ use deno_core::GarbageCollected;
|
|||
use deno_core::WebIDL;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use crate::wrap::bind_group_layout::GPUBindGroupLayout;
|
||||
use crate::wrap::sampler::GPUCompareFunction;
|
||||
use crate::wrap::shader::GPUShaderModule;
|
||||
use crate::wrap::texture::GPUTextureFormat;
|
||||
use crate::wrap::webidl::GPUPipelineLayoutOrGPUAutoLayoutMode;
|
||||
use crate::bind_group_layout::GPUBindGroupLayout;
|
||||
use crate::sampler::GPUCompareFunction;
|
||||
use crate::shader::GPUShaderModule;
|
||||
use crate::texture::GPUTextureFormat;
|
||||
use crate::webidl::GPUPipelineLayoutOrGPUAutoLayoutMode;
|
||||
use crate::Instance;
|
||||
|
||||
pub struct GPURenderPipeline {
|
|
@ -302,7 +302,7 @@ pub(crate) enum GPUAutoLayoutMode {
|
|||
}
|
||||
|
||||
pub(crate) enum GPUPipelineLayoutOrGPUAutoLayoutMode {
|
||||
PipelineLayout(Ptr<crate::wrap::pipeline_layout::GPUPipelineLayout>),
|
||||
PipelineLayout(Ptr<crate::pipeline_layout::GPUPipelineLayout>),
|
||||
AutoLayoutMode(GPUAutoLayoutMode),
|
||||
}
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use deno_core::cppgc::SameObject;
|
||||
use deno_core::op2;
|
||||
use deno_core::GarbageCollected;
|
||||
use deno_core::OpState;
|
||||
use wgpu_types::PowerPreference;
|
||||
|
||||
use crate::Instance;
|
||||
|
||||
pub mod adapter;
|
||||
pub mod bind_group;
|
||||
pub mod bind_group_layout;
|
||||
pub mod buffer;
|
||||
pub mod command_buffer;
|
||||
pub mod command_encoder;
|
||||
pub mod compute_pass;
|
||||
pub mod compute_pipeline;
|
||||
pub mod device;
|
||||
pub mod error;
|
||||
pub mod pipeline_layout;
|
||||
pub mod query_set;
|
||||
pub mod queue;
|
||||
pub mod render_bundle;
|
||||
pub mod render_pass;
|
||||
pub mod render_pipeline;
|
||||
pub mod sampler;
|
||||
pub mod shader;
|
||||
pub mod texture;
|
||||
pub mod webidl;
|
||||
|
||||
#[op2]
|
||||
#[cppgc]
|
||||
pub fn create_gpu() -> GPU {
|
||||
GPU
|
||||
}
|
||||
|
||||
pub struct GPU;
|
||||
|
||||
impl GarbageCollected for GPU {}
|
||||
|
||||
#[op2]
|
||||
impl GPU {
|
||||
#[async_method]
|
||||
#[cppgc]
|
||||
async fn request_adapter(
|
||||
&self,
|
||||
state: Rc<RefCell<OpState>>,
|
||||
#[webidl] options: adapter::GPURequestAdapterOptions,
|
||||
) -> Option<adapter::GPUAdapter> {
|
||||
let mut state = state.borrow_mut();
|
||||
|
||||
let backends = std::env::var("DENO_WEBGPU_BACKEND").map_or_else(
|
||||
|_| wgpu_types::Backends::all(),
|
||||
|s| wgpu_core::instance::parse_backends_from_comma_list(&s),
|
||||
);
|
||||
let instance = if let Some(instance) = state.try_borrow::<Instance>() {
|
||||
instance
|
||||
} else {
|
||||
state.put(Arc::new(wgpu_core::global::Global::new(
|
||||
"webgpu",
|
||||
wgpu_types::InstanceDescriptor {
|
||||
backends,
|
||||
flags: wgpu_types::InstanceFlags::from_build_config(),
|
||||
dx12_shader_compiler: wgpu_types::Dx12Compiler::Fxc,
|
||||
gles_minor_version: wgpu_types::Gles3MinorVersion::default(),
|
||||
},
|
||||
)));
|
||||
state.borrow::<Instance>()
|
||||
};
|
||||
|
||||
let descriptor = wgpu_core::instance::RequestAdapterOptions {
|
||||
power_preference: options
|
||||
.power_preference
|
||||
.map(|pp| match pp {
|
||||
adapter::GPUPowerPreference::LowPower => PowerPreference::LowPower,
|
||||
adapter::GPUPowerPreference::HighPerformance => {
|
||||
PowerPreference::HighPerformance
|
||||
}
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
force_fallback_adapter: options.force_fallback_adapter,
|
||||
compatible_surface: None, // windowless
|
||||
};
|
||||
let id = instance.request_adapter(&descriptor, backends, None).ok()?;
|
||||
|
||||
Some(adapter::GPUAdapter {
|
||||
instance: instance.clone(),
|
||||
features: SameObject::new(),
|
||||
limits: SameObject::new(),
|
||||
info: Rc::new(SameObject::new()),
|
||||
id,
|
||||
})
|
||||
}
|
||||
|
||||
#[string]
|
||||
fn getPreferredCanvasFormat(&self) -> &'static str {
|
||||
// https://github.com/mozilla/gecko-dev/blob/b75080bb8b11844d18cb5f9ac6e68a866ef8e243/dom/webgpu/Instance.h#L42-L47
|
||||
if cfg!(target_os = "android") {
|
||||
texture::GPUTextureFormat::Rgba8unorm.as_str()
|
||||
} else {
|
||||
texture::GPUTextureFormat::Bgra8unorm.as_str()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue