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

Commit ea2a737

Browse files
committed
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.
1 parent 80d7817 commit ea2a737

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

src/lib.rs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ impl std::hash::Hash for Temp {
9999
///
100100
/// An `Adapter` can be used to open a connection to the corresponding device on the host system,
101101
/// yielding a [`Device`] object.
102-
#[derive(Debug, PartialEq, Eq, Hash)]
102+
#[derive(Debug, PartialEq, Eq)]
103+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
103104
pub struct Adapter {
104105
id: wgc::id::AdapterId,
105106
}
@@ -117,7 +118,8 @@ pub struct RequestAdapterOptions<'a> {
117118
///
118119
/// The `Device` is the responsible for the creation of most rendering and compute resources, as
119120
/// well as exposing [`Queue`] objects.
120-
#[derive(Debug, PartialEq, Eq, Hash)]
121+
#[derive(Debug, PartialEq, Eq)]
122+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
121123
pub struct Device {
122124
id: wgc::id::DeviceId,
123125
temp: Temp,
@@ -132,14 +134,16 @@ pub enum Maintain {
132134
}
133135

134136
/// A handle to a GPU-accessible buffer.
135-
#[derive(Debug, PartialEq, Eq, Hash)]
137+
#[derive(Debug, PartialEq, Eq)]
138+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
136139
pub struct Buffer {
137140
id: wgc::id::BufferId,
138141
device_id: wgc::id::DeviceId,
139142
}
140143

141144
/// A handle to a texture on the GPU.
142-
#[derive(Debug, PartialEq, Eq, Hash)]
145+
#[derive(Debug, PartialEq, Eq)]
146+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
143147
pub struct Texture {
144148
id: wgc::id::TextureId,
145149
owned: bool,
@@ -149,7 +153,8 @@ pub struct Texture {
149153
///
150154
/// A `TextureView` object describes a texture and associated metadata needed by a
151155
/// [`RenderPipeline`] or [`BindGroup`].
152-
#[derive(Debug, PartialEq, Eq, Hash)]
156+
#[derive(Debug, PartialEq, Eq)]
157+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
153158
pub struct TextureView {
154159
id: wgc::id::TextureViewId,
155160
owned: bool,
@@ -160,7 +165,8 @@ pub struct TextureView {
160165
/// A `Sampler` object defines how a pipeline will sample from a [`TextureView`]. Samplers define
161166
/// image filters (including anisotropy) and address (wrapping) modes, among other things. See
162167
/// the documentation for [`SamplerDescriptor`] for more information.
163-
#[derive(Debug, PartialEq, Eq, Hash)]
168+
#[derive(Debug, PartialEq, Eq)]
169+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
164170
pub struct Sampler {
165171
id: wgc::id::SamplerId,
166172
}
@@ -169,7 +175,8 @@ pub struct Sampler {
169175
///
170176
/// A `Surface` represents a platform-specific surface (e.g. a window) to which rendered images may
171177
/// be presented. A `Surface` may be created with [`Surface::create`].
172-
#[derive(Debug, PartialEq)]
178+
#[derive(Debug, PartialEq, Eq)]
179+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
173180
pub struct Surface {
174181
id: wgc::id::SurfaceId,
175182
}
@@ -178,7 +185,8 @@ pub struct Surface {
178185
///
179186
/// A `SwapChain` represents the image or series of images that will be presented to a [`Surface`].
180187
/// A `SwapChain` may be created with [`Device::create_swap_chain`].
181-
#[derive(Debug, PartialEq)]
188+
#[derive(Debug, PartialEq, Eq)]
189+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
182190
pub struct SwapChain {
183191
id: wgc::id::SwapChainId,
184192
}
@@ -189,7 +197,8 @@ pub struct SwapChain {
189197
/// create a [`BindGroupDescriptor`] object, which in turn can be used to create a [`BindGroup`]
190198
/// object with [`Device::create_bind_group`]. A series of `BindGroupLayout`s can also be used to
191199
/// create a [`PipelineLayoutDescriptor`], which can be used to create a [`PipelineLayout`].
192-
#[derive(Debug, PartialEq, Eq, Hash)]
200+
#[derive(Debug, PartialEq, Eq)]
201+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
193202
pub struct BindGroupLayout {
194203
id: wgc::id::BindGroupLayoutId,
195204
}
@@ -200,7 +209,8 @@ pub struct BindGroupLayout {
200209
/// [`BindGroupLayout`]. It can be created with [`Device::create_bind_group`]. A `BindGroup` can
201210
/// be bound to a particular [`RenderPass`] with [`RenderPass::set_bind_group`], or to a
202211
/// [`ComputePass`] with [`ComputePass::set_bind_group`].
203-
#[derive(Debug, PartialEq, Eq, Hash)]
212+
#[derive(Debug, PartialEq, Eq)]
213+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
204214
pub struct BindGroup {
205215
id: wgc::id::BindGroupId,
206216
}
@@ -216,15 +226,17 @@ impl Drop for BindGroup {
216226
/// A `ShaderModule` represents a compiled shader module on the GPU. It can be created by passing
217227
/// valid SPIR-V source code to [`Device::create_shader_module`]. Shader modules are used to define
218228
/// programmable stages of a pipeline.
219-
#[derive(Debug, PartialEq, Eq, Hash)]
229+
#[derive(Debug, PartialEq, Eq)]
230+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
220231
pub struct ShaderModule {
221232
id: wgc::id::ShaderModuleId,
222233
}
223234

224235
/// An opaque handle to a pipeline layout.
225236
///
226237
/// A `PipelineLayout` object describes the available binding groups of a pipeline.
227-
#[derive(Debug, PartialEq, Eq, Hash)]
238+
#[derive(Debug, PartialEq, Eq)]
239+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
228240
pub struct PipelineLayout {
229241
id: wgc::id::PipelineLayoutId,
230242
}
@@ -233,13 +245,15 @@ pub struct PipelineLayout {
233245
///
234246
/// A `RenderPipeline` object represents a graphics pipeline and its stages, bindings, vertex
235247
/// buffers and targets. A `RenderPipeline` may be created with [`Device::create_render_pipeline`].
236-
#[derive(Debug, PartialEq)]
248+
#[derive(Debug, PartialEq, Eq)]
249+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
237250
pub struct RenderPipeline {
238251
id: wgc::id::RenderPipelineId,
239252
}
240253

241254
/// A handle to a compute pipeline.
242-
#[derive(Debug, PartialEq)]
255+
#[derive(Debug, PartialEq, Eq)]
256+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
243257
pub struct ComputePipeline {
244258
id: wgc::id::ComputePipelineId,
245259
}
@@ -249,7 +263,8 @@ pub struct ComputePipeline {
249263
/// A `CommandBuffer` represents a complete sequence of commands that may be submitted to a command
250264
/// queue with [`Queue::submit`]. A `CommandBuffer` is obtained by recording a series of commands to
251265
/// a [`CommandEncoder`] and then calling [`CommandEncoder::finish`].
252-
#[derive(Debug, PartialEq, Eq, Hash)]
266+
#[derive(Debug, PartialEq, Eq)]
267+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
253268
pub struct CommandBuffer {
254269
id: wgc::id::CommandBufferId,
255270
}
@@ -261,7 +276,8 @@ pub struct CommandBuffer {
261276
///
262277
/// When finished recording, call [`CommandEncoder::finish`] to obtain a [`CommandBuffer`] which may
263278
/// be submitted for execution.
264-
#[derive(Debug, PartialEq, Eq, Hash)]
279+
#[derive(Debug, PartialEq, Eq)]
280+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
265281
pub struct CommandEncoder {
266282
id: wgc::id::CommandEncoderId,
267283
/// This type should be !Send !Sync, because it represents an allocation on this thread's
@@ -286,7 +302,8 @@ pub struct ComputePass<'a> {
286302
/// A handle to a command queue on a device.
287303
///
288304
/// A `Queue` executes recorded [`CommandBuffer`] objects.
289-
#[derive(Debug, PartialEq)]
305+
#[derive(Debug, PartialEq, Eq)]
306+
#[cfg_attr(not(target_arch = "wasm32"), derive(Hash))]
290307
pub struct Queue {
291308
id: wgc::id::QueueId,
292309
}

0 commit comments

Comments
 (0)