Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of GPUBuffer for WebGPU #25264

Merged
merged 1 commit into from Dec 17, 2019
Merged

Conversation

@imiklos
Copy link
Contributor

imiklos commented Dec 12, 2019

Added WebIDL bindings for GPUBuffer, GPUBufferDescriptor, GPUBufferUsage.
Implemented the createBuffer and createBufferMapped functions of GPUDevice.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes addresses a part of #24706

cc @kvark @jdm @zakorgy


This change is Reviewable

@highfive
Copy link

highfive commented Dec 12, 2019

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/gpuadapter.rs, components/script/dom/gpubufferusage.rs, components/script/dom/navigator.rs, components/script/dom/mod.rs, components/script/dom/identityhub.rs and 6 more
  • @KiChjang: components/script/dom/gpuadapter.rs, components/script/dom/gpubufferusage.rs, components/script/dom/navigator.rs, components/script/dom/mod.rs, components/script/dom/identityhub.rs and 6 more
@highfive
Copy link

highfive commented Dec 12, 2019

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify script code, but no tests are modified. Please consider adding a test!
},
_ => {},
};
if let Some(window) = self.global().downcast::<Window>() {

This comment has been minimized.

Copy link
@jdm

jdm Dec 12, 2019

Member

Since this method is called from the destructor, instead of getting the channel from the global we should hold on to the channel so we can use it directly.

This comment has been minimized.

Copy link
@gterzian

gterzian Dec 15, 2019

Member

I think "holding on to the channel so we can use it directly" will be generally addressed in #25030, it might be a good idea to coordinate with @zakorgy and perhaps rebase this one off of those changes when they are completed(or do it in a follow-up requiring some refactoring).

This comment has been minimized.

Copy link
@imiklos

imiklos Dec 16, 2019

Author Contributor

I've saved the channel in the GPUBuffer so we can send requests directly.

global.device_create_buffer_mapped(device.0, &descriptor, &mut arr_buff, id));
let buffer = WebGPUBuffer(id);

if let Err(e) = sender.send((buffer, arr_buff as usize)) {

This comment has been minimized.

Copy link
@jdm

jdm Dec 12, 2019

Member

This sends a pointer over IPC, so this won't work with multiple processes. How do we deal with this? Do we need to copy the memory into a Vec and send that instead?

This comment has been minimized.

Copy link
@imiklos

imiklos Dec 16, 2019

Author Contributor

Yes, you are right. I've copied the memory into a Vec as you mentioned.

@@ -63,6 +75,74 @@ impl GPUDevice {
}
}

impl GPUDevice {
fn resolve_create_buffer_mapped(

This comment has been minimized.

Copy link
@jdm

jdm Dec 12, 2019

Member

This should be marked unsafe, since it accepts an arbitrary integer, converts it to a pointer, and dereferences it by using it to create a slice.

);
unsafe { buff.to_jsval(*cx, js_gpu_buffer.handle_mut()) };
let mut out = Vec::new();
out.push(js_gpu_buffer.get());

This comment has been minimized.

Copy link
@jdm

jdm Dec 12, 2019

Member

This can be ObjectValue(buff.reflector().get_jsobject().get()), and then we don't need js_gpu_buffer.

Copy link
Member

kvark left a comment

Reviewed 14 of 14 files at r1.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @imiklos)


components/script/dom/gpubuffer.rs, line 32 at r1 (raw file):

    label: DomRefCell<Option<DOMString>>,
    size: Cell<GPUBufferSize>,
    usage: Cell<u32>,

usage and size shouldn't be mutable: they are set at creation and persist across the life time


components/script/dom/gpubufferusage.rs, line 9 at r1 (raw file):

#[dom_struct]
pub struct GPUBufferUsage {

does this have to be an interface?
There are no methods expected, it's just a namespace, conceptually.
In Gecko, we mark those interfaces as concrete: false and don't need any classes on C++ side for them.


components/script/dom/gpudevice.rs, line 190 at r1 (raw file):

                    .unwrap(),
                None => {
                    return GPUBuffer::new(

if the GPU process is dead and the channel is not available, we should probably not pretend we are doing anything constructive here


components/script/dom/gpudevice.rs, line 246 at r1 (raw file):

        };

        let (buffer, array_ptr_address) = receiver.recv().unwrap();

we can't pass around pointers between processes, as @jdm noted already

Copy link
Contributor Author

imiklos left a comment

Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @imiklos, @jdm, @kvark, and @zakorgy)


components/script/dom/gpubuffer.rs, line 32 at r1 (raw file):

Previously, kvark (Dzmitry Malyshau) wrote…

usage and size shouldn't be mutable: they are set at creation and persist across the life time

Thank you! I will remove the Cell.


components/script/dom/gpubufferusage.rs, line 9 at r1 (raw file):

Previously, kvark (Dzmitry Malyshau) wrote…

does this have to be an interface?
There are no methods expected, it's just a namespace, conceptually.
In Gecko, we mark those interfaces as concrete: false and don't need any classes on C++ side for them.

I didn't find similar to concrete: false in servo. @jdm Do you have an idea about this?


components/script/dom/gpudevice.rs, line 190 at r1 (raw file):

Previously, kvark (Dzmitry Malyshau) wrote…

if the GPU process is dead and the channel is not available, we should probably not pretend we are doing anything constructive here

You are right! I've just put an unimplemented! macro instead of returning with a GPUBuffer here.


components/script/dom/gpudevice.rs, line 246 at r1 (raw file):

Previously, kvark (Dzmitry Malyshau) wrote…

we can't pass around pointers between processes, as @jdm noted already

Yes, I've copied the memory into a Vec and sent that instead of pointers.

@imiklos imiklos force-pushed the szeged:wgpu_buffer branch from 706c2ac to 2033790 Dec 16, 2019
@imiklos
Copy link
Contributor Author

imiklos commented Dec 16, 2019

@jdm @kvark @gterzian Thank your for your review! I've addressed what you mentioned.

@imiklos
Copy link
Contributor Author

imiklos commented Dec 16, 2019

@kvark I get the following validation layer error on destruction:
(this is an unmapped buffer created with device.createBuffer)

[2019-12-16T13:09:39Z ERROR relevant] Values of this type can't be dropped!
[2019-12-16T13:09:39Z ERROR gfx_backend_vulkan]
VALIDATION [VUID-vkDestroyDevice-device-00378 (0)] : OBJ ERROR : For device 0x7fac702eac70, DeviceMemory object 0x3 has not been destroyed. The Vulkan spec states: All child objects created on device must have been destroyed prior to destroying device (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-vkDestroyDevice-device-00378)
object info: (type: DEVICE_MEMORY, hndl: 3)

[2019-12-16T13:09:39Z ERROR relevant] Values of this type can't be dropped!

I got the same result with explicitly call the Buffer.destroy() or without.
The Global.delete() called before exit.
Am I missing something?

@kvark
Copy link
Member

kvark commented Dec 16, 2019

I get the following validation layer error on destruction:

This comes from rendy-memory, which you need to double-check if you are destroying correctly.

@jdm
jdm approved these changes Dec 16, 2019
@bors-servo
Copy link
Contributor

bors-servo commented Dec 17, 2019

The latest upstream changes (presumably #25299) made this pull request unmergeable. Please resolve the merge conflicts.

Added WebIDL bindings for GPUBuffer, GPUBufferDescriptor, GPUBufferUsage
Implemented the `createBuffer` and `createBufferMapped` functions of GPUDevice
@imiklos imiklos force-pushed the szeged:wgpu_buffer branch from 2033790 to ebfcd0f Dec 17, 2019
@jdm
Copy link
Member

jdm commented Dec 17, 2019

@bors-servo
Copy link
Contributor

bors-servo commented Dec 17, 2019

📌 Commit ebfcd0f has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Dec 17, 2019

Testing commit ebfcd0f with merge c9a7c0e...

bors-servo added a commit that referenced this pull request Dec 17, 2019
Initial implementation of GPUBuffer for WebGPU

Added WebIDL bindings for `GPUBuffer`, `GPUBufferDescriptor`, `GPUBufferUsage`.
Implemented the `createBuffer` and `createBufferMapped` functions of `GPUDevice`.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes addresses a part of #24706

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
cc @kvark @jdm @zakorgy

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/25264)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Dec 17, 2019

💔 Test failed - status-taskcluster

@jdm
Copy link
Member

jdm commented Dec 17, 2019

@bors-servo
Copy link
Contributor

bors-servo commented Dec 17, 2019

Testing commit ebfcd0f with merge f86a027...

bors-servo added a commit that referenced this pull request Dec 17, 2019
Initial implementation of GPUBuffer for WebGPU

Added WebIDL bindings for `GPUBuffer`, `GPUBufferDescriptor`, `GPUBufferUsage`.
Implemented the `createBuffer` and `createBufferMapped` functions of `GPUDevice`.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes addresses a part of #24706

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
cc @kvark @jdm @zakorgy

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/25264)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Dec 17, 2019

💔 Test failed - status-taskcluster

@jdm
Copy link
Member

jdm commented Dec 17, 2019

@bors-servo
Copy link
Contributor

bors-servo commented Dec 17, 2019

Testing commit ebfcd0f with merge cea55e3...

bors-servo added a commit that referenced this pull request Dec 17, 2019
Initial implementation of GPUBuffer for WebGPU

Added WebIDL bindings for `GPUBuffer`, `GPUBufferDescriptor`, `GPUBufferUsage`.
Implemented the `createBuffer` and `createBufferMapped` functions of `GPUDevice`.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes addresses a part of #24706

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
cc @kvark @jdm @zakorgy

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/25264)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Dec 17, 2019

☀️ Test successful - status-taskcluster
Approved by: jdm
Pushing cea55e3 to master...

@bors-servo bors-servo merged commit ebfcd0f into servo:master Dec 17, 2019
2 checks passed
2 checks passed
Community-TC (pull_request) TaskGroup: success
Details
homu Test successful
Details
@kvark kvark deleted the szeged:wgpu_buffer branch Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.