Skip to content

Commit

Permalink
Update wgpu-core and wgpu-types
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalmohan committed Jun 3, 2020
1 parent 1d4efb4 commit 3b5ede1
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 90 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions components/script/dom/gpuadapter.rs
Expand Up @@ -39,8 +39,8 @@ impl GPUAdapter {
name: DOMString,
extensions: Heap<*mut JSObject>,
adapter: WebGPUAdapter,
) -> GPUAdapter {
GPUAdapter {
) -> Self {
Self {
reflector_: Reflector::new(),
channel,
name,
Expand All @@ -55,7 +55,7 @@ impl GPUAdapter {
name: DOMString,
extensions: Heap<*mut JSObject>,
adapter: WebGPUAdapter,
) -> DomRoot<GPUAdapter> {
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUAdapter::new_inherited(
channel, name, extensions, adapter,
Expand All @@ -81,9 +81,7 @@ impl GPUAdapterMethods for GPUAdapter {
let promise = Promise::new_in_current_realm(&self.global(), comp);
let sender = response_async(&promise, self);
let desc = wgt::DeviceDescriptor {
extensions: wgt::Extensions {
anisotropic_filtering: descriptor.extensions.anisotropicFiltering,
},
extensions: wgt::Extensions::empty(),
limits: wgt::Limits {
max_bind_groups: descriptor.limits.maxBindGroups,
},
Expand Down
8 changes: 2 additions & 6 deletions components/script/dom/gpubindgroup.rs
Expand Up @@ -21,7 +21,7 @@ pub struct GPUBindGroup {
}

impl GPUBindGroup {
fn new_inherited(bind_group: WebGPUBindGroup, valid: bool) -> GPUBindGroup {
fn new_inherited(bind_group: WebGPUBindGroup, valid: bool) -> Self {
Self {
reflector_: Reflector::new(),
label: DomRefCell::new(None),
Expand All @@ -30,11 +30,7 @@ impl GPUBindGroup {
}
}

pub fn new(
global: &GlobalScope,
bind_group: WebGPUBindGroup,
valid: bool,
) -> DomRoot<GPUBindGroup> {
pub fn new(global: &GlobalScope, bind_group: WebGPUBindGroup, valid: bool) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUBindGroup::new_inherited(bind_group, valid)),
global,
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/gpubindgrouplayout.rs
Expand Up @@ -32,7 +32,7 @@ impl GPUBindGroupLayout {
bind_group_layout: WebGPUBindGroupLayout,
bindings: Vec<GPUBindGroupLayoutEntry>,
valid: bool,
) -> GPUBindGroupLayout {
) -> Self {
Self {
reflector_: Reflector::new(),
channel,
Expand All @@ -49,7 +49,7 @@ impl GPUBindGroupLayout {
bind_group_layout: WebGPUBindGroupLayout,
bindings: Vec<GPUBindGroupLayoutEntry>,
valid: bool,
) -> DomRoot<GPUBindGroupLayout> {
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUBindGroupLayout::new_inherited(
channel,
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/gpubuffer.rs
Expand Up @@ -57,7 +57,7 @@ impl GPUBuffer {
usage: u32,
valid: bool,
mapping: RootedTraceableBox<Heap<*mut JSObject>>,
) -> GPUBuffer {
) -> Self {
Self {
reflector_: Reflector::new(),
channel,
Expand All @@ -83,7 +83,7 @@ impl GPUBuffer {
usage: u32,
valid: bool,
mapping: RootedTraceableBox<Heap<*mut JSObject>>,
) -> DomRoot<GPUBuffer> {
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUBuffer::new_inherited(
channel, buffer, device, state, size, usage, valid, mapping,
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/gpucommandbuffer.rs
Expand Up @@ -37,8 +37,8 @@ impl GPUCommandBuffer {
channel: WebGPU,
command_buffer: WebGPUCommandBuffer,
buffers: HashSet<DomRoot<GPUBuffer>>,
) -> GPUCommandBuffer {
GPUCommandBuffer {
) -> Self {
Self {
channel,
reflector_: Reflector::new(),
label: DomRefCell::new(None),
Expand All @@ -52,7 +52,7 @@ impl GPUCommandBuffer {
channel: WebGPU,
command_buffer: WebGPUCommandBuffer,
buffers: HashSet<DomRoot<GPUBuffer>>,
) -> DomRoot<GPUCommandBuffer> {
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUCommandBuffer::new_inherited(
channel,
Expand Down
2 changes: 2 additions & 0 deletions components/script/dom/gpucommandencoder.rs
Expand Up @@ -192,12 +192,14 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
GPUStoreOp::Clear => wgt::StoreOp::Clear,
},
clear_depth,
depth_read_only: depth.depthReadOnly,
stencil_load_op,
stencil_store_op: match depth.stencilStoreOp {
GPUStoreOp::Store => wgt::StoreOp::Store,
GPUStoreOp::Clear => wgt::StoreOp::Clear,
},
clear_stencil,
stencil_read_only: depth.stencilReadOnly,
}
});

Expand Down
7 changes: 2 additions & 5 deletions components/script/dom/gpucomputepipeline.rs
Expand Up @@ -20,18 +20,15 @@ pub struct GPUComputePipeline {
}

impl GPUComputePipeline {
fn new_inherited(compute_pipeline: WebGPUComputePipeline) -> GPUComputePipeline {
fn new_inherited(compute_pipeline: WebGPUComputePipeline) -> Self {
Self {
reflector_: Reflector::new(),
label: DomRefCell::new(None),
compute_pipeline,
}
}

pub fn new(
global: &GlobalScope,
compute_pipeline: WebGPUComputePipeline,
) -> DomRoot<GPUComputePipeline> {
pub fn new(global: &GlobalScope, compute_pipeline: WebGPUComputePipeline) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUComputePipeline::new_inherited(compute_pipeline)),
global,
Expand Down
24 changes: 13 additions & 11 deletions components/script/dom/gpudevice.rs
Expand Up @@ -85,7 +85,7 @@ impl GPUDevice {
limits: Heap<*mut JSObject>,
device: webgpu::WebGPUDevice,
queue: &GPUQueue,
) -> GPUDevice {
) -> Self {
Self {
eventtarget: EventTarget::new_inherited(),
channel,
Expand All @@ -106,7 +106,7 @@ impl GPUDevice {
limits: Heap<*mut JSObject>,
device: webgpu::WebGPUDevice,
queue: webgpu::WebGPUQueue,
) -> DomRoot<GPUDevice> {
) -> DomRoot<Self> {
let queue = GPUQueue::new(global, channel.clone(), queue);
reflect_dom_object(
Box::new(GPUDevice::new_inherited(
Expand All @@ -121,6 +121,7 @@ impl GPUDevice {
fn validate_buffer_descriptor(
&self,
descriptor: &GPUBufferDescriptor,
mapped_at_creation: bool,
) -> (bool, wgt::BufferDescriptor<std::string::String>) {
// TODO: Record a validation error in the current scope if the descriptor is invalid.
let wgpu_usage = wgt::BufferUsage::from_bits(descriptor.usage);
Expand All @@ -132,6 +133,7 @@ impl GPUDevice {
wgt::BufferDescriptor {
size: descriptor.size,
usage: wgpu_usage.unwrap(),
mapped_at_creation,
label: Default::default(),
},
)
Expand All @@ -141,6 +143,7 @@ impl GPUDevice {
wgt::BufferDescriptor {
size: 0,
usage: wgt::BufferUsage::empty(),
mapped_at_creation,
label: Default::default(),
},
)
Expand Down Expand Up @@ -181,7 +184,7 @@ impl GPUDeviceMethods for GPUDevice {

/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbuffer
fn CreateBuffer(&self, descriptor: &GPUBufferDescriptor) -> DomRoot<GPUBuffer> {
let (valid, wgpu_descriptor) = self.validate_buffer_descriptor(descriptor);
let (valid, wgpu_descriptor) = self.validate_buffer_descriptor(descriptor, false);
let id = self
.global()
.wgpu_id_hub()
Expand Down Expand Up @@ -217,15 +220,15 @@ impl GPUDeviceMethods for GPUDevice {
cx: SafeJSContext,
descriptor: &GPUBufferDescriptor,
) -> Vec<JSVal> {
let (valid, wgpu_descriptor) = self.validate_buffer_descriptor(descriptor);
let (valid, wgpu_descriptor) = self.validate_buffer_descriptor(descriptor, true);
let buffer_id = self
.global()
.wgpu_id_hub()
.lock()
.create_buffer_id(self.device.0.backend());
self.channel
.0
.send(WebGPURequest::CreateBufferMapped {
.send(WebGPURequest::CreateBuffer {
device_id: self.device.0,
buffer_id,
descriptor: wgpu_descriptor.clone(),
Expand Down Expand Up @@ -546,7 +549,9 @@ impl GPUDeviceMethods for GPUDevice {
resource: BindingResource::Buffer(BufferBinding {
buffer: bind.resource.buffer.id().0,
offset: bind.resource.offset,
size: bind.resource.size.unwrap_or(bind.resource.buffer.size()),
size: wgt::BufferSize(
bind.resource.size.unwrap_or(bind.resource.buffer.size()),
),
}),
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -729,11 +734,8 @@ impl GPUDeviceMethods for GPUDevice {
mipmap_filter: convert_filter_mode(descriptor.mipmapFilter),
lod_min_clamp: *descriptor.lodMinClamp,
lod_max_clamp: *descriptor.lodMaxClamp,
compare: if let Some(c) = descriptor.compare {
convert_compare_function(c)
} else {
wgt::CompareFunction::Undefined
},
compare: descriptor.compare.map(|c| convert_compare_function(c)),
anisotropy_clamp: None,
};
self.channel
.0
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/gpupipelinelayout.rs
Expand Up @@ -26,7 +26,7 @@ impl GPUPipelineLayout {
bind_group_layouts: Vec<WebGPUBindGroupLayout>,
pipeline_layout: WebGPUPipelineLayout,
valid: bool,
) -> GPUPipelineLayout {
) -> Self {
Self {
reflector_: Reflector::new(),
bind_group_layouts,
Expand All @@ -41,7 +41,7 @@ impl GPUPipelineLayout {
bind_group_layouts: Vec<WebGPUBindGroupLayout>,
pipeline_layout: WebGPUPipelineLayout,
valid: bool,
) -> DomRoot<GPUPipelineLayout> {
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUPipelineLayout::new_inherited(
bind_group_layouts,
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/gpuqueue.rs
Expand Up @@ -23,7 +23,7 @@ pub struct GPUQueue {
}

impl GPUQueue {
fn new_inherited(channel: WebGPU, queue: WebGPUQueue) -> GPUQueue {
fn new_inherited(channel: WebGPU, queue: WebGPUQueue) -> Self {
GPUQueue {
channel,
reflector_: Reflector::new(),
Expand All @@ -32,7 +32,7 @@ impl GPUQueue {
}
}

pub fn new(global: &GlobalScope, channel: WebGPU, queue: WebGPUQueue) -> DomRoot<GPUQueue> {
pub fn new(global: &GlobalScope, channel: WebGPU, queue: WebGPUQueue) -> DomRoot<Self> {
reflect_dom_object(Box::new(GPUQueue::new_inherited(channel, queue)), global)
}
}
Expand Down
18 changes: 8 additions & 10 deletions components/script/dom/gpurenderpassencoder.rs
Expand Up @@ -173,12 +173,11 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {

/// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-setindexbuffer
fn SetIndexBuffer(&self, buffer: &GPUBuffer, offset: u64, size: u64) {
let s;
if size == 0 {
s = buffer.size() - offset;
let s = if size == 0 {
wgt::BufferSize::WHOLE
} else {
s = size;
}
wgt::BufferSize(size)
};

if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() {
unsafe {
Expand All @@ -189,12 +188,11 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {

/// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-setvertexbuffer
fn SetVertexBuffer(&self, slot: u32, buffer: &GPUBuffer, offset: u64, size: u64) {
let s;
if size == 0 {
s = buffer.size() - offset;
let s = if size == 0 {
wgt::BufferSize::WHOLE
} else {
s = size;
}
wgt::BufferSize(size)
};

if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() {
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/gpurenderpipeline.rs
Expand Up @@ -27,7 +27,7 @@ impl GPURenderPipeline {
render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice,
valid: bool,
) -> GPURenderPipeline {
) -> Self {
Self {
reflector_: Reflector::new(),
label: DomRefCell::new(None),
Expand All @@ -42,7 +42,7 @@ impl GPURenderPipeline {
render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice,
valid: bool,
) -> DomRoot<GPURenderPipeline> {
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPURenderPipeline::new_inherited(
render_pipeline,
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/gpusampler.rs
Expand Up @@ -31,7 +31,7 @@ impl GPUSampler {
compare_enable: bool,
sampler: WebGPUSampler,
valid: bool,
) -> GPUSampler {
) -> Self {
Self {
reflector_: Reflector::new(),
channel,
Expand All @@ -50,7 +50,7 @@ impl GPUSampler {
compare_enable: bool,
sampler: WebGPUSampler,
valid: bool,
) -> DomRoot<GPUSampler> {
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUSampler::new_inherited(
channel,
Expand Down
7 changes: 2 additions & 5 deletions components/script/dom/gpushadermodule.rs
Expand Up @@ -19,18 +19,15 @@ pub struct GPUShaderModule {
}

impl GPUShaderModule {
fn new_inherited(shader_module: WebGPUShaderModule) -> GPUShaderModule {
fn new_inherited(shader_module: WebGPUShaderModule) -> Self {
Self {
reflector_: Reflector::new(),
label: DomRefCell::new(None),
shader_module,
}
}

pub fn new(
global: &GlobalScope,
shader_module: WebGPUShaderModule,
) -> DomRoot<GPUShaderModule> {
pub fn new(global: &GlobalScope, shader_module: WebGPUShaderModule) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUShaderModule::new_inherited(shader_module)),
global,
Expand Down

0 comments on commit 3b5ede1

Please sign in to comment.