-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathComputeCopyImageOp.cpp
More file actions
52 lines (42 loc) · 1.87 KB
/
Copy pathComputeCopyImageOp.cpp
File metadata and controls
52 lines (42 loc) · 1.87 KB
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
/*
* Copyright (C) 2020 by Xu Xing (xu.xing@outlook.com)
*
* This code is licensed under the MIT license (MIT)
* (http://opensource.org/licenses/MIT)
*/
#include "ComputeCopyImageOp.h"
ComputeCopyImageOp::ComputeCopyImageOp() {}
ComputeCopyImageOp::~ComputeCopyImageOp() {}
ComputeCopyImageOp::ComputeCopyImageOp(const InitParams &init_params)
: ComputeOp(init_params) {}
void ComputeCopyImageOp::execute() {
// Prepare storage buffers.
const VkDeviceSize bufferSize =
(params_.inputWidth * params_.inputHeight) * sizeof(uint32_t);
const VkDeviceSize filterBufferSize =
(params_.filterWidth * params_.filterHeight) * sizeof(uint32_t);
const VkDeviceSize outputBufferSize =
(params_.outputWidth * params_.outputHeight) * sizeof(uint32_t);
// Copy input data to VRAM using a staging buffer.
{
createBufferWithData(VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
VK_BUFFER_USAGE_TRANSFER_DST_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &hostBuffer_,
&hostMemory_, bufferSize, params_.computeInput.data());
createDeviceImage(image_, params_.inputWidth, params_.inputHeight);
createSampler(image_, sampler_, view_);
copyHostBufferToDeviceImage(image_, hostBuffer_, params_.inputWidth,
params_.inputHeight);
VkDeviceMemory testMemory;
VkBuffer testBuffer;
createBufferWithData(VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
VK_BUFFER_USAGE_TRANSFER_DST_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &testBuffer,
&testMemory, bufferSize);
copyDeviceImageToHostBuffer(image_, params_.computeOutput.data(),
bufferSize, params_.inputWidth,
params_.inputHeight);
}
vkQueueWaitIdle(queue_);
// TODO: exit clean up.
}