15
15
#ifndef SAMPLE_APPLICATION_FRAMEWORK_SAMPLE_APPLICATION_H_
16
16
#define SAMPLE_APPLICATION_FRAMEWORK_SAMPLE_APPLICATION_H_
17
17
18
+ #include < chrono>
19
+ #include < cstddef>
20
+
18
21
#include " support/entry/entry.h"
19
22
#include " vulkan_helpers/helper_functions.h"
20
23
#include " vulkan_helpers/vulkan_application.h"
21
24
22
- #include < chrono>
23
- #include < cstddef>
24
-
25
25
namespace sample_application {
26
26
27
27
const static VkSampleCountFlagBits kVkMultiSampledSampleCount =
@@ -39,6 +39,7 @@ struct SampleOptions {
39
39
bool enable_depth_buffer = false ;
40
40
bool enable_stencil = false ;
41
41
bool verbose_output = false ;
42
+
42
43
bool async_compute = false ;
43
44
bool sparse_binding = false ;
44
45
bool protected_memory = false ;
@@ -154,6 +155,39 @@ const VkSubmitInfo kEmptySubmitInfo{
154
155
nullptr // pSignalSemaphores
155
156
};
156
157
158
+ vulkan::VulkanApplicationOptions buildVulkanApplicationOptions (
159
+ uint32_t host_buffer_size_in_MB, uint32_t image_memory_size_in_MB,
160
+ uint32_t device_buffer_size_in_MB, uint32_t coherent_buffer_size_in_MB,
161
+ const SampleOptions& options) {
162
+ vulkan::VulkanApplicationOptions ret;
163
+
164
+ ret.SetHostBufferSize (host_buffer_size_in_MB * 1024 * 1024 )
165
+ .SetDeviceImageSize (image_memory_size_in_MB * 1024 * 1024 )
166
+ .SetDeviceBufferSize (device_buffer_size_in_MB * 1024 * 1024 )
167
+ .SetCoherentBufferSize (coherent_buffer_size_in_MB * 1024 * 1024 );
168
+
169
+ if (options.async_compute ) ret.EnableAsyncComputeQueue ();
170
+ if (options.sparse_binding ) ret.EnableSparseBinding ();
171
+ if (options.protected_memory ) ret.EnableProtectedMemory ();
172
+ if (options.host_query_reset ) ret.EnableHostQueryReset ();
173
+ if (options.shared_presentation ) ret.EnableSharedPresentation ();
174
+ if (options.enable_vulkan_1_1 ) ret.EnableVulkan11 ();
175
+ if (options.enable_10bit_hdr ) ret.Enable10BitHDR ();
176
+ if (options.mutable_swapchain_format ) ret.EnableMutableSwapchainFormat ();
177
+
178
+ if (options.extended_swapchain_color_space )
179
+ ret.SetSwapchainColorSpace (VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT);
180
+
181
+ if (options.mutable_swapchain_format )
182
+ ret.SetSwapchainExtensions (&kMutableSwapchainImageFormatList );
183
+
184
+ ret.SetMinSwapchainImageCount (options.min_swapchain_image_count );
185
+
186
+ ret.SetDeviceExtensions (options.device_extension_structures );
187
+
188
+ return ret;
189
+ }
190
+
157
191
template <typename FrameData>
158
192
class Sample {
159
193
// The per-frame data for an application.
@@ -195,8 +229,7 @@ class Sample {
195
229
public:
196
230
Sample (containers::Allocator* allocator, const entry::EntryData* entry_data,
197
231
uint32_t host_buffer_size_in_MB, uint32_t image_memory_size_in_MB,
198
- uint32_t device_buffer_size_in_MB,
199
- uint32_t coherent_buffer_size_in_MB,
232
+ uint32_t device_buffer_size_in_MB, uint32_t coherent_buffer_size_in_MB,
200
233
const SampleOptions& options,
201
234
const VkPhysicalDeviceFeatures& physical_device_features = {0 },
202
235
const std::initializer_list<const char *> instance_extensions = {},
@@ -205,23 +238,11 @@ class Sample {
205
238
data_ (entry_data),
206
239
allocator_(allocator),
207
240
application_(
208
- allocator, entry_data->logger (), entry_data, instance_extensions,
209
- device_extensions, physical_device_features,
210
- host_buffer_size_in_MB * 1024 * 1024,
211
- image_memory_size_in_MB * 1024 * 1024,
212
- device_buffer_size_in_MB * 1024 * 1024,
213
- coherent_buffer_size_in_MB * 1024 * 1024, options.async_compute,
214
- options.sparse_binding, false, 0, options.protected_memory,
215
- options.host_query_reset,
216
- options.extended_swapchain_color_space
217
- ? VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT
218
- : VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
219
- options.shared_presentation, options.mutable_swapchain_format,
220
- options.mutable_swapchain_format ? &kMutableSwapchainImageFormatList
221
- : nullptr,
222
- options.enable_vulkan_1_1, options.enable_10bit_hdr,
223
- options.device_extension_structures,
224
- options.min_swapchain_image_count),
241
+ allocator, entry_data->logger (), entry_data,
242
+ buildVulkanApplicationOptions(
243
+ host_buffer_size_in_MB, image_memory_size_in_MB,
244
+ device_buffer_size_in_MB, coherent_buffer_size_in_MB, options),
245
+ instance_extensions, device_extensions, physical_device_features),
225
246
frame_data_(allocator),
226
247
swapchain_images_(application_.swapchain_images()),
227
248
last_frame_time_(std::chrono::high_resolution_clock::now()),
@@ -242,18 +263,19 @@ class Sample {
242
263
if (options_.enable_stencil ) {
243
264
depth_stencil_format_ = GetSupportedDepthStencilFormat (
244
265
&application_.instance (), &application_.device ());
245
- LOG_ASSERT (!=, data_->logger (), VK_FORMAT_UNDEFINED, depth_stencil_format_);
266
+ LOG_ASSERT (!=, data_->logger (), VK_FORMAT_UNDEFINED,
267
+ depth_stencil_format_);
246
268
}
247
269
248
270
num_samples_ = options.enable_multisampling ? kVkMultiSampledSampleCount
249
271
: VK_SAMPLE_COUNT_1_BIT;
250
272
251
- num_color_samples_ =
252
- options. enable_mixed_multisampling ? VK_SAMPLE_COUNT_1_BIT
253
- : num_samples_;
273
+ num_color_samples_ = options. enable_mixed_multisampling
274
+ ? VK_SAMPLE_COUNT_1_BIT
275
+ : num_samples_;
254
276
num_depth_stencil_samples_ = options.enable_mixed_multisampling
255
- ? kVkMultiSampledSampleCount
256
- : num_samples_;
277
+ ? kVkMultiSampledSampleCount
278
+ : num_samples_;
257
279
default_viewport_ = {0 .0f ,
258
280
0 .0f ,
259
281
static_cast <float >(application_.swapchain ().width ()),
@@ -276,7 +298,7 @@ class Sample {
276
298
277
299
InitializeApplicationData (&initialization_command_buffer_,
278
300
swapchain_images_.size ());
279
-
301
+
280
302
if (options_.enable_10bit_hdr ) {
281
303
VkHdrMetadataEXT hdr10_metadata{
282
304
VK_STRUCTURE_TYPE_HDR_METADATA_EXT,
@@ -329,7 +351,9 @@ class Sample {
329
351
data_->NotifyReady ();
330
352
}
331
353
332
- virtual void WaitIdle () { app ()->device ()->vkDeviceWaitIdle (app ()->device ()); }
354
+ virtual void WaitIdle () {
355
+ app ()->device ()->vkDeviceWaitIdle (app ()->device ());
356
+ }
333
357
334
358
// The format that we are using to render. This will be either the swapchain
335
359
// format if we are not rendering multi-sampled, or the multisampled image
@@ -343,7 +367,9 @@ class Sample {
343
367
// The number of color samples that will be used with mixed sampling
344
368
VkSampleCountFlagBits num_color_samples () const { return num_color_samples_; }
345
369
// The number of depth/stencil samples that will be used with mixed sampling
346
- VkSampleCountFlagBits num_depth_stencil_samples () const { return num_depth_stencil_samples_; }
370
+ VkSampleCountFlagBits num_depth_stencil_samples () const {
371
+ return num_depth_stencil_samples_;
372
+ }
347
373
348
374
vulkan::VulkanApplication* app () { return &application_; }
349
375
const vulkan::VulkanApplication* app () const { return &application_; }
@@ -365,7 +391,7 @@ class Sample {
365
391
average_frame_time_ =
366
392
elapsed_time.count () * 0 .05f + average_frame_time_ * 0 .95f ;
367
393
368
- // Display Timing
394
+ // Display Timing
369
395
VkRefreshCycleDurationGOOGLE rc_dur = {};
370
396
static unsigned refresh_multiplier = 1 ;
371
397
static uint32_t present_id = 0 ;
@@ -573,7 +599,7 @@ class Sample {
573
599
&ptime, // pTimes
574
600
};
575
601
576
- if (options_.enable_display_timing ) {
602
+ if (options_.enable_display_timing ) {
577
603
present_info.pNext = &present_time;
578
604
}
579
605
@@ -740,9 +766,9 @@ class Sample {
740
766
}
741
767
742
768
view_create_info.image =
743
- (options_.enable_multisampling && !options_.enable_mixed_multisampling )
744
- ? *data->multisampled_target_
745
- : data->swapchain_image_ ;
769
+ (options_.enable_multisampling && !options_.enable_mixed_multisampling )
770
+ ? *data->multisampled_target_
771
+ : data->swapchain_image_ ;
746
772
view_create_info.format = options_.mutable_swapchain_format
747
773
? VK_FORMAT_B8G8R8A8_SRGB
748
774
: render_target_format_;
@@ -857,7 +883,7 @@ class Sample {
857
883
dstQueueFamilyIndex, // dstQueueFamilyIndex
858
884
(options_.enable_multisampling && !options_.enable_mixed_multisampling )
859
885
? *data->multisampled_target_
860
- : data->swapchain_image_ , // image
886
+ : data->swapchain_image_ , // image
861
887
{VK_IMAGE_ASPECT_COLOR_BIT, 0 , 1 , 0 , 1 }};
862
888
863
889
data->setup_command_buffer_ =
0 commit comments