]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/device_backend.cpp
Cache framebuffer and viewport in VulkanCommands
[libs/gl.git] / source / backends / vulkan / device_backend.cpp
1 #include <msp/graphics/vulkancontext_platform.h>
2 #include "device.h"
3 #include "device_backend.h"
4 #include "vulkan.h"
5
6 namespace Msp {
7 namespace GL {
8
9 VulkanDevice::VulkanDevice(Graphics::Window &wnd, const Graphics::VulkanOptions &opts):
10         context(wnd, opts),
11         device(handle_cast<VkDevice>(context.get_private().device)),
12         graphics_queue(handle_cast<VkQueue>(context.get_private().graphics_queue)),
13         functions(new VulkanFunctions(context)),
14         allocator(*static_cast<Device *>(this)),
15         destroy_queue(*static_cast<Device *>(this)),
16         transfer_queue(*static_cast<Device *>(this)),
17         pipeline_cache(*static_cast<Device *>(this))
18 { }
19
20 // Cause the destructor of RefPtr<VulkanFunctions> to be emitted here
21 VulkanDevice::~VulkanDevice()
22 { }
23
24 Graphics::VulkanOptions VulkanDevice::create_default_options()
25 {
26         Graphics::VulkanOptions opts;
27 #ifdef DEBUG
28         opts.enable_validation = true;
29         opts.enable_debug_report = true;
30 #endif
31         return opts;
32 }
33
34 void VulkanDevice::fill_info()
35 {
36         DeviceInfo &info = static_cast<Device *>(this)->info;
37
38         VkPhysicalDeviceProperties props;
39         functions->GetPhysicalDeviceProperties(props);
40
41         info.api_version.major = (props.apiVersion>>22)&0x7F;
42         info.api_version.minor = (props.apiVersion>>12)&0x3FF;
43
44         DeviceLimits &limits = info.limits;
45         limits.max_clip_planes = props.limits.maxClipDistances;
46         limits.max_vertex_attributes = props.limits.maxVertexInputAttributes;
47         limits.max_texture_bindings = props.limits.maxDescriptorSetSampledImages;
48         limits.max_color_attachments = props.limits.maxColorAttachments;
49         unsigned samples = props.limits.framebufferColorSampleCounts&props.limits.framebufferDepthSampleCounts&props.limits.framebufferStencilSampleCounts;
50         if(samples&VK_SAMPLE_COUNT_64_BIT)
51                 limits.max_samples = 64;
52         else if(samples&VK_SAMPLE_COUNT_32_BIT)
53                 limits.max_samples = 32;
54         else if(samples&VK_SAMPLE_COUNT_16_BIT)
55                 limits.max_samples = 16;
56         else if(samples&VK_SAMPLE_COUNT_8_BIT)
57                 limits.max_samples = 8;
58         limits.max_uniform_bindings = props.limits.maxDescriptorSetUniformBuffers;
59         limits.uniform_buffer_alignment = props.limits.minUniformBufferOffsetAlignment;
60         limits.max_anisotropy = props.limits.maxSamplerAnisotropy;
61
62         info.glsl_features = SL::Features::from_api_version(info.api, info.api_version);
63 }
64
65 } // namespace GL
66 } // namespace Msp