This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
query_pool.go
61 lines (47 loc) · 1.61 KB
/
query_pool.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
package core1_0
/*
#include <stdlib.h>
#include "vulkan/vulkan.h"
*/
import "C"
import (
"github.com/CannibalVox/VKng/core/common"
"github.com/CannibalVox/VKng/core/driver"
"github.com/CannibalVox/cgoparam"
"unsafe"
)
type VulkanQueryPool struct {
deviceDriver driver.Driver
queryPoolHandle driver.VkQueryPool
device driver.VkDevice
maximumAPIVersion common.APIVersion
}
func (p *VulkanQueryPool) Handle() driver.VkQueryPool {
return p.queryPoolHandle
}
func (p *VulkanQueryPool) Driver() driver.Driver {
return p.deviceDriver
}
func (p *VulkanQueryPool) DeviceHandle() driver.VkDevice {
return p.device
}
func (p *VulkanQueryPool) APIVersion() common.APIVersion {
return p.maximumAPIVersion
}
func (p *VulkanQueryPool) Destroy(callbacks *driver.AllocationCallbacks) {
p.deviceDriver.VkDestroyQueryPool(p.device, p.queryPoolHandle, callbacks.Handle())
p.deviceDriver.ObjectStore().Delete(driver.VulkanHandle(p.queryPoolHandle))
}
func (p *VulkanQueryPool) PopulateResults(firstQuery, queryCount int, results []byte, resultStride int, flags QueryResultFlags) (common.VkResult, error) {
arena := cgoparam.GetAlloc()
defer cgoparam.ReturnAlloc(arena)
resultSize := len(results)
inPointer := arena.Malloc(resultSize)
res, err := p.deviceDriver.VkGetQueryPoolResults(p.device, p.queryPoolHandle, driver.Uint32(firstQuery), driver.Uint32(queryCount), driver.Size(resultSize), inPointer, driver.VkDeviceSize(resultStride), driver.VkQueryResultFlags(flags))
if err != nil {
return res, err
}
inBuffer := ([]byte)(unsafe.Slice((*byte)(inPointer), resultSize))
copy(results, inBuffer)
return res, nil
}