separate Queue&Device Id (#32966)

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
Samson 2024-08-08 09:53:17 +02:00 committed by GitHub
parent a5df51ea56
commit f989d3776e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 54 additions and 32 deletions

View file

@ -138,10 +138,14 @@ impl GPUAdapterMethods for GPUAdapter {
}
}
}
let id = self
let device_id = self
.global()
.wgpu_id_hub()
.create_device_id(self.adapter.0.backend());
let queue_id = self
.global()
.wgpu_id_hub()
.create_queue_id(self.adapter.0.backend());
let pipeline_id = self.global().pipeline_id();
if self
.channel
@ -150,7 +154,8 @@ impl GPUAdapterMethods for GPUAdapter {
sender,
adapter_id: self.adapter,
descriptor: desc,
device_id: id,
device_id,
queue_id,
pipeline_id,
})
.is_err()

View file

@ -272,6 +272,7 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
.0
.send(WebGPURequest::CreateSwapChain {
device_id: descriptor.device.id().0,
queue_id: descriptor.device.GetQueue().id().0,
buffer_ids,
external_id: self.context_id.0,
sender,

View file

@ -61,6 +61,10 @@ impl GPUQueue {
pub fn set_device(&self, device: &GPUDevice) {
*self.device.borrow_mut() = Some(Dom::from_ref(device));
}
pub fn id(&self) -> WebGPUQueue {
self.queue
}
}
impl GPUQueueMethods for GPUQueue {
@ -95,6 +99,7 @@ impl GPUQueueMethods for GPUQueue {
self.channel
.0
.send(WebGPURequest::Submit {
device_id: self.device.borrow().as_ref().unwrap().id().0,
queue_id: self.queue.0,
command_buffers,
})
@ -133,6 +138,7 @@ impl GPUQueueMethods for GPUQueue {
&bytes[data_offset as usize..(data_offset + content_size) as usize],
);
if let Err(e) = self.channel.0.send(WebGPURequest::WriteBuffer {
device_id: self.device.borrow().as_ref().unwrap().id().0,
queue_id: self.queue.0,
buffer_id: buffer.id().0,
buffer_offset,
@ -169,6 +175,7 @@ impl GPUQueueMethods for GPUQueue {
let final_data = IpcSharedMemory::from_bytes(&bytes);
if let Err(e) = self.channel.0.send(WebGPURequest::WriteTexture {
device_id: self.device.borrow().as_ref().unwrap().id().0,
queue_id: self.queue.0,
texture_cv,
data_layout: texture_layout,
@ -197,6 +204,7 @@ impl GPUQueueMethods for GPUQueue {
.send(WebGPURequest::QueueOnSubmittedWorkDone {
sender,
queue_id: self.queue.0,
device_id: self.device.borrow().as_ref().unwrap().id().0,
})
{
warn!("QueueOnSubmittedWorkDone failed with {e}")

View file

@ -6,12 +6,13 @@ use smallvec::SmallVec;
use webgpu::identity::{ComputePass, ComputePassId, RenderPass, RenderPassId};
use webgpu::wgc::id::markers::{
Adapter, BindGroup, BindGroupLayout, Buffer, CommandEncoder, ComputePipeline, Device,
PipelineLayout, RenderBundle, RenderPipeline, Sampler, ShaderModule, Texture, TextureView,
PipelineLayout, Queue, RenderBundle, RenderPipeline, Sampler, ShaderModule, Texture,
TextureView,
};
use webgpu::wgc::id::{
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandEncoderId, ComputePipelineId,
DeviceId, PipelineLayoutId, RenderBundleId, RenderPipelineId, SamplerId, ShaderModuleId,
TextureId, TextureViewId,
DeviceId, PipelineLayoutId, QueueId, RenderBundleId, RenderPipelineId, SamplerId,
ShaderModuleId, TextureId, TextureViewId,
};
use webgpu::wgc::identity::IdentityManager;
use webgpu::wgt::Backend;
@ -20,6 +21,7 @@ use webgpu::wgt::Backend;
pub struct IdentityHub {
adapters: IdentityManager<Adapter>,
devices: IdentityManager<Device>,
queues: IdentityManager<Queue>,
buffers: IdentityManager<Buffer>,
bind_groups: IdentityManager<BindGroup>,
bind_group_layouts: IdentityManager<BindGroupLayout>,
@ -41,6 +43,7 @@ impl IdentityHub {
IdentityHub {
adapters: IdentityManager::new(),
devices: IdentityManager::new(),
queues: IdentityManager::new(),
buffers: IdentityManager::new(),
bind_groups: IdentityManager::new(),
bind_group_layouts: IdentityManager::new(),
@ -123,6 +126,14 @@ impl Identities {
self.select(id.backend()).devices.free(id);
}
pub fn create_queue_id(&self, backend: Backend) -> QueueId {
self.select(backend).queues.process(backend)
}
pub fn free_queue_id(&self, id: QueueId) {
self.select(id.backend()).queues.free(id);
}
pub fn create_adapter_ids(&self) -> SmallVec<[AdapterId; 4]> {
let mut ids = SmallVec::new();
for hubs in self.hubs() {