Testing VulkanImage TransferDataWithVkBuffer.
Init with ArrayData.
Instance a staginBuffer for transfer data from array to image.
Copy the data from array to staginBuffer.
Transform Image Layout from origin to Transfer_dst.
Copy the data from staginBuffer to Image.
Iter all texel and test is get the data correct.
Copy the data from Image to array.
84 {
85
89 std::array<float, m_TextureSize* m_TextureSize * 4> dataArray;
90 for (int i = 0; i < m_TextureSize * m_TextureSize * 4; i++)
91 {
92 dataArray[i] = i + 0.0f;
93 }
94
99 m_RenderBackend->GetState(),
100 "StagingBuffer",
101 sizeof(dataArray),
102 VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
103 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
104 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
105 );
106
110 stagingBuffer.WriteToBuffer(dataArray.data());
111
115 m_VulkanImage->TransitionImageLayout(VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
116
120 m_VulkanImage->CopyBufferToImage(stagingBuffer.Get(), m_VulkanImage->GetImage(), static_cast<uint32_t>(m_TextureSize), static_cast<uint32_t>(m_TextureSize));
121
125 for (int i = 0; i < m_TextureSize; i++)
126 {
127 for (int j = 0; j < m_TextureSize; j++)
128 {
132 std::array<float, 4> outDta;
133 m_VulkanImage->CopyImageTexelToBuffer(i, j, reinterpret_cast<void*>(outDta.data()));
134
135 EXPECT_EQ(outDta[0], 4.0f * m_TextureSize * j + 4.0f * i + 0.0f);
136 EXPECT_EQ(outDta[1], 4.0f * m_TextureSize * j + 4.0f * i + 1.0f);
137 EXPECT_EQ(outDta[2], 4.0f * m_TextureSize * j + 4.0f * i + 2.0f);
138 EXPECT_EQ(outDta[3], 4.0f * m_TextureSize * j + 4.0f * i + 3.0f);
139 }
140 }
141 }
This Class is a Wrapper of VulkanBuffer.