Skip to content

Instantly share code, notes, and snippets.

@NotAPenguin0
Created May 23, 2020 13:58
Show Gist options
  • Select an option

  • Save NotAPenguin0/b79a0fab4175e237bf9f42ec4ba12c81 to your computer and use it in GitHub Desktop.

Select an option

Save NotAPenguin0/b79a0fab4175e237bf9f42ec4ba12c81 to your computer and use it in GitHub Desktop.
compute
void EnvMapLoader::create_specular_map(ftl::TaskScheduler* scheduler, ph::VulkanContext& vulkan, EnvMapProcessData& process_data) {
const uint32_t mip_count = std::log2(process_data.specular_map_base_size) + 1;
process_data.specular_map = ph::create_image(vulkan, process_data.specular_map_base_size, process_data.specular_map_base_size,
ph::ImageType::EnvMap, vk::Format::eR32G32B32A32Sfloat, 6, mip_count);
process_data.specular_map_view = ph::create_image_view(vulkan.device, process_data.specular_map);
process_data.specular_map_mips.resize(mip_count);
for (uint32_t level = 0; level < mip_count; ++level) {
process_data.specular_map_mips[level] = ph::create_image_view_level(vulkan.device, process_data.specular_map, level);
}
ph::transition_image_layout(process_data.raw_cmd_buf, process_data.specular_map, vk::ImageLayout::eGeneral);
ph::CommandBuffer& cmd_buf = *process_data.cmd_buf;
ph::Pipeline pipeline = cmd_buf.get_compute_pipeline("irradiance_map_convolution");
cmd_buf.bind_pipeline(pipeline);
for (uint32_t level = 0; level < mip_count; ++level) {
ph::DescriptorSetBinding set_binding;
set_binding.add(ph::make_descriptor(specular_prefiter_bindings.cube_map, process_data.cubemap_view, sampler, vk::ImageLayout::eGeneral));
set_binding.add(ph::make_descriptor(specular_prefiter_bindings.specular_map,
process_data.specular_map_mips[level], vk::ImageLayout::eGeneral));
vk::DescriptorSet descr_set = cmd_buf.get_descriptor(set_binding);
cmd_buf.bind_descriptor_set(0, descr_set);
uint32_t const mip_size = process_data.specular_map_base_size / pow(2, level);
cmd_buf.dispatch_compute(std::max(mip_size / 16, 1u), std::max(mip_size / 16, 1u), 6);
}
}
void EnvMapLoader::end_preprocess_commands(ftl::TaskScheduler* scheduler, ph::VulkanContext& vulkan, EnvMapProcessData& process_data) {
uint32_t const thread_index = scheduler->GetCurrentThreadIndex();
// vulkan.compute->release_ownership(process_data.raw_cmd_buf, process_data.irradiance_map, *vulkan.graphics);
// vulkan.compute->release_ownership(process_data.raw_cmd_buf, process_data.cube_map, *vulkan.graphics);
vk::Fence fence = vulkan.device.createFence({});
vulkan.compute->end_single_time(process_data.raw_cmd_buf, fence, vk::PipelineStageFlagBits::eTransfer, process_data.transfer_done);
vulkan.device.waitForFences(fence, true, std::numeric_limits<uint64_t>::max());
//vk::CommandBuffer gfx_commands = vulkan.graphics->begin_single_time(thread_index);
//// Acquire ownership
//vulkan.graphics->acquire_ownership(gfx_commands, process_data.irradiance_map, *vulkan.compute);
//vulkan.graphics->acquire_ownership(gfx_commands, process_data.cube_map, *vulkan.compute);
//// Transition textures to ShaderReadOnlyOptimal
//ph::transition_image_layout(gfx_commands, process_data.irradiance_map, vk::ImageLayout::eShaderReadOnlyOptimal);
//ph::transition_image_layout(gfx_commands, process_data.cube_map, vk::ImageLayout::eShaderReadOnlyOptimal);
//
//vulkan.device.resetFences(fence);
//vulkan.graphics->end_single_time(gfx_commands, fence);
//vulkan.device.waitForFences(fence, true, std::numeric_limits<uint64_t>::max());
//vulkan.graphics->free_single_time(gfx_commands, thread_index);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment