1- use std:: mem:: size_of;
2-
31use gfx_hal:: {
42 adapter:: Adapter ,
53 device:: Device ,
@@ -31,12 +29,14 @@ pub struct GpuBuilder {
3129}
3230
3331impl GpuBuilder {
32+ /// Create a new GpuBuilder to configure and build a GPU to use for rendering.
3433 pub fn new ( ) -> Self {
3534 return Self {
3635 render_queue_type : RenderQueueType :: Graphical ,
3736 } ;
3837 }
3938
39+ /// Set the type of queue to use for rendering. The GPU defaults to graphical.
4040 pub fn with_render_queue_type ( mut self , queue_type : RenderQueueType ) -> Self {
4141 self . render_queue_type = queue_type;
4242 return self ;
@@ -88,7 +88,7 @@ pub struct Gpu<B: gfx_hal::Backend> {
8888 queue_group : QueueGroup < B > ,
8989}
9090
91- #[ derive( Clone , Copy , Debug ) ]
91+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
9292pub enum RenderQueueType {
9393 Compute ,
9494 Graphical ,
@@ -171,39 +171,37 @@ impl<RenderBackend: gfx_hal::Backend> Gpu<RenderBackend> {
171171
172172 return Ok ( ( ) ) ;
173173 }
174-
175- /// Create a frame buffer on the GPU.
176- pub fn create_frame_buffer (
177- & mut self ,
178- render_pass : & RenderBackend :: RenderPass ,
179- image : gfx_hal:: image:: FramebufferAttachment ,
180- dimensions : & Extent2D ,
181- ) -> RenderBackend :: Framebuffer {
182- unsafe {
183- use gfx_hal:: image:: Extent ;
184- return self
185- . gpu
186- . device
187- . create_framebuffer (
188- & render_pass,
189- vec ! [ image] . into_iter ( ) ,
190- Extent {
191- width : dimensions. width ,
192- height : dimensions. height ,
193- depth : 1 ,
194- } ,
195- )
196- . unwrap ( ) ;
197- }
198- }
199174}
200175
201176#[ cfg( test) ]
202177mod tests {
203178 #[ test]
204- fn test_gpu_builder ( ) {
205- assert_eq ! ( 2 + 2 , 4 ) ;
179+ fn test_gpu_builder_default_state ( ) {
180+ use super :: {
181+ GpuBuilder ,
182+ RenderQueueType ,
183+ } ;
184+
185+ let builder = GpuBuilder :: new ( ) ;
186+
187+ assert_eq ! ( builder. render_queue_type, RenderQueueType :: Graphical ) ;
206188 }
189+
190+ #[ test]
191+ fn test_gpu_builder_with_render_queue_type ( ) {
192+ use super :: {
193+ GpuBuilder ,
194+ RenderQueueType ,
195+ } ;
196+
197+ let builder =
198+ GpuBuilder :: new ( ) . with_render_queue_type ( RenderQueueType :: Compute ) ;
199+
200+ assert_eq ! ( builder. render_queue_type, RenderQueueType :: Compute ) ;
201+ }
202+
203+ #[ test]
204+ fn test_gpu_builder_build ( ) { }
207205}
208206
209207// --------------------------------- GPU INTERNALS -----------------------------
@@ -219,13 +217,15 @@ pub mod internal {
219217 return & gpu. gpu . device ;
220218 }
221219
220+ /// Retrieves the gfx_hal physical device for a given GPU.
222221 #[ inline]
223222 pub fn physical_device_for < RenderBackend : gfx_hal:: Backend > (
224223 gpu : & Gpu < RenderBackend > ,
225224 ) -> & RenderBackend :: PhysicalDevice {
226225 return & gpu. adapter . physical_device ;
227226 }
228227
228+ /// Retrieves the gfx_hal queue group for a given GPU.
229229 #[ inline]
230230 pub fn queue_family_for < RenderBackend : gfx_hal:: Backend > (
231231 gpu : & Gpu < RenderBackend > ,
0 commit comments