| 2758 | } |
| 2759 | |
| 2760 | void Demo::prepare_texture_buffer(const char *filename, texture_object &tex_obj) { |
| 2761 | vk::SubresourceLayout tex_layout; |
| 2762 | |
| 2763 | if (!loadTexture(filename, nullptr, tex_layout, tex_obj.tex_width, tex_obj.tex_height)) { |
| 2764 | ERR_EXIT("Failed to load textures", "Load Texture Failure"); |
| 2765 | } |
| 2766 | |
| 2767 | auto const buffer_create_info = vk::BufferCreateInfo() |
| 2768 | .setSize(tex_obj.tex_width * tex_obj.tex_height * 4) |
| 2769 | .setUsage(vk::BufferUsageFlagBits::eTransferSrc) |
| 2770 | .setSharingMode(vk::SharingMode::eExclusive); |
| 2771 | |
| 2772 | auto result = device.createBuffer(&buffer_create_info, nullptr, &tex_obj.buffer); |
| 2773 | VERIFY(result == vk::Result::eSuccess); |
| 2774 | |
| 2775 | vk::MemoryRequirements mem_reqs; |
| 2776 | device.getBufferMemoryRequirements(tex_obj.buffer, &mem_reqs); |
| 2777 | |
| 2778 | tex_obj.mem_alloc.setAllocationSize(mem_reqs.size); |
| 2779 | tex_obj.mem_alloc.setMemoryTypeIndex(0); |
| 2780 | |
| 2781 | vk::MemoryPropertyFlags requirements = vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent; |
| 2782 | auto pass = memory_type_from_properties(mem_reqs.memoryTypeBits, requirements, tex_obj.mem_alloc.memoryTypeIndex); |
| 2783 | VERIFY(pass == true); |
| 2784 | |
| 2785 | result = device.allocateMemory(&tex_obj.mem_alloc, nullptr, &(tex_obj.mem)); |
| 2786 | VERIFY(result == vk::Result::eSuccess); |
| 2787 | |
| 2788 | result = device.bindBufferMemory(tex_obj.buffer, tex_obj.mem, 0); |
| 2789 | VERIFY(result == vk::Result::eSuccess); |
| 2790 | |
| 2791 | vk::SubresourceLayout layout; |
| 2792 | layout.rowPitch = tex_obj.tex_width * 4; |
| 2793 | auto data = device.mapMemory(tex_obj.mem, 0, tex_obj.mem_alloc.allocationSize); |
| 2794 | VERIFY(data.result == vk::Result::eSuccess); |
| 2795 | |
| 2796 | if (!loadTexture(filename, (uint8_t *)data.value, layout, tex_obj.tex_width, tex_obj.tex_height)) { |
| 2797 | fprintf(stderr, "Error loading texture: %s\n", filename); |
| 2798 | } |
| 2799 | |
| 2800 | device.unmapMemory(tex_obj.mem); |
| 2801 | } |
| 2802 | |
| 2803 | void Demo::prepare_texture_image(const char *filename, texture_object &tex_obj, vk::ImageTiling tiling, vk::ImageUsageFlags usage, |
| 2804 | vk::MemoryPropertyFlags required_props) { |
nothing calls this directly
no test coverage detected