Skip to content

Commit afe34eb

Browse files
committed
Use go memeory when pass array
1 parent 3e6b62b commit afe34eb

File tree

4 files changed

+118
-138
lines changed

4 files changed

+118
-138
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ The warping rules used in this package.
102102

103103
- Copy data between go and c, instead of pass memory.
104104

105-
- But no copy for `unsafe.Pointer`.
106-
105+
- Except Go arrays with same layout as C arrays in function params.
107106

108107
- No manual memory management is need.
109108

v1.1/vk/vk.auto.go

Lines changed: 8 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5998,19 +5998,13 @@ func ToGetQueryPoolResults(p PFNVoidFunction) (fn FuncGetQueryPoolResults) {
59985998
flags C.VkQueryResultFlags
59995999
_ret C.VkResult
60006000
}
6001-
m := pool.take()
6002-
defer pool.give(m)
60036001
c.device = C.VkDevice(device)
60046002
c.queryPool = C.VkQueryPool(queryPool)
60056003
c.firstQuery = C.uint32_t(firstQuery)
60066004
c.queryCount = C.uint32_t(queryCount)
60076005
c.dataSize = C.size_t(len(data))
60086006
if len(data) != 0 {
6009-
c.pData = m.alloc(C.sizeof_char * uint(len(data)))
6010-
slice1 := (*[1 << 31]byte)(c.pData)[:len(data):len(data)]
6011-
for i1, _ := range data {
6012-
slice1[i1] = data[i1]
6013-
}
6007+
c.pData = (unsafe.Pointer)(&data[0])
60146008
} else {
60156009
c.pData = nil
60166010
}
@@ -6030,12 +6024,6 @@ func ToGetQueryPoolResults(p PFNVoidFunction) (fn FuncGetQueryPoolResults) {
60306024
}
60316025
c._ret = C.callPFN_vkGetQueryPoolResults(C.PFN_vkGetQueryPoolResults(unsafe.Pointer(p)), c.device, c.queryPool, c.firstQuery, c.queryCount, c.dataSize, c.pData, c.stride, c.flags)
60326026
_ret = Result(c._ret)
6033-
if len(data) != 0 {
6034-
slice1 := (*[1 << 31]byte)(c.pData)[:len(data):len(data)]
6035-
for i1, _ := range data {
6036-
data[i1] = slice1[i1]
6037-
}
6038-
}
60396027
return
60406028
}
60416029
}
@@ -7137,11 +7125,7 @@ func ToGetPipelineCacheData(p PFNVoidFunction) (fn FuncGetPipelineCacheData) {
71377125
c.pDataSize = nil
71387126
}
71397127
if len(data) != 0 {
7140-
c.pData = m.alloc(C.sizeof_char * uint(len(data)))
7141-
slice1 := (*[1 << 31]byte)(c.pData)[:len(data):len(data)]
7142-
for i1, _ := range data {
7143-
slice1[i1] = data[i1]
7144-
}
7128+
c.pData = (unsafe.Pointer)(&data[0])
71457129
} else {
71467130
c.pData = nil
71477131
}
@@ -7150,12 +7134,6 @@ func ToGetPipelineCacheData(p PFNVoidFunction) (fn FuncGetPipelineCacheData) {
71507134
if dataSize != nil {
71517135
*dataSize = uint(*c.pDataSize)
71527136
}
7153-
if len(data) != 0 {
7154-
slice1 := (*[1 << 31]byte)(c.pData)[:len(data):len(data)]
7155-
for i1, _ := range data {
7156-
data[i1] = slice1[i1]
7157-
}
7158-
}
71597137
return
71607138
}
71617139
}
@@ -12648,8 +12626,6 @@ func ToCmdPushConstants(p PFNVoidFunction) (fn FuncCmdPushConstants) {
1264812626
size C.uint32_t
1264912627
pValues unsafe.Pointer
1265012628
}
12651-
m := pool.take()
12652-
defer pool.give(m)
1265312629
c.commandBuffer = C.VkCommandBuffer(commandBuffer)
1265412630
c.layout = C.VkPipelineLayout(layout)
1265512631
{
@@ -12664,11 +12640,7 @@ func ToCmdPushConstants(p PFNVoidFunction) (fn FuncCmdPushConstants) {
1266412640
c.offset = C.uint32_t(offset)
1266512641
c.size = C.uint32_t(len(values))
1266612642
if len(values) != 0 {
12667-
c.pValues = m.alloc(C.sizeof_char * uint(len(values)))
12668-
slice1 := (*[1 << 31]byte)(c.pValues)[:len(values):len(values)]
12669-
for i1, _ := range values {
12670-
slice1[i1] = values[i1]
12671-
}
12643+
c.pValues = (unsafe.Pointer)(&values[0])
1267212644
} else {
1267312645
c.pValues = nil
1267412646
}
@@ -14074,19 +14046,13 @@ func GetQueryPoolResults(device Device, queryPool QueryPool, firstQuery uint32,
1407414046
flags C.VkQueryResultFlags
1407514047
_ret C.VkResult
1407614048
}
14077-
m := pool.take()
14078-
defer pool.give(m)
1407914049
c.device = C.VkDevice(device)
1408014050
c.queryPool = C.VkQueryPool(queryPool)
1408114051
c.firstQuery = C.uint32_t(firstQuery)
1408214052
c.queryCount = C.uint32_t(queryCount)
1408314053
c.dataSize = C.size_t(len(data))
1408414054
if len(data) != 0 {
14085-
c.pData = m.alloc(C.sizeof_char * uint(len(data)))
14086-
slice1 := (*[1 << 31]byte)(c.pData)[:len(data):len(data)]
14087-
for i1, _ := range data {
14088-
slice1[i1] = data[i1]
14089-
}
14055+
c.pData = (unsafe.Pointer)(&data[0])
1409014056
} else {
1409114057
c.pData = nil
1409214058
}
@@ -14106,12 +14072,6 @@ func GetQueryPoolResults(device Device, queryPool QueryPool, firstQuery uint32,
1410614072
}
1410714073
c._ret = C.vkGetQueryPoolResults(c.device, c.queryPool, c.firstQuery, c.queryCount, c.dataSize, c.pData, c.stride, c.flags)
1410814074
_ret = Result(c._ret)
14109-
if len(data) != 0 {
14110-
slice1 := (*[1 << 31]byte)(c.pData)[:len(data):len(data)]
14111-
for i1, _ := range data {
14112-
data[i1] = slice1[i1]
14113-
}
14114-
}
1411514075
return
1411614076
}
1411714077
func CreateBuffer(device Device, createInfo *BufferCreateInfo, allocator *AllocationCallbacks, buffer *Buffer) (_ret Result) {
@@ -14485,11 +14445,7 @@ func GetPipelineCacheData(device Device, pipelineCache PipelineCache, dataSize *
1448514445
c.pDataSize = nil
1448614446
}
1448714447
if len(data) != 0 {
14488-
c.pData = m.alloc(C.sizeof_char * uint(len(data)))
14489-
slice1 := (*[1 << 31]byte)(c.pData)[:len(data):len(data)]
14490-
for i1, _ := range data {
14491-
slice1[i1] = data[i1]
14492-
}
14448+
c.pData = (unsafe.Pointer)(&data[0])
1449314449
} else {
1449414450
c.pData = nil
1449514451
}
@@ -14498,12 +14454,6 @@ func GetPipelineCacheData(device Device, pipelineCache PipelineCache, dataSize *
1449814454
if dataSize != nil {
1449914455
*dataSize = uint(*c.pDataSize)
1450014456
}
14501-
if len(data) != 0 {
14502-
slice1 := (*[1 << 31]byte)(c.pData)[:len(data):len(data)]
14503-
for i1, _ := range data {
14504-
data[i1] = slice1[i1]
14505-
}
14506-
}
1450714457
return
1450814458
}
1450914459
func MergePipelineCaches(device Device, dstCache PipelineCache, srcCaches []PipelineCache) (_ret Result) {
@@ -16239,8 +16189,6 @@ func CmdPushConstants(commandBuffer CommandBuffer, layout PipelineLayout, stageF
1623916189
size C.uint32_t
1624016190
pValues unsafe.Pointer
1624116191
}
16242-
m := pool.take()
16243-
defer pool.give(m)
1624416192
c.commandBuffer = C.VkCommandBuffer(commandBuffer)
1624516193
c.layout = C.VkPipelineLayout(layout)
1624616194
{
@@ -16255,11 +16203,7 @@ func CmdPushConstants(commandBuffer CommandBuffer, layout PipelineLayout, stageF
1625516203
c.offset = C.uint32_t(offset)
1625616204
c.size = C.uint32_t(len(values))
1625716205
if len(values) != 0 {
16258-
c.pValues = m.alloc(C.sizeof_char * uint(len(values)))
16259-
slice1 := (*[1 << 31]byte)(c.pValues)[:len(values):len(values)]
16260-
for i1, _ := range values {
16261-
slice1[i1] = values[i1]
16262-
}
16206+
c.pValues = (unsafe.Pointer)(&values[0])
1626316207
} else {
1626416208
c.pValues = nil
1626516209
}
@@ -22117,18 +22061,12 @@ func ToCmdPushDescriptorSetWithTemplateKHR(p PFNVoidFunction) (fn FuncCmdPushDes
2211722061
set C.uint32_t
2211822062
pData unsafe.Pointer
2211922063
}
22120-
m := pool.take()
22121-
defer pool.give(m)
2212222064
c.commandBuffer = C.VkCommandBuffer(commandBuffer)
2212322065
c.descriptorUpdateTemplate = C.VkDescriptorUpdateTemplate(descriptorUpdateTemplate)
2212422066
c.layout = C.VkPipelineLayout(layout)
2212522067
c.set = C.uint32_t(len(data))
2212622068
if len(data) != 0 {
22127-
c.pData = m.alloc(C.sizeof_char * uint(len(data)))
22128-
slice1 := (*[1 << 31]byte)(c.pData)[:len(data):len(data)]
22129-
for i1, _ := range data {
22130-
slice1[i1] = data[i1]
22131-
}
22069+
c.pData = (unsafe.Pointer)(&data[0])
2213222070
} else {
2213322071
c.pData = nil
2213422072
}
@@ -27668,11 +27606,7 @@ func ToGetValidationCacheDataEXT(p PFNVoidFunction) (fn FuncGetValidationCacheDa
2766827606
c.pDataSize = nil
2766927607
}
2767027608
if len(data) != 0 {
27671-
c.pData = m.alloc(C.sizeof_char * uint(len(data)))
27672-
slice1 := (*[1 << 31]byte)(c.pData)[:len(data):len(data)]
27673-
for i1, _ := range data {
27674-
slice1[i1] = data[i1]
27675-
}
27609+
c.pData = (unsafe.Pointer)(&data[0])
2767627610
} else {
2767727611
c.pData = nil
2767827612
}
@@ -27681,12 +27615,6 @@ func ToGetValidationCacheDataEXT(p PFNVoidFunction) (fn FuncGetValidationCacheDa
2768127615
if dataSize != nil {
2768227616
*dataSize = uint(*c.pDataSize)
2768327617
}
27684-
if len(data) != 0 {
27685-
slice1 := (*[1 << 31]byte)(c.pData)[:len(data):len(data)]
27686-
for i1, _ := range data {
27687-
data[i1] = slice1[i1]
27688-
}
27689-
}
2769027618
return
2769127619
}
2769227620
}

0 commit comments

Comments
 (0)