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