Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit d8e0138

Browse files
committed
Add PartialEq, Eq, Hash for more types
Don't implement Hash on handle id types for wasm32 Unlike the native handle ids that are effectively wrappers around an intetger type, the handle id types for the wasm32 backend are redefined to point at web_sys structures that may not have Hash implemented. Remove Hash implementations for now but keep PartialEq and Eq Remove Hash on more descriptors Remove Temp
1 parent 0751806 commit d8e0138

File tree

1 file changed

+30
-39
lines changed

1 file changed

+30
-39
lines changed

src/lib.rs

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,11 @@ pub use wgc::instance::{
7474
DeviceType,
7575
};
7676

77-
//TODO: avoid heap allocating vectors during resource creation.
78-
#[derive(Default, Debug)]
79-
struct Temp {
80-
//bind_group_descriptors: Vec<wgn::BindGroupDescriptor>,
81-
//vertex_buffers: Vec<wgn::VertexBufferDescriptor>,
82-
}
83-
8477
/// A handle to a physical graphics and/or compute device.
8578
///
8679
/// An `Adapter` can be used to open a connection to the corresponding device on the host system,
8780
/// yielding a [`Device`] object.
88-
#[derive(Debug, PartialEq)]
81+
#[derive(Debug, PartialEq, Eq)]
8982
pub struct Adapter {
9083
id: wgc::id::AdapterId,
9184
}
@@ -103,10 +96,9 @@ pub struct RequestAdapterOptions<'a> {
10396
///
10497
/// The `Device` is the responsible for the creation of most rendering and compute resources, as
10598
/// well as exposing [`Queue`] objects.
106-
#[derive(Debug)]
99+
#[derive(Debug, PartialEq, Eq)]
107100
pub struct Device {
108101
id: wgc::id::DeviceId,
109-
temp: Temp,
110102
}
111103

112104
/// This is passed to `Device::poll` to control whether
@@ -118,14 +110,14 @@ pub enum Maintain {
118110
}
119111

120112
/// A handle to a GPU-accessible buffer.
121-
#[derive(Debug, PartialEq)]
113+
#[derive(Debug, PartialEq, Eq)]
122114
pub struct Buffer {
123115
id: wgc::id::BufferId,
124116
device_id: wgc::id::DeviceId,
125117
}
126118

127119
/// A handle to a texture on the GPU.
128-
#[derive(Debug, PartialEq)]
120+
#[derive(Debug, PartialEq, Eq)]
129121
pub struct Texture {
130122
id: wgc::id::TextureId,
131123
owned: bool,
@@ -135,7 +127,7 @@ pub struct Texture {
135127
///
136128
/// A `TextureView` object describes a texture and associated metadata needed by a
137129
/// [`RenderPipeline`] or [`BindGroup`].
138-
#[derive(Debug, PartialEq)]
130+
#[derive(Debug, PartialEq, Eq)]
139131
pub struct TextureView {
140132
id: wgc::id::TextureViewId,
141133
owned: bool,
@@ -146,7 +138,7 @@ pub struct TextureView {
146138
/// A `Sampler` object defines how a pipeline will sample from a [`TextureView`]. Samplers define
147139
/// image filters (including anisotropy) and address (wrapping) modes, among other things. See
148140
/// the documentation for [`SamplerDescriptor`] for more information.
149-
#[derive(Debug, PartialEq)]
141+
#[derive(Debug, PartialEq, Eq)]
150142
pub struct Sampler {
151143
id: wgc::id::SamplerId,
152144
}
@@ -155,7 +147,7 @@ pub struct Sampler {
155147
///
156148
/// A `Surface` represents a platform-specific surface (e.g. a window) to which rendered images may
157149
/// be presented. A `Surface` may be created with [`Surface::create`].
158-
#[derive(Debug, PartialEq)]
150+
#[derive(Debug, PartialEq, Eq)]
159151
pub struct Surface {
160152
id: wgc::id::SurfaceId,
161153
}
@@ -164,7 +156,7 @@ pub struct Surface {
164156
///
165157
/// A `SwapChain` represents the image or series of images that will be presented to a [`Surface`].
166158
/// A `SwapChain` may be created with [`Device::create_swap_chain`].
167-
#[derive(Debug, PartialEq)]
159+
#[derive(Debug, PartialEq, Eq)]
168160
pub struct SwapChain {
169161
id: wgc::id::SwapChainId,
170162
}
@@ -175,7 +167,7 @@ pub struct SwapChain {
175167
/// create a [`BindGroupDescriptor`] object, which in turn can be used to create a [`BindGroup`]
176168
/// object with [`Device::create_bind_group`]. A series of `BindGroupLayout`s can also be used to
177169
/// create a [`PipelineLayoutDescriptor`], which can be used to create a [`PipelineLayout`].
178-
#[derive(Debug, PartialEq)]
170+
#[derive(Debug, PartialEq, Eq)]
179171
pub struct BindGroupLayout {
180172
id: wgc::id::BindGroupLayoutId,
181173
}
@@ -186,7 +178,7 @@ pub struct BindGroupLayout {
186178
/// [`BindGroupLayout`]. It can be created with [`Device::create_bind_group`]. A `BindGroup` can
187179
/// be bound to a particular [`RenderPass`] with [`RenderPass::set_bind_group`], or to a
188180
/// [`ComputePass`] with [`ComputePass::set_bind_group`].
189-
#[derive(Debug, PartialEq)]
181+
#[derive(Debug, PartialEq, Eq)]
190182
pub struct BindGroup {
191183
id: wgc::id::BindGroupId,
192184
}
@@ -202,15 +194,15 @@ impl Drop for BindGroup {
202194
/// A `ShaderModule` represents a compiled shader module on the GPU. It can be created by passing
203195
/// valid SPIR-V source code to [`Device::create_shader_module`]. Shader modules are used to define
204196
/// programmable stages of a pipeline.
205-
#[derive(Debug, PartialEq)]
197+
#[derive(Debug, PartialEq, Eq)]
206198
pub struct ShaderModule {
207199
id: wgc::id::ShaderModuleId,
208200
}
209201

210202
/// An opaque handle to a pipeline layout.
211203
///
212204
/// A `PipelineLayout` object describes the available binding groups of a pipeline.
213-
#[derive(Debug, PartialEq)]
205+
#[derive(Debug, PartialEq, Eq)]
214206
pub struct PipelineLayout {
215207
id: wgc::id::PipelineLayoutId,
216208
}
@@ -219,13 +211,13 @@ pub struct PipelineLayout {
219211
///
220212
/// A `RenderPipeline` object represents a graphics pipeline and its stages, bindings, vertex
221213
/// buffers and targets. A `RenderPipeline` may be created with [`Device::create_render_pipeline`].
222-
#[derive(Debug, PartialEq)]
214+
#[derive(Debug, PartialEq, Eq)]
223215
pub struct RenderPipeline {
224216
id: wgc::id::RenderPipelineId,
225217
}
226218

227219
/// A handle to a compute pipeline.
228-
#[derive(Debug, PartialEq)]
220+
#[derive(Debug, PartialEq, Eq)]
229221
pub struct ComputePipeline {
230222
id: wgc::id::ComputePipelineId,
231223
}
@@ -235,7 +227,7 @@ pub struct ComputePipeline {
235227
/// A `CommandBuffer` represents a complete sequence of commands that may be submitted to a command
236228
/// queue with [`Queue::submit`]. A `CommandBuffer` is obtained by recording a series of commands to
237229
/// a [`CommandEncoder`] and then calling [`CommandEncoder::finish`].
238-
#[derive(Debug, PartialEq)]
230+
#[derive(Debug, PartialEq, Eq)]
239231
pub struct CommandBuffer {
240232
id: wgc::id::CommandBufferId,
241233
}
@@ -247,7 +239,7 @@ pub struct CommandBuffer {
247239
///
248240
/// When finished recording, call [`CommandEncoder::finish`] to obtain a [`CommandBuffer`] which may
249241
/// be submitted for execution.
250-
#[derive(Debug)]
242+
#[derive(Debug, PartialEq, Eq)]
251243
pub struct CommandEncoder {
252244
id: wgc::id::CommandEncoderId,
253245
/// This type should be !Send !Sync, because it represents an allocation on this thread's
@@ -256,14 +248,14 @@ pub struct CommandEncoder {
256248
}
257249

258250
/// An in-progress recording of a render pass.
259-
#[derive(Debug)]
251+
#[derive(Debug, PartialEq, Eq)]
260252
pub struct RenderPass<'a> {
261253
id: wgc::id::RenderPassId,
262254
_parent: &'a mut CommandEncoder,
263255
}
264256

265257
/// An in-progress recording of a compute pass.
266-
#[derive(Debug)]
258+
#[derive(Debug, PartialEq, Eq)]
267259
pub struct ComputePass<'a> {
268260
id: wgc::id::ComputePassId,
269261
_parent: &'a mut CommandEncoder,
@@ -272,13 +264,13 @@ pub struct ComputePass<'a> {
272264
/// A handle to a command queue on a device.
273265
///
274266
/// A `Queue` executes recorded [`CommandBuffer`] objects.
275-
#[derive(Debug, PartialEq)]
267+
#[derive(Debug, PartialEq, Eq)]
276268
pub struct Queue {
277269
id: wgc::id::QueueId,
278270
}
279271

280272
/// A resource that can be bound to a pipeline.
281-
#[derive(Clone, Debug)]
273+
#[derive(Clone, Debug, PartialEq, Eq)]
282274
pub enum BindingResource<'a> {
283275
Buffer {
284276
buffer: &'a Buffer,
@@ -289,7 +281,7 @@ pub enum BindingResource<'a> {
289281
}
290282

291283
/// A bindable resource and the slot to bind it to.
292-
#[derive(Clone, Debug)]
284+
#[derive(Clone, Debug, PartialEq, Eq)]
293285
pub struct Binding<'a> {
294286
pub binding: u32,
295287
pub resource: BindingResource<'a>,
@@ -322,15 +314,15 @@ pub enum BindingType {
322314
}
323315

324316
/// A description of a single binding inside a bind group.
325-
#[derive(Clone, Debug, Hash)]
317+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
326318
pub struct BindGroupLayoutEntry {
327319
pub binding: u32,
328320
pub visibility: ShaderStage,
329321
pub ty: BindingType,
330322
}
331323

332324
/// A description of a bind group layout.
333-
#[derive(Clone, Debug)]
325+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
334326
pub struct BindGroupLayoutDescriptor<'a> {
335327
pub bindings: &'a [BindGroupLayoutEntry],
336328

@@ -340,7 +332,7 @@ pub struct BindGroupLayoutDescriptor<'a> {
340332
}
341333

342334
/// A description of a group of bindings and the resources to be bound.
343-
#[derive(Clone, Debug)]
335+
#[derive(Clone, Debug, PartialEq, Eq)]
344336
pub struct BindGroupDescriptor<'a> {
345337
/// The layout for this bind group.
346338
pub layout: &'a BindGroupLayout,
@@ -357,13 +349,13 @@ pub struct BindGroupDescriptor<'a> {
357349
///
358350
/// A `PipelineLayoutDescriptor` can be passed to [`Device::create_pipeline_layout`] to obtain a
359351
/// [`PipelineLayout`].
360-
#[derive(Clone, Debug)]
352+
#[derive(Clone, Debug, PartialEq, Eq)]
361353
pub struct PipelineLayoutDescriptor<'a> {
362354
pub bind_group_layouts: &'a [&'a BindGroupLayout],
363355
}
364356

365357
/// A description of a programmable pipeline stage.
366-
#[derive(Clone, Debug)]
358+
#[derive(Clone, Debug, PartialEq, Eq)]
367359
pub struct ProgrammableStageDescriptor<'a> {
368360
/// The compiled shader module for this stage.
369361
pub module: &'a ShaderModule,
@@ -383,7 +375,7 @@ pub struct VertexStateDescriptor<'a> {
383375
}
384376

385377
/// A description of a vertex buffer.
386-
#[derive(Clone, Debug)]
378+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
387379
pub struct VertexBufferDescriptor<'a> {
388380
/// The stride, in bytes, between elements of this buffer.
389381
pub stride: BufferAddress,
@@ -513,14 +505,14 @@ pub struct TextureDescriptor<'a> {
513505
}
514506

515507
/// A swap chain image that can be rendered to.
516-
#[derive(Debug)]
508+
#[derive(Debug, PartialEq, Eq)]
517509
pub struct SwapChainOutput {
518510
pub view: TextureView,
519511
swap_chain_id: wgc::id::SwapChainId,
520512
}
521513

522514
/// A view of a buffer which can be used to copy to or from a texture.
523-
#[derive(Clone, Debug)]
515+
#[derive(Clone, Debug, PartialEq, Eq)]
524516
pub struct BufferCopyView<'a> {
525517
/// The buffer to be copied to or from.
526518
pub buffer: &'a Buffer,
@@ -550,7 +542,7 @@ impl BufferCopyView<'_> {
550542
}
551543

552544
/// A view of a texture which can be used to copy to or from a buffer or another texture.
553-
#[derive(Clone, Debug)]
545+
#[derive(Clone, Debug, PartialEq, Eq)]
554546
pub struct TextureCopyView<'a> {
555547
/// The texture to be copied to or from.
556548
pub texture: &'a Texture,
@@ -654,7 +646,6 @@ impl Adapter {
654646
pub async fn request_device(&self, desc: &DeviceDescriptor) -> (Device, Queue) {
655647
let device = Device {
656648
id: wgn::wgpu_adapter_request_device(self.id, Some(desc)),
657-
temp: Temp::default(),
658649
};
659650
let queue = Queue {
660651
id: wgn::wgpu_device_get_default_queue(device.id),

0 commit comments

Comments
 (0)