| 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) { |
| 2805 | vk::SubresourceLayout tex_layout; |
| 2806 | if (!loadTexture(filename, nullptr, tex_layout, tex_obj.tex_width, tex_obj.tex_height)) { |
| 2807 | ERR_EXIT("Failed to load textures", "Load Texture Failure"); |
| 2808 | } |
| 2809 | |
| 2810 | auto const image_create_info = vk::ImageCreateInfo() |
| 2811 | .setImageType(vk::ImageType::e2D) |
| 2812 | .setFormat(vk::Format::eR8G8B8A8Srgb) |
| 2813 | .setExtent({tex_obj.tex_width, tex_obj.tex_height, 1}) |
| 2814 | .setMipLevels(1) |
| 2815 | .setArrayLayers(1) |
| 2816 | .setSamples(vk::SampleCountFlagBits::e1) |
| 2817 | .setTiling(tiling) |
| 2818 | .setUsage(usage) |
| 2819 | .setSharingMode(vk::SharingMode::eExclusive) |
| 2820 | .setInitialLayout(vk::ImageLayout::ePreinitialized); |
| 2821 | |
| 2822 | auto result = device.createImage(&image_create_info, nullptr, &tex_obj.image); |
| 2823 | VERIFY(result == vk::Result::eSuccess); |
| 2824 | |
| 2825 | vk::MemoryRequirements mem_reqs; |
| 2826 | device.getImageMemoryRequirements(tex_obj.image, &mem_reqs); |
| 2827 | |
| 2828 | tex_obj.mem_alloc.setAllocationSize(mem_reqs.size); |
| 2829 | tex_obj.mem_alloc.setMemoryTypeIndex(0); |
| 2830 | |
| 2831 | auto pass = memory_type_from_properties(mem_reqs.memoryTypeBits, required_props, tex_obj.mem_alloc.memoryTypeIndex); |
| 2832 | VERIFY(pass == true); |
| 2833 | |
| 2834 | result = device.allocateMemory(&tex_obj.mem_alloc, nullptr, &tex_obj.mem); |
| 2835 | VERIFY(result == vk::Result::eSuccess); |
| 2836 | |
| 2837 | result = device.bindImageMemory(tex_obj.image, tex_obj.mem, 0); |
| 2838 | VERIFY(result == vk::Result::eSuccess); |
| 2839 | |
| 2840 | if (required_props & vk::MemoryPropertyFlagBits::eHostVisible) { |
| 2841 | auto const subres = vk::ImageSubresource().setAspectMask(vk::ImageAspectFlagBits::eColor).setMipLevel(0).setArrayLayer(0); |
| 2842 | vk::SubresourceLayout layout; |
| 2843 | device.getImageSubresourceLayout(tex_obj.image, &subres, &layout); |
| 2844 | |
| 2845 | auto data = device.mapMemory(tex_obj.mem, 0, tex_obj.mem_alloc.allocationSize); |
| 2846 | VERIFY(data.result == vk::Result::eSuccess); |
| 2847 | |
| 2848 | if (!loadTexture(filename, (uint8_t *)data.value, layout, tex_obj.tex_width, tex_obj.tex_height)) { |
| 2849 | fprintf(stderr, "Error loading texture: %s\n", filename); |
| 2850 | } |
| 2851 | |
| 2852 | device.unmapMemory(tex_obj.mem); |
| 2853 | } |
| 2854 | |
| 2855 | tex_obj.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal; |
| 2856 | } |
| 2857 | |
| 2858 | void Demo::prepare_textures() { |
| 2859 | vk::Format const tex_format = vk::Format::eR8G8B8A8Srgb; |
nothing calls this directly
no test coverage detected