| 2398 | } |
| 2399 | |
| 2400 | void Demo::prepare_cube_data_buffers() { |
| 2401 | mat4x4 VP; |
| 2402 | mat4x4_mul(VP, projection_matrix, view_matrix); |
| 2403 | |
| 2404 | mat4x4 MVP; |
| 2405 | mat4x4_mul(MVP, VP, model_matrix); |
| 2406 | |
| 2407 | vktexcube_vs_uniform data; |
| 2408 | memcpy(data.mvp, MVP, sizeof(MVP)); |
| 2409 | // dumpMatrix("MVP", MVP) |
| 2410 | |
| 2411 | for (int32_t i = 0; i < 12 * 3; i++) { |
| 2412 | data.position[i][0] = g_vertex_buffer_data[i * 3]; |
| 2413 | data.position[i][1] = g_vertex_buffer_data[i * 3 + 1]; |
| 2414 | data.position[i][2] = g_vertex_buffer_data[i * 3 + 2]; |
| 2415 | data.position[i][3] = 1.0f; |
| 2416 | data.attr[i][0] = g_uv_buffer_data[2 * i]; |
| 2417 | data.attr[i][1] = g_uv_buffer_data[2 * i + 1]; |
| 2418 | data.attr[i][2] = 0; |
| 2419 | data.attr[i][3] = 0; |
| 2420 | } |
| 2421 | |
| 2422 | auto const buf_info = vk::BufferCreateInfo().setSize(sizeof(data)).setUsage(vk::BufferUsageFlagBits::eUniformBuffer); |
| 2423 | |
| 2424 | for (auto &submission_resource : submission_resources) { |
| 2425 | auto result = device.createBuffer(&buf_info, nullptr, &submission_resource.uniform_buffer); |
| 2426 | VERIFY(result == vk::Result::eSuccess); |
| 2427 | |
| 2428 | vk::MemoryRequirements mem_reqs; |
| 2429 | device.getBufferMemoryRequirements(submission_resource.uniform_buffer, &mem_reqs); |
| 2430 | |
| 2431 | auto mem_alloc = vk::MemoryAllocateInfo().setAllocationSize(mem_reqs.size).setMemoryTypeIndex(0); |
| 2432 | |
| 2433 | bool const pass = memory_type_from_properties( |
| 2434 | mem_reqs.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent, |
| 2435 | mem_alloc.memoryTypeIndex); |
| 2436 | VERIFY(pass); |
| 2437 | |
| 2438 | result = device.allocateMemory(&mem_alloc, nullptr, &submission_resource.uniform_memory); |
| 2439 | VERIFY(result == vk::Result::eSuccess); |
| 2440 | |
| 2441 | result = device.mapMemory(submission_resource.uniform_memory, 0, VK_WHOLE_SIZE, vk::MemoryMapFlags(), |
| 2442 | &submission_resource.uniform_memory_ptr); |
| 2443 | VERIFY(result == vk::Result::eSuccess); |
| 2444 | |
| 2445 | memcpy(submission_resource.uniform_memory_ptr, &data, sizeof data); |
| 2446 | |
| 2447 | result = device.bindBufferMemory(submission_resource.uniform_buffer, submission_resource.uniform_memory, 0); |
| 2448 | VERIFY(result == vk::Result::eSuccess); |
| 2449 | } |
| 2450 | } |
| 2451 | |
| 2452 | void Demo::prepare_depth() { |
| 2453 | depth.format = vk::Format::eD16Unorm; |
nothing calls this directly
no test coverage detected