1extern crate gfx_hal as hal;
5
6use crate::{
7 buffer::Buffer,
8 descriptor::{DescriptorPool, DescriptorSet, DescriptorSetLayout},
9 image::Image,
10 memory::Memory,
11};
12
13use hal::{adapter, command, device, display, format, pass, pool, pso, query, queue, window};
14use log::debug;
15
16use std::{borrow::Borrow, ops::Range};
17
18mod buffer;
19mod descriptor;
20mod image;
21mod memory;
22
23const NOT_SUPPORTED_MESSAGE: &str = "This function is not currently mocked by the empty backend";
24
25#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
27pub enum Backend {}
28impl hal::Backend for Backend {
29 type Instance = Instance;
30 type PhysicalDevice = PhysicalDevice;
31 type Device = Device;
32 type Surface = Surface;
33
34 type QueueFamily = QueueFamily;
35 type Queue = Queue;
36 type CommandBuffer = CommandBuffer;
37
38 type Memory = Memory;
39 type CommandPool = CommandPool;
40
41 type ShaderModule = ();
42 type RenderPass = ();
43 type Framebuffer = ();
44
45 type Buffer = Buffer;
46 type BufferView = ();
47 type Image = Image;
48 type ImageView = ();
49 type Sampler = ();
50
51 type ComputePipeline = ();
52 type GraphicsPipeline = ();
53 type PipelineCache = ();
54 type PipelineLayout = ();
55 type DescriptorSetLayout = DescriptorSetLayout;
56 type DescriptorPool = DescriptorPool;
57 type DescriptorSet = DescriptorSet;
58
59 type Fence = ();
60 type Semaphore = ();
61 type Event = ();
62 type QueryPool = ();
63
64 type Display = ();
65 type DisplayMode = ();
66}
67
68#[derive(Debug)]
70pub struct PhysicalDevice;
71impl adapter::PhysicalDevice<Backend> for PhysicalDevice {
72 unsafe fn open(
73 &self,
74 families: &[(&QueueFamily, &[queue::QueuePriority])],
75 _requested_features: hal::Features,
76 ) -> Result<adapter::Gpu<Backend>, device::CreationError> {
77 assert_eq!(
79 families.len(),
80 1,
81 "Empty backend doesn't have multiple queue families"
82 );
83 let (_family, priorities) = families[0];
84 assert_eq!(
85 priorities.len(),
86 1,
87 "Empty backend doesn't support multiple queues"
88 );
89 let priority = priorities[0];
90 assert!(
91 0.0 <= priority && priority <= 1.0,
92 "Queue priority is out of range"
93 );
94
95 let queue_groups = {
97 let mut queue_group = queue::QueueGroup::new(QUEUE_FAMILY_ID);
98 queue_group.add_queue(Queue);
99 vec![queue_group]
100 };
101 let gpu = adapter::Gpu {
102 device: Device,
103 queue_groups,
104 };
105 Ok(gpu)
106 }
107
108 fn format_properties(&self, _: Option<format::Format>) -> format::Properties {
109 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
110 }
111
112 fn image_format_properties(
113 &self,
114 _: format::Format,
115 _dim: u8,
116 _: hal::image::Tiling,
117 _: hal::image::Usage,
118 _: hal::image::ViewCapabilities,
119 ) -> Option<hal::image::FormatProperties> {
120 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
121 }
122
123 fn memory_properties(&self) -> adapter::MemoryProperties {
124 let memory_types = {
125 use hal::memory::Properties;
126 let properties = Properties::DEVICE_LOCAL
127 | Properties::CPU_VISIBLE
128 | Properties::COHERENT
129 | Properties::CPU_CACHED;
130 let memory_type = adapter::MemoryType {
131 properties,
132 heap_index: 0,
133 };
134 vec![memory_type]
135 };
136 let memory_heaps = vec![adapter::MemoryHeap {
138 size: 64 * 1024,
139 flags: hal::memory::HeapFlags::empty(),
140 }];
141 adapter::MemoryProperties {
142 memory_types,
143 memory_heaps,
144 }
145 }
146
147 fn external_buffer_properties(
148 &self,
149 _usage: hal::buffer::Usage,
150 _sparse: hal::memory::SparseFlags,
151 _memory_type: hal::external_memory::ExternalMemoryType,
152 ) -> hal::external_memory::ExternalMemoryProperties {
153 unimplemented!()
154 }
155
156 fn external_image_properties(
157 &self,
158 _format: hal::format::Format,
159 _dimensions: u8,
160 _tiling: hal::image::Tiling,
161 _usage: hal::image::Usage,
162 _view_caps: hal::image::ViewCapabilities,
163 _memory_type: hal::external_memory::ExternalMemoryType,
164 ) -> Result<
165 hal::external_memory::ExternalMemoryProperties,
166 hal::external_memory::ExternalImagePropertiesError,
167 > {
168 unimplemented!()
169 }
170
171 fn features(&self) -> hal::Features {
172 hal::Features::empty()
173 }
174
175 fn properties(&self) -> hal::PhysicalDeviceProperties {
176 hal::PhysicalDeviceProperties {
177 limits: hal::Limits {
178 non_coherent_atom_size: 1,
179 optimal_buffer_copy_pitch_alignment: 1,
180 ..Default::default()
181 },
182 ..Default::default()
183 }
184 }
185
186 unsafe fn enumerate_displays(&self) -> Vec<display::Display<Backend>> {
187 unimplemented!();
188 }
189
190 unsafe fn enumerate_compatible_planes(
191 &self,
192 _display: &display::Display<Backend>,
193 ) -> Vec<display::Plane> {
194 unimplemented!();
195 }
196
197 unsafe fn create_display_mode(
198 &self,
199 _display: &display::Display<Backend>,
200 _resolution: (u32, u32),
201 _refresh_rate: u32,
202 ) -> Result<display::DisplayMode<Backend>, display::DisplayModeError> {
203 unimplemented!();
204 }
205
206 unsafe fn create_display_plane<'a>(
207 &self,
208 _display: &'a display::DisplayMode<Backend>,
209 _plane: &'a display::Plane,
210 ) -> Result<display::DisplayPlane<'a, Backend>, device::OutOfMemory> {
211 unimplemented!();
212 }
213}
214
215#[derive(Debug)]
217pub struct Queue;
218impl queue::Queue<Backend> for Queue {
219 unsafe fn submit<'a, Ic, Iw, Is>(&mut self, _: Ic, _: Iw, _: Is, _: Option<&mut ()>)
220 where
221 Ic: Iterator<Item = &'a CommandBuffer>,
222 {
223 }
224
225 unsafe fn present(
226 &mut self,
227 _surface: &mut Surface,
228 _image: SwapchainImage,
229 _wait_semaphore: Option<&mut ()>,
230 ) -> Result<Option<window::Suboptimal>, window::PresentError> {
231 Ok(None)
232 }
233
234 fn wait_idle(&mut self) -> Result<(), device::OutOfMemory> {
235 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
236 }
237
238 fn timestamp_period(&self) -> f32 {
239 1.0
240 }
241}
242
243#[derive(Debug)]
245pub struct Device;
246impl device::Device<Backend> for Device {
247 unsafe fn create_command_pool(
248 &self,
249 _: queue::QueueFamilyId,
250 _: pool::CommandPoolCreateFlags,
251 ) -> Result<CommandPool, device::OutOfMemory> {
252 Ok(CommandPool)
253 }
254
255 unsafe fn destroy_command_pool(&self, _: CommandPool) {}
256
257 unsafe fn allocate_memory(
258 &self,
259 memory_type: hal::MemoryTypeId,
260 size: u64,
261 ) -> Result<Memory, device::AllocationError> {
262 Memory::allocate(memory_type, size)
263 }
264
265 unsafe fn create_render_pass<'a, Ia, Is, Id>(
266 &self,
267 _: Ia,
268 _: Is,
269 _: Id,
270 ) -> Result<(), device::OutOfMemory>
271 where
272 Is: Iterator<Item = pass::SubpassDesc<'a>>,
273 {
274 Ok(())
275 }
276
277 unsafe fn create_pipeline_layout<'a, Is, Ic>(
278 &self,
279 _: Is,
280 _: Ic,
281 ) -> Result<(), device::OutOfMemory>
282 where
283 Is: Iterator<Item = &'a DescriptorSetLayout>,
284 {
285 Ok(())
286 }
287
288 unsafe fn create_pipeline_cache(
289 &self,
290 _data: Option<&[u8]>,
291 ) -> Result<(), device::OutOfMemory> {
292 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
293 }
294
295 unsafe fn get_pipeline_cache_data(&self, _cache: &()) -> Result<Vec<u8>, device::OutOfMemory> {
296 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
297 }
298
299 unsafe fn destroy_pipeline_cache(&self, _: ()) {
300 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
301 }
302
303 unsafe fn create_graphics_pipeline<'a>(
304 &self,
305 _: &pso::GraphicsPipelineDesc<'a, Backend>,
306 _: Option<&()>,
307 ) -> Result<(), pso::CreationError> {
308 Ok(())
309 }
310
311 unsafe fn create_compute_pipeline<'a>(
312 &self,
313 _: &pso::ComputePipelineDesc<'a, Backend>,
314 _: Option<&()>,
315 ) -> Result<(), pso::CreationError> {
316 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
317 }
318
319 unsafe fn merge_pipeline_caches<'a, I>(
320 &self,
321 _: &mut (),
322 _: I,
323 ) -> Result<(), device::OutOfMemory>
324 where
325 I: Iterator<Item = &'a ()>,
326 {
327 Ok(())
328 }
329
330 unsafe fn create_framebuffer<I>(
331 &self,
332 _: &(),
333 _: I,
334 _: hal::image::Extent,
335 ) -> Result<(), device::OutOfMemory> {
336 Ok(())
337 }
338
339 unsafe fn create_shader_module(&self, _: &[u32]) -> Result<(), device::ShaderError> {
340 Ok(())
341 }
342
343 unsafe fn create_sampler(
344 &self,
345 _: &hal::image::SamplerDesc,
346 ) -> Result<(), device::AllocationError> {
347 Ok(())
348 }
349
350 unsafe fn create_buffer(
351 &self,
352 size: u64,
353 _: hal::buffer::Usage,
354 _: hal::memory::SparseFlags,
355 ) -> Result<Buffer, hal::buffer::CreationError> {
356 Ok(Buffer::new(size))
357 }
358
359 unsafe fn get_buffer_requirements(&self, buffer: &Buffer) -> hal::memory::Requirements {
360 hal::memory::Requirements {
361 size: buffer.size,
362 alignment: 1,
364 type_mask: !0,
365 }
366 }
367
368 unsafe fn bind_buffer_memory(
369 &self,
370 _memory: &Memory,
371 _: u64,
372 _: &mut Buffer,
373 ) -> Result<(), device::BindError> {
374 Ok(())
375 }
376
377 unsafe fn create_buffer_view(
378 &self,
379 _: &Buffer,
380 _: Option<format::Format>,
381 _: hal::buffer::SubRange,
382 ) -> Result<(), hal::buffer::ViewCreationError> {
383 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
384 }
385
386 unsafe fn create_image(
387 &self,
388 kind: hal::image::Kind,
389 _: hal::image::Level,
390 _: format::Format,
391 _: hal::image::Tiling,
392 _: hal::image::Usage,
393 _: hal::memory::SparseFlags,
394 _: hal::image::ViewCapabilities,
395 ) -> Result<Image, hal::image::CreationError> {
396 Ok(Image::new(kind))
397 }
398
399 unsafe fn get_image_requirements(&self, image: &Image) -> hal::memory::Requirements {
400 image.get_requirements()
401 }
402
403 unsafe fn get_image_subresource_footprint(
404 &self,
405 _: &Image,
406 _: hal::image::Subresource,
407 ) -> hal::image::SubresourceFootprint {
408 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
409 }
410
411 unsafe fn bind_image_memory(
412 &self,
413 _memory: &Memory,
414 _: u64,
415 _: &mut Image,
416 ) -> Result<(), device::BindError> {
417 Ok(())
418 }
419
420 unsafe fn create_image_view(
421 &self,
422 _: &Image,
423 _: hal::image::ViewKind,
424 _: format::Format,
425 _: format::Swizzle,
426 _: hal::image::Usage,
427 _: hal::image::SubresourceRange,
428 ) -> Result<(), hal::image::ViewCreationError> {
429 Ok(())
430 }
431
432 unsafe fn create_descriptor_pool<I>(
433 &self,
434 _: usize,
435 _: I,
436 _: pso::DescriptorPoolCreateFlags,
437 ) -> Result<DescriptorPool, device::OutOfMemory> {
438 Ok(DescriptorPool)
439 }
440
441 unsafe fn create_descriptor_set_layout<'a, I, J>(
442 &self,
443 _bindings: I,
444 _samplers: J,
445 ) -> Result<DescriptorSetLayout, device::OutOfMemory>
446 where
447 J: Iterator<Item = &'a ()>,
448 {
449 let layout = DescriptorSetLayout {
450 name: String::new(),
451 };
452 Ok(layout)
453 }
454
455 unsafe fn write_descriptor_set<'a, I>(&self, _: pso::DescriptorSetWrite<'a, Backend, I>)
456 where
457 I: Iterator<Item = pso::Descriptor<'a, Backend>>,
458 {
459 }
460
461 unsafe fn copy_descriptor_set<'a>(&self, _: pso::DescriptorSetCopy<'a, Backend>) {
462 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
463 }
464
465 fn create_semaphore(&self) -> Result<(), device::OutOfMemory> {
466 Ok(())
467 }
468
469 fn create_fence(&self, _: bool) -> Result<(), device::OutOfMemory> {
470 Ok(())
471 }
472
473 unsafe fn get_fence_status(&self, _: &()) -> Result<bool, device::DeviceLost> {
474 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
475 }
476
477 fn create_event(&self) -> Result<(), device::OutOfMemory> {
478 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
479 }
480
481 unsafe fn get_event_status(&self, _: &()) -> Result<bool, device::WaitError> {
482 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
483 }
484
485 unsafe fn set_event(&self, _: &mut ()) -> Result<(), device::OutOfMemory> {
486 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
487 }
488
489 unsafe fn reset_event(&self, _: &mut ()) -> Result<(), device::OutOfMemory> {
490 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
491 }
492
493 unsafe fn create_query_pool(&self, _: query::Type, _: u32) -> Result<(), query::CreationError> {
494 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
495 }
496
497 unsafe fn destroy_query_pool(&self, _: ()) {
498 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
499 }
500
501 unsafe fn get_query_pool_results(
502 &self,
503 _: &(),
504 _: Range<query::Id>,
505 _: &mut [u8],
506 _: hal::buffer::Stride,
507 _: query::ResultFlags,
508 ) -> Result<bool, device::WaitError> {
509 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
510 }
511
512 unsafe fn map_memory(
513 &self,
514 memory: &mut Memory,
515 segment: hal::memory::Segment,
516 ) -> Result<*mut u8, device::MapError> {
517 memory.map(segment)
518 }
519
520 unsafe fn unmap_memory(&self, _memory: &mut Memory) {}
521
522 unsafe fn flush_mapped_memory_ranges<'a, I>(&self, _: I) -> Result<(), device::OutOfMemory>
523 where
524 I: Iterator<Item = (&'a Memory, hal::memory::Segment)>,
525 {
526 Ok(())
527 }
528
529 unsafe fn invalidate_mapped_memory_ranges<'a, I>(&self, _: I) -> Result<(), device::OutOfMemory>
530 where
531 I: Iterator<Item = (&'a Memory, hal::memory::Segment)>,
532 {
533 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
534 }
535
536 unsafe fn free_memory(&self, _memory: Memory) {
537 }
539
540 unsafe fn destroy_shader_module(&self, _: ()) {}
541
542 unsafe fn destroy_render_pass(&self, _: ()) {}
543
544 unsafe fn destroy_pipeline_layout(&self, _: ()) {}
545
546 unsafe fn destroy_graphics_pipeline(&self, _: ()) {}
547
548 unsafe fn destroy_compute_pipeline(&self, _: ()) {
549 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
550 }
551 unsafe fn destroy_framebuffer(&self, _: ()) {}
552
553 unsafe fn destroy_buffer(&self, _: Buffer) {}
554
555 unsafe fn destroy_buffer_view(&self, _: ()) {
556 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
557 }
558
559 unsafe fn destroy_image(&self, _: Image) {}
560
561 unsafe fn destroy_image_view(&self, _: ()) {}
562
563 unsafe fn destroy_sampler(&self, _: ()) {}
564
565 unsafe fn destroy_descriptor_pool(&self, _: DescriptorPool) {}
566
567 unsafe fn destroy_descriptor_set_layout(&self, _: DescriptorSetLayout) {}
568
569 unsafe fn destroy_fence(&self, _: ()) {}
570
571 unsafe fn destroy_semaphore(&self, _: ()) {}
572
573 unsafe fn destroy_event(&self, _: ()) {
574 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
575 }
576
577 fn wait_idle(&self) -> Result<(), device::OutOfMemory> {
578 Ok(())
579 }
580
581 unsafe fn set_image_name(&self, _: &mut Image, _: &str) {
582 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
583 }
584
585 unsafe fn set_buffer_name(&self, _: &mut Buffer, _: &str) {
586 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
587 }
588
589 unsafe fn set_command_buffer_name(&self, _: &mut CommandBuffer, _: &str) {
590 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
591 }
592
593 unsafe fn set_semaphore_name(&self, _: &mut (), _: &str) {
594 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
595 }
596
597 unsafe fn set_fence_name(&self, _: &mut (), _: &str) {
598 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
599 }
600
601 unsafe fn set_framebuffer_name(&self, _: &mut (), _: &str) {
602 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
603 }
604
605 unsafe fn set_render_pass_name(&self, _: &mut (), _: &str) {
606 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
607 }
608
609 unsafe fn set_descriptor_set_name(&self, set: &mut DescriptorSet, name: &str) {
610 set.name = name.to_string();
611 }
612
613 unsafe fn set_descriptor_set_layout_name(&self, layout: &mut DescriptorSetLayout, name: &str) {
614 layout.name = name.to_string();
615 }
616
617 unsafe fn set_pipeline_layout_name(&self, _pipeline_layout: &mut (), _name: &str) {
618 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
619 }
620
621 unsafe fn create_allocate_external_buffer(
622 &self,
623 _external_memory_type: hal::external_memory::ExternalBufferMemoryType,
624 _usage: hal::buffer::Usage,
625 _sparse: hal::memory::SparseFlags,
626 _type_mask: u32,
627 _size: u64,
628 ) -> Result<
629 (
630 <Backend as gfx_hal::Backend>::Buffer,
631 <Backend as gfx_hal::Backend>::Memory,
632 ),
633 hal::external_memory::ExternalResourceError,
634 > {
635 unimplemented!()
636 }
637
638 unsafe fn import_external_buffer(
639 &self,
640 _external_memory: hal::external_memory::ExternalBufferMemory,
641 _usage: hal::buffer::Usage,
642 _sparse: hal::memory::SparseFlags,
643 _type_mask: u32,
644 _size: u64,
645 ) -> Result<
646 (
647 <Backend as gfx_hal::Backend>::Buffer,
648 <Backend as gfx_hal::Backend>::Memory,
649 ),
650 hal::external_memory::ExternalResourceError,
651 > {
652 unimplemented!()
653 }
654
655 unsafe fn create_allocate_external_image(
656 &self,
657 _external_memory_type: hal::external_memory::ExternalImageMemoryType,
658 _kind: hal::image::Kind,
659 _num_levels: hal::image::Level,
660 _format: hal::format::Format,
661 _tiling: hal::image::Tiling,
662 _usage: hal::image::Usage,
663 _sparse: hal::memory::SparseFlags,
664 _view_caps: hal::image::ViewCapabilities,
665 _type_mask: u32,
666 ) -> Result<
667 (
668 <Backend as gfx_hal::Backend>::Image,
669 <Backend as gfx_hal::Backend>::Memory,
670 ),
671 hal::external_memory::ExternalResourceError,
672 > {
673 unimplemented!()
674 }
675
676 unsafe fn import_external_image(
677 &self,
678 _external_memory: hal::external_memory::ExternalImageMemory,
679 _kind: hal::image::Kind,
680 _num_levels: hal::image::Level,
681 _format: hal::format::Format,
682 _tiling: hal::image::Tiling,
683 _usage: hal::image::Usage,
684 _sparse: hal::memory::SparseFlags,
685 _view_caps: hal::image::ViewCapabilities,
686 _type_mask: u32,
687 ) -> Result<
688 (
689 <Backend as gfx_hal::Backend>::Image,
690 <Backend as gfx_hal::Backend>::Memory,
691 ),
692 hal::external_memory::ExternalResourceError,
693 > {
694 unimplemented!()
695 }
696
697 unsafe fn export_memory(
698 &self,
699 _external_memory_type: hal::external_memory::ExternalMemoryType,
700 _memory: &<Backend as gfx_hal::Backend>::Memory,
701 ) -> Result<hal::external_memory::PlatformMemory, hal::external_memory::ExternalMemoryExportError>
702 {
703 unimplemented!()
704 }
705
706 unsafe fn drm_format_modifier(
707 &self,
708 _image: &<Backend as gfx_hal::Backend>::Image,
709 ) -> Option<hal::format::DrmModifier> {
710 None
711 }
712
713 unsafe fn reset_fence(&self, _: &mut ()) -> Result<(), device::OutOfMemory> {
714 Ok(())
715 }
716
717 unsafe fn wait_for_fence(&self, _: &(), _: u64) -> Result<bool, device::WaitError> {
718 Ok(true)
719 }
720
721 unsafe fn set_display_power_state(
722 &self,
723 _display: &display::Display<Backend>,
724 _power_state: &display::control::PowerState,
725 ) -> Result<(), display::control::DisplayControlError> {
726 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
727 }
728
729 unsafe fn register_device_event(
730 &self,
731 _device_event: &display::control::DeviceEvent,
732 _fence: &mut <Backend as hal::Backend>::Fence,
733 ) -> Result<(), display::control::DisplayControlError> {
734 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
735 }
736
737 unsafe fn register_display_event(
738 &self,
739 _display: &display::Display<Backend>,
740 _display_event: &display::control::DisplayEvent,
741 _fence: &mut <Backend as hal::Backend>::Fence,
742 ) -> Result<(), display::control::DisplayControlError> {
743 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
744 }
745
746 fn start_capture(&self) {
747 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
748 }
749
750 fn stop_capture(&self) {
751 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
752 }
753}
754
755#[derive(Debug)]
756pub struct QueueFamily;
757impl queue::QueueFamily for QueueFamily {
758 fn queue_type(&self) -> queue::QueueType {
759 queue::QueueType::General
760 }
761 fn max_queues(&self) -> usize {
762 1
763 }
764 fn id(&self) -> queue::QueueFamilyId {
765 QUEUE_FAMILY_ID
766 }
767 fn supports_sparse_binding(&self) -> bool {
768 true
769 }
770}
771
772const QUEUE_FAMILY_ID: queue::QueueFamilyId = queue::QueueFamilyId(0);
773
774#[derive(Debug)]
776pub struct CommandPool;
777impl pool::CommandPool<Backend> for CommandPool {
778 unsafe fn allocate_one(&mut self, level: command::Level) -> CommandBuffer {
779 assert_eq!(
780 level,
781 command::Level::Primary,
782 "Only primary command buffers are supported"
783 );
784 CommandBuffer
785 }
786
787 unsafe fn reset(&mut self, _: bool) {}
788
789 unsafe fn free<I>(&mut self, _: I) {
790 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
791 }
792}
793
794#[derive(Debug)]
796pub struct CommandBuffer;
797impl command::CommandBuffer<Backend> for CommandBuffer {
798 unsafe fn begin(
799 &mut self,
800 _: command::CommandBufferFlags,
801 _: command::CommandBufferInheritanceInfo<Backend>,
802 ) {
803 }
804
805 unsafe fn finish(&mut self) {}
806
807 unsafe fn reset(&mut self, _: bool) {
808 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
809 }
810
811 unsafe fn pipeline_barrier<'a, T>(
812 &mut self,
813 _: Range<pso::PipelineStage>,
814 _: hal::memory::Dependencies,
815 _: T,
816 ) where
817 T: Iterator<Item = hal::memory::Barrier<'a, Backend>>,
818 {
819 }
820
821 unsafe fn fill_buffer(&mut self, _: &Buffer, _: hal::buffer::SubRange, _: u32) {
822 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
823 }
824
825 unsafe fn update_buffer(&mut self, _: &Buffer, _: hal::buffer::Offset, _: &[u8]) {
826 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
827 }
828
829 unsafe fn clear_image<T>(
830 &mut self,
831 _: &Image,
832 _: hal::image::Layout,
833 _: command::ClearValue,
834 _: T,
835 ) {
836 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
837 }
838
839 unsafe fn clear_attachments<T, U>(&mut self, _: T, _: U) {
840 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
841 }
842
843 unsafe fn resolve_image<T>(
844 &mut self,
845 _: &Image,
846 _: hal::image::Layout,
847 _: &Image,
848 _: hal::image::Layout,
849 _: T,
850 ) {
851 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
852 }
853
854 unsafe fn blit_image<T>(
855 &mut self,
856 _: &Image,
857 _: hal::image::Layout,
858 _: &Image,
859 _: hal::image::Layout,
860 _: hal::image::Filter,
861 _: T,
862 ) {
863 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
864 }
865
866 unsafe fn bind_index_buffer(
867 &mut self,
868 _: &Buffer,
869 _: hal::buffer::SubRange,
870 _: hal::IndexType,
871 ) {
872 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
873 }
874
875 unsafe fn bind_vertex_buffers<'a, T>(&mut self, _: u32, _: T)
876 where
877 T: Iterator<Item = (&'a Buffer, hal::buffer::SubRange)>,
878 {
879 }
880
881 unsafe fn set_viewports<T>(&mut self, _: u32, _: T) {}
882
883 unsafe fn set_scissors<T>(&mut self, _: u32, _: T) {}
884
885 unsafe fn set_stencil_reference(&mut self, _: pso::Face, _: pso::StencilValue) {
886 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
887 }
888
889 unsafe fn set_stencil_read_mask(&mut self, _: pso::Face, _: pso::StencilValue) {
890 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
891 }
892
893 unsafe fn set_stencil_write_mask(&mut self, _: pso::Face, _: pso::StencilValue) {
894 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
895 }
896
897 unsafe fn set_blend_constants(&mut self, _: pso::ColorValue) {
898 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
899 }
900
901 unsafe fn set_depth_bounds(&mut self, _: Range<f32>) {
902 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
903 }
904
905 unsafe fn set_line_width(&mut self, _: f32) {
906 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
907 }
908
909 unsafe fn set_depth_bias(&mut self, _: pso::DepthBias) {
910 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
911 }
912
913 unsafe fn begin_render_pass<'a, T>(
914 &mut self,
915 _: &(),
916 _: &(),
917 _: pso::Rect,
918 _: T,
919 _: command::SubpassContents,
920 ) where
921 T: Iterator<Item = command::RenderAttachmentInfo<'a, Backend>>,
922 {
923 }
924
925 unsafe fn next_subpass(&mut self, _: command::SubpassContents) {
926 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
927 }
928
929 unsafe fn end_render_pass(&mut self) {}
930
931 unsafe fn bind_graphics_pipeline(&mut self, _: &()) {}
932
933 unsafe fn bind_graphics_descriptor_sets<'a, I, J>(&mut self, _: &(), _: usize, _: I, _: J)
934 where
935 I: Iterator<Item = &'a DescriptorSet>,
936 {
937 }
939
940 unsafe fn bind_compute_pipeline(&mut self, _: &()) {
941 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
942 }
943
944 unsafe fn bind_compute_descriptor_sets<'a, I, J>(&mut self, _: &(), _: usize, _: I, _: J)
945 where
946 I: Iterator<Item = &'a DescriptorSet>,
947 {
948 }
950
951 unsafe fn dispatch(&mut self, _: hal::WorkGroupCount) {
952 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
953 }
954
955 unsafe fn dispatch_indirect(&mut self, _: &Buffer, _: hal::buffer::Offset) {
956 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
957 }
958
959 unsafe fn copy_buffer<T>(&mut self, _: &Buffer, _: &Buffer, _: T) {
960 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
961 }
962
963 unsafe fn copy_image<T>(
964 &mut self,
965 _: &Image,
966 _: hal::image::Layout,
967 _: &Image,
968 _: hal::image::Layout,
969 _: T,
970 ) {
971 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
972 }
973
974 unsafe fn copy_buffer_to_image<T>(
975 &mut self,
976 _: &Buffer,
977 _: &Image,
978 _: hal::image::Layout,
979 _: T,
980 ) {
981 }
982
983 unsafe fn copy_image_to_buffer<T>(
984 &mut self,
985 _: &Image,
986 _: hal::image::Layout,
987 _: &Buffer,
988 _: T,
989 ) {
990 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
991 }
992
993 unsafe fn draw(&mut self, _: Range<hal::VertexCount>, _: Range<hal::InstanceCount>) {}
994
995 unsafe fn draw_indexed(
996 &mut self,
997 _: Range<hal::IndexCount>,
998 _: hal::VertexOffset,
999 _: Range<hal::InstanceCount>,
1000 ) {
1001 }
1002
1003 unsafe fn draw_indirect(
1004 &mut self,
1005 _: &Buffer,
1006 _: hal::buffer::Offset,
1007 _: hal::DrawCount,
1008 _: hal::buffer::Stride,
1009 ) {
1010 }
1011
1012 unsafe fn draw_indexed_indirect(
1013 &mut self,
1014 _: &Buffer,
1015 _: hal::buffer::Offset,
1016 _: hal::DrawCount,
1017 _: hal::buffer::Stride,
1018 ) {
1019 }
1020
1021 unsafe fn draw_indirect_count(
1022 &mut self,
1023 _: &Buffer,
1024 _: hal::buffer::Offset,
1025 _: &Buffer,
1026 _: hal::buffer::Offset,
1027 _: u32,
1028 _: hal::buffer::Stride,
1029 ) {
1030 }
1031
1032 unsafe fn draw_indexed_indirect_count(
1033 &mut self,
1034 _: &Buffer,
1035 _: hal::buffer::Offset,
1036 _: &Buffer,
1037 _: hal::buffer::Offset,
1038 _: u32,
1039 _: hal::buffer::Stride,
1040 ) {
1041 }
1042
1043 unsafe fn draw_mesh_tasks(&mut self, _: hal::TaskCount, _: hal::TaskCount) {
1044 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1045 }
1046
1047 unsafe fn draw_mesh_tasks_indirect(
1048 &mut self,
1049 _: &Buffer,
1050 _: hal::buffer::Offset,
1051 _: hal::DrawCount,
1052 _: hal::buffer::Stride,
1053 ) {
1054 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1055 }
1056
1057 unsafe fn draw_mesh_tasks_indirect_count(
1058 &mut self,
1059 _: &Buffer,
1060 _: hal::buffer::Offset,
1061 _: &Buffer,
1062 _: hal::buffer::Offset,
1063 _: u32,
1064 _: hal::buffer::Stride,
1065 ) {
1066 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1067 }
1068
1069 unsafe fn set_event(&mut self, _: &(), _: pso::PipelineStage) {
1070 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1071 }
1072
1073 unsafe fn reset_event(&mut self, _: &(), _: pso::PipelineStage) {
1074 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1075 }
1076
1077 unsafe fn wait_events<'a, I, J>(&mut self, _: I, _: Range<pso::PipelineStage>, _: J)
1078 where
1079 J: Iterator<Item = hal::memory::Barrier<'a, Backend>>,
1080 {
1081 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1082 }
1083
1084 unsafe fn begin_query(&mut self, _: query::Query<Backend>, _: query::ControlFlags) {
1085 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1086 }
1087
1088 unsafe fn end_query(&mut self, _: query::Query<Backend>) {
1089 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1090 }
1091
1092 unsafe fn reset_query_pool(&mut self, _: &(), _: Range<query::Id>) {
1093 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1094 }
1095
1096 unsafe fn copy_query_pool_results(
1097 &mut self,
1098 _: &(),
1099 _: Range<query::Id>,
1100 _: &Buffer,
1101 _: hal::buffer::Offset,
1102 _: hal::buffer::Stride,
1103 _: query::ResultFlags,
1104 ) {
1105 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1106 }
1107
1108 unsafe fn write_timestamp(&mut self, _: pso::PipelineStage, _: query::Query<Backend>) {
1109 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1110 }
1111
1112 unsafe fn push_graphics_constants(
1113 &mut self,
1114 _: &(),
1115 _: pso::ShaderStageFlags,
1116 _: u32,
1117 _: &[u32],
1118 ) {
1119 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1120 }
1121
1122 unsafe fn push_compute_constants(&mut self, _: &(), _: u32, _: &[u32]) {
1123 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1124 }
1125
1126 unsafe fn execute_commands<'a, T>(&mut self, _: T)
1127 where
1128 T: Iterator<Item = &'a CommandBuffer>,
1129 {
1130 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1131 }
1132
1133 unsafe fn insert_debug_marker(&mut self, _: &str, _: u32) {
1134 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1135 }
1136 unsafe fn begin_debug_marker(&mut self, _: &str, _: u32) {
1137 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1138 }
1139 unsafe fn end_debug_marker(&mut self) {
1140 unimplemented!("{}", NOT_SUPPORTED_MESSAGE)
1141 }
1142}
1143
1144#[derive(Debug)]
1146pub struct Surface;
1147impl window::Surface<Backend> for Surface {
1148 fn supports_queue_family(&self, _: &QueueFamily) -> bool {
1149 true
1150 }
1151
1152 fn capabilities(&self, _: &PhysicalDevice) -> window::SurfaceCapabilities {
1153 let extents = {
1154 let min_extent = window::Extent2D {
1155 width: 0,
1156 height: 0,
1157 };
1158 let max_extent = window::Extent2D {
1159 width: 8192,
1160 height: 4096,
1161 };
1162 min_extent..=max_extent
1163 };
1164 let usage = hal::image::Usage::COLOR_ATTACHMENT;
1165 let present_modes = window::PresentMode::all();
1166 let composite_alpha_modes = window::CompositeAlphaMode::OPAQUE;
1167 window::SurfaceCapabilities {
1168 image_count: 1..=1,
1169 current_extent: None,
1170 extents,
1171 max_image_layers: 1,
1172 usage,
1173 present_modes,
1174 composite_alpha_modes,
1175 }
1176 }
1177
1178 fn supported_formats(&self, _: &PhysicalDevice) -> Option<Vec<format::Format>> {
1179 None
1180 }
1181}
1182
1183#[derive(Debug)]
1184pub struct SwapchainImage;
1185impl Borrow<Image> for SwapchainImage {
1186 fn borrow(&self) -> &Image {
1187 unimplemented!()
1188 }
1189}
1190impl Borrow<()> for SwapchainImage {
1191 fn borrow(&self) -> &() {
1192 unimplemented!()
1193 }
1194}
1195
1196impl window::PresentationSurface<Backend> for Surface {
1197 type SwapchainImage = SwapchainImage;
1198
1199 unsafe fn configure_swapchain(
1200 &mut self,
1201 _: &Device,
1202 _: window::SwapchainConfig,
1203 ) -> Result<(), window::SwapchainError> {
1204 Ok(())
1205 }
1206
1207 unsafe fn unconfigure_swapchain(&mut self, _: &Device) {}
1208
1209 unsafe fn acquire_image(
1210 &mut self,
1211 _: u64,
1212 ) -> Result<(SwapchainImage, Option<window::Suboptimal>), window::AcquireError> {
1213 Ok((SwapchainImage, None))
1214 }
1215}
1216
1217#[derive(Debug)]
1218pub struct Instance;
1219
1220impl hal::Instance<Backend> for Instance {
1221 fn create(name: &str, version: u32) -> Result<Self, hal::UnsupportedBackend> {
1222 debug!(
1223 "Creating empty backend instance with name '{}' and version {}",
1224 name, version
1225 );
1226 Ok(Instance)
1227 }
1228
1229 fn enumerate_adapters(&self) -> Vec<adapter::Adapter<Backend>> {
1230 let info = adapter::AdapterInfo {
1232 name: "Mock Device".to_string(),
1233 vendor: 0,
1234 device: 1234,
1235 device_type: adapter::DeviceType::Other,
1236 };
1237 let adapter = adapter::Adapter {
1238 info,
1239 physical_device: PhysicalDevice,
1240 queue_families: vec![QueueFamily],
1242 };
1243 vec![adapter]
1244 }
1245
1246 unsafe fn create_surface(
1247 &self,
1248 raw_window_handle: &impl raw_window_handle::HasRawWindowHandle,
1249 ) -> Result<Surface, hal::window::InitError> {
1250 let _handle = raw_window_handle.raw_window_handle();
1252 Ok(Surface)
1253 }
1254
1255 unsafe fn destroy_surface(&self, _surface: Surface) {}
1256
1257 unsafe fn create_display_plane_surface(
1258 &self,
1259 _display_plane: &display::DisplayPlane<Backend>,
1260 _plane_stack_index: u32,
1261 _transformation: display::SurfaceTransform,
1262 _alpha: display::DisplayPlaneAlpha,
1263 _image_extent: window::Extent2D,
1264 ) -> Result<Surface, display::DisplayPlaneSurfaceError> {
1265 unimplemented!();
1266 }
1267}