• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2021 The vulkano developers
2 // Licensed under the Apache License, Version 2.0
3 // <LICENSE-APACHE or
4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT
5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>,
6 // at your option. All files in the project carrying such
7 // notice may not be copied, modified, or distributed except
8 // according to those terms.
9 
10 use crate::buffer::BufferAccess;
11 use crate::device::Device;
12 use crate::device::DeviceOwned;
13 use crate::VulkanObject;
14 use std::error;
15 use std::fmt;
16 
17 /// Checks whether an indirect buffer can be bound.
check_indirect_buffer<Inb>( device: &Device, buffer: &Inb, ) -> Result<(), CheckIndirectBufferError> where Inb: BufferAccess + Send + Sync + 'static,18 pub fn check_indirect_buffer<Inb>(
19     device: &Device,
20     buffer: &Inb,
21 ) -> Result<(), CheckIndirectBufferError>
22 where
23     Inb: BufferAccess + Send + Sync + 'static,
24 {
25     assert_eq!(
26         buffer.inner().buffer.device().internal_object(),
27         device.internal_object()
28     );
29 
30     if !buffer.inner().buffer.usage().indirect_buffer {
31         return Err(CheckIndirectBufferError::BufferMissingUsage);
32     }
33 
34     Ok(())
35 }
36 
37 /// Error that can happen when checking whether binding an indirect buffer is valid.
38 #[derive(Debug, Copy, Clone)]
39 pub enum CheckIndirectBufferError {
40     /// The "indirect buffer" usage must be enabled on the indirect buffer.
41     BufferMissingUsage,
42     /// The maximum number of indirect draws has been exceeded.
43     MaxDrawIndirectCountLimitExceeded {
44         /// The limit that must be fulfilled.
45         limit: u32,
46         /// What was requested.
47         requested: u32,
48     },
49 }
50 
51 impl error::Error for CheckIndirectBufferError {}
52 
53 impl fmt::Display for CheckIndirectBufferError {
54     #[inline]
fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error>55     fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
56         write!(
57             fmt,
58             "{}",
59             match *self {
60                 CheckIndirectBufferError::BufferMissingUsage => {
61                     "the indirect buffer usage must be enabled on the indirect buffer"
62                 }
63                 CheckIndirectBufferError::MaxDrawIndirectCountLimitExceeded {
64                     limit,
65                     requested,
66                 } => {
67                     "the maximum number of indirect draws has been exceeded"
68                 }
69             }
70         )
71     }
72 }
73