-
Notifications
You must be signed in to change notification settings - Fork 2
/
physical_device.go
72 lines (61 loc) · 3.26 KB
/
physical_device.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package core1_2
import (
"github.com/vkngwrapper/core/common"
"github.com/vkngwrapper/core/core1_0"
"github.com/vkngwrapper/core/core1_1"
"github.com/vkngwrapper/core/driver"
)
// VulkanPhysicalDevice is an implementation of the PhysicalDevice interface that actually communicates with Vulkan. This
// is the default implementation. See the interface for more documentation.
type VulkanPhysicalDevice struct {
core1_1.PhysicalDevice
InstanceScoped1_2 InstanceScopedPhysicalDevice
}
func (p *VulkanPhysicalDevice) InstanceScopedPhysicalDevice1_2() InstanceScopedPhysicalDevice {
return p.InstanceScoped1_2
}
// PromotePhysicalDevice accepts a PhysicalDevice object from any core version. If provided a physical device that supports
// at least core 1.2 for its device-scoped functionality, it will return a core1_2.PhysicalDevice. Otherwise, it will return nil. This method
// will always return a core1_2.VulkanPhysicalDevice, even if it is provided a VulkanPhysicalDevice from a higher
// core version. Two Vulkan 1.2 compatible PhysicalDevice objects with the same PhysicalDevice.Handle will
// return the same interface value when passed to this method.
func PromotePhysicalDevice(physicalDevice core1_0.PhysicalDevice) PhysicalDevice {
if !physicalDevice.DeviceAPIVersion().IsAtLeast(common.Vulkan1_2) {
return nil
}
instanceScoped := PromoteInstanceScopedPhysicalDevice(physicalDevice)
promotedPhysicalDevice := core1_1.PromotePhysicalDevice(physicalDevice)
return physicalDevice.Driver().ObjectStore().GetOrCreate(
driver.VulkanHandle(physicalDevice.Handle()),
driver.Core1_2,
func() any {
return &VulkanPhysicalDevice{
PhysicalDevice: promotedPhysicalDevice,
InstanceScoped1_2: instanceScoped,
}
}).(PhysicalDevice)
}
// VulkanInstanceScopedPhysicalDevice is an implementation of the InstanceScopedPhysicalDevice interface that actually communicates with Vulkan. This
// is the default implementation. See the interface for more documentation.
type VulkanInstanceScopedPhysicalDevice struct {
core1_1.InstanceScopedPhysicalDevice
}
// PromoteInstanceScopedPhysicalDevice accepts a InstanceScopedPhysicalDevice object from any core version. If provided an instance-scoped physical device that supports
// at least core 1.2 for its instance-scoped functionality, it will return a core1_2.InstanceScopedPhysicalDevice. Otherwise, it will return nil. This method
// will always return a core1_2.VulkanInstanceScopedPhysicalDevice, even if it is provided a VulkanInstanceScopedPhysicalDevice from a higher
// core version. Two Vulkan 1.2 compatible InstanceScopedPhysicalDevice objects with the same InstanceScopedPhysicalDevice.Handle will
// return the same interface value when passed to this method.
func PromoteInstanceScopedPhysicalDevice(physicalDevice core1_0.PhysicalDevice) InstanceScopedPhysicalDevice {
if !physicalDevice.InstanceAPIVersion().IsAtLeast(common.Vulkan1_2) {
return nil
}
promotedPhysicalDevice := core1_1.PromoteInstanceScopedPhysicalDevice(physicalDevice)
return physicalDevice.Driver().ObjectStore().GetOrCreate(
driver.VulkanHandle(physicalDevice.Handle()),
driver.Core1_2InstanceScope,
func() any {
return &VulkanInstanceScopedPhysicalDevice{
InstanceScopedPhysicalDevice: promotedPhysicalDevice,
}
}).(InstanceScopedPhysicalDevice)
}