(Shaders vulkan/GLcore) Simplify

This commit is contained in:
twinaphex 2019-04-25 02:34:26 +02:00
parent e40c3ec07b
commit 15afaedaa8
2 changed files with 87 additions and 71 deletions

View File

@ -1077,9 +1077,9 @@ bool Pass::build()
framebuffer = unique_ptr<Framebuffer>( framebuffer = unique_ptr<Framebuffer>(
new Framebuffer(pass_info.rt_format, pass_info.max_levels)); new Framebuffer(pass_info.rt_format, pass_info.max_levels));
for (auto &param : parameters) for (i = 0; i < parameters.size(); i++)
{ {
if (!gl_core_shader_set_unique_map(semantic_map, param.id, if (!gl_core_shader_set_unique_map(semantic_map, parameters[i].id,
slang_semantic_map{ SLANG_SEMANTIC_FLOAT_PARAMETER, j })) slang_semantic_map{ SLANG_SEMANTIC_FLOAT_PARAMETER, j }))
return false; return false;
j++; j++;
@ -1863,16 +1863,16 @@ void gl_core_filter_chain::build_offscreen_passes(const gl_core_viewport &vp)
{ {
passes[i]->build_commands(original, source, vp, nullptr); passes[i]->build_commands(original, source, vp, nullptr);
auto &fb = passes[i]->get_framebuffer(); const gl_core::Framebuffer &fb = passes[i]->get_framebuffer();
source.texture.image = fb.get_image(); source.texture.image = fb.get_image();
source.texture.width = fb.get_size().width; source.texture.width = fb.get_size().width;
source.texture.height = fb.get_size().height; source.texture.height = fb.get_size().height;
source.filter = passes[i + 1]->get_source_filter(); source.filter = passes[i + 1]->get_source_filter();
source.mip_filter = passes[i + 1]->get_mip_filter(); source.mip_filter = passes[i + 1]->get_mip_filter();
source.address = passes[i + 1]->get_address_mode(); source.address = passes[i + 1]->get_address_mode();
common.pass_outputs[i] = source; common.pass_outputs[i] = source;
} }
} }
@ -1909,7 +1909,8 @@ void gl_core_filter_chain::build_viewport_pass(
const gl_core_viewport &vp, const float *mvp) const gl_core_viewport &vp, const float *mvp)
{ {
unsigned i; unsigned i;
/* First frame, make sure our history and feedback textures are in a clean state. */ /* First frame, make sure our history and
* feedback textures are in a clean state. */
if (require_clear) if (require_clear)
{ {
clear_history_and_feedback(); clear_history_and_feedback();
@ -1935,13 +1936,14 @@ void gl_core_filter_chain::build_viewport_pass(
} }
else else
{ {
auto &fb = passes[passes.size() - 2]->get_framebuffer(); const gl_core::Framebuffer &fb = passes[passes.size() - 2]
source.texture.image = fb.get_image(); ->get_framebuffer();
source.texture.width = fb.get_size().width; source.texture.image = fb.get_image();
source.texture.height = fb.get_size().height; source.texture.width = fb.get_size().width;
source.filter = passes.back()->get_source_filter(); source.texture.height = fb.get_size().height;
source.mip_filter = passes.back()->get_mip_filter(); source.filter = passes.back()->get_source_filter();
source.address = passes.back()->get_address_mode(); source.mip_filter = passes.back()->get_mip_filter();
source.address = passes.back()->get_address_mode();
} }
passes.back()->build_commands(original, source, vp, mvp); passes.back()->build_commands(original, source, vp, mvp);
@ -2034,43 +2036,49 @@ bool gl_core_filter_chain::init_feedback()
bool gl_core_filter_chain::init_alias() bool gl_core_filter_chain::init_alias()
{ {
unsigned i, j;
common.texture_semantic_map.clear(); common.texture_semantic_map.clear();
common.texture_semantic_uniform_map.clear(); common.texture_semantic_uniform_map.clear();
for (auto &pass : passes) for (i = 0; i < passes.size(); i++)
{ {
auto &name = pass->get_name(); const string name = passes[i]->get_name();
if (name.empty()) if (name.empty())
continue; continue;
unsigned i = &pass - passes.data(); j = &passes[i] - passes.data();
if (!gl_core_shader_set_unique_map(common.texture_semantic_map, name, if (!gl_core_shader_set_unique_map(common.texture_semantic_map, name,
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, i })) slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j }))
return false; return false;
if (!gl_core_shader_set_unique_map(common.texture_semantic_uniform_map, name + "Size", if (!gl_core_shader_set_unique_map(common.texture_semantic_uniform_map,
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, i })) name + "Size",
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j }))
return false; return false;
if (!gl_core_shader_set_unique_map(common.texture_semantic_map, name + "Feedback", if (!gl_core_shader_set_unique_map(common.texture_semantic_map,
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, i })) name + "Feedback",
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
return false; return false;
if (!gl_core_shader_set_unique_map(common.texture_semantic_uniform_map, name + "FeedbackSize", if (!gl_core_shader_set_unique_map(common.texture_semantic_uniform_map,
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, i })) name + "FeedbackSize",
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
return false; return false;
} }
for (auto &lut : common.luts) for (i = 0; i < common.luts.size(); i++)
{ {
unsigned i = &lut - common.luts.data(); j = &common.luts[i] - common.luts.data();
if (!gl_core_shader_set_unique_map(common.texture_semantic_map, lut->get_id(), if (!gl_core_shader_set_unique_map(common.texture_semantic_map,
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, i })) common.luts[i]->get_id(),
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
return false; return false;
if (!gl_core_shader_set_unique_map(common.texture_semantic_uniform_map, lut->get_id() + "Size", if (!gl_core_shader_set_unique_map(common.texture_semantic_uniform_map,
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, i })) common.luts[i]->get_id() + "Size",
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
return false; return false;
} }
@ -2104,7 +2112,8 @@ void gl_core_filter_chain::set_shader(unsigned pass, GLenum stage, const uint32_
passes[pass]->set_shader(stage, spirv, spirv_words); passes[pass]->set_shader(stage, spirv, spirv_words);
} }
void gl_core_filter_chain::add_parameter(unsigned pass, unsigned index, const std::string &id) void gl_core_filter_chain::add_parameter(unsigned pass,
unsigned index, const std::string &id)
{ {
passes[pass]->add_parameter(index, id); passes[pass]->add_parameter(index, id);
} }
@ -2118,14 +2127,13 @@ bool gl_core_filter_chain::init()
for (i = 0; i < passes.size(); i++) for (i = 0; i < passes.size(); i++)
{ {
auto &pass = passes[i];
RARCH_LOG("[slang]: Building pass #%u (%s)\n", i, RARCH_LOG("[slang]: Building pass #%u (%s)\n", i,
pass->get_name().empty() ? passes[i]->get_name().empty() ?
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE) : msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE) :
pass->get_name().c_str()); passes[i]->get_name().c_str());
pass->set_pass_info(pass_info[i]); passes[i]->set_pass_info(pass_info[i]);
if (!pass->build()) if (!passes[i]->build())
return false; return false;
} }

View File

@ -624,6 +624,7 @@ void vulkan_filter_chain::set_num_sync_indices(unsigned num_indices)
void vulkan_filter_chain::notify_sync_index(unsigned index) void vulkan_filter_chain::notify_sync_index(unsigned index)
{ {
unsigned i;
auto &calls = deferred_calls[index]; auto &calls = deferred_calls[index];
for (auto &call : calls) for (auto &call : calls)
call(); call();
@ -631,8 +632,8 @@ void vulkan_filter_chain::notify_sync_index(unsigned index)
current_sync_index = index; current_sync_index = index;
for (auto &pass : passes) for (i = 0; i < passes.size(); i++)
pass->notify_sync_index(index); passes[i]->notify_sync_index(index);
} }
bool vulkan_filter_chain::update_swapchain_info( bool vulkan_filter_chain::update_swapchain_info(
@ -645,8 +646,9 @@ bool vulkan_filter_chain::update_swapchain_info(
void vulkan_filter_chain::release_staging_buffers() void vulkan_filter_chain::release_staging_buffers()
{ {
for (auto &lut : common.luts) unsigned i;
lut->release_staging_buffer(); for (i = 0; i < common.luts.size(); i++)
common.luts[i]->release_staging_buffer();
} }
void vulkan_filter_chain::execute_deferred() void vulkan_filter_chain::execute_deferred()
@ -747,7 +749,7 @@ void vulkan_filter_chain::build_offscreen_passes(VkCommandBuffer cmd,
passes[i]->build_commands(disposer, cmd, passes[i]->build_commands(disposer, cmd,
original, source, vp, nullptr); original, source, vp, nullptr);
auto &fb = passes[i]->get_framebuffer(); const Framebuffer &fb = passes[i]->get_framebuffer();
source.texture.view = fb.get_view(); source.texture.view = fb.get_view();
source.texture.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; source.texture.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
@ -757,11 +759,12 @@ void vulkan_filter_chain::build_offscreen_passes(VkCommandBuffer cmd,
source.mip_filter = passes[i + 1]->get_mip_filter(); source.mip_filter = passes[i + 1]->get_mip_filter();
source.address = passes[i + 1]->get_address_mode(); source.address = passes[i + 1]->get_address_mode();
common.pass_outputs[i] = source; common.pass_outputs[i] = source;
} }
} }
void vulkan_filter_chain::update_history(DeferredDisposer &disposer, VkCommandBuffer cmd) void vulkan_filter_chain::update_history(DeferredDisposer &disposer,
VkCommandBuffer cmd)
{ {
unique_ptr<Framebuffer> tmp; unique_ptr<Framebuffer> tmp;
VkImageLayout src_layout = input_texture.layout; VkImageLayout src_layout = input_texture.layout;
@ -827,7 +830,8 @@ void vulkan_filter_chain::build_viewport_pass(
VkCommandBuffer cmd, const VkViewport &vp, const float *mvp) VkCommandBuffer cmd, const VkViewport &vp, const float *mvp)
{ {
unsigned i; unsigned i;
/* First frame, make sure our history and feedback textures are in a clean state. */ /* First frame, make sure our history and
* feedback textures are in a clean state. */
if (require_clear) if (require_clear)
{ {
clear_history_and_feedback(cmd); clear_history_and_feedback(cmd);
@ -854,7 +858,7 @@ void vulkan_filter_chain::build_viewport_pass(
} }
else else
{ {
auto &fb = passes[passes.size() - 2]->get_framebuffer(); const Framebuffer &fb = passes[passes.size() - 2]->get_framebuffer();
source.texture.view = fb.get_view(); source.texture.view = fb.get_view();
source.texture.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; source.texture.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
source.texture.width = fb.get_size().width; source.texture.width = fb.get_size().width;
@ -957,43 +961,46 @@ bool vulkan_filter_chain::init_feedback()
bool vulkan_filter_chain::init_alias() bool vulkan_filter_chain::init_alias()
{ {
unsigned i, j;
common.texture_semantic_map.clear(); common.texture_semantic_map.clear();
common.texture_semantic_uniform_map.clear(); common.texture_semantic_uniform_map.clear();
for (auto &pass : passes) for (i = 0; i < passes.size(); i++)
{ {
auto &name = pass->get_name(); const string name = passes[i]->get_name();
if (name.empty()) if (name.empty())
continue; continue;
unsigned i = &pass - passes.data(); j = &passes[i] - passes.data();
if (!vk_shader_set_unique_map(common.texture_semantic_map, name, if (!vk_shader_set_unique_map(common.texture_semantic_map, name,
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, i })) slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j }))
return false; return false;
if (!vk_shader_set_unique_map(common.texture_semantic_uniform_map, name + "Size", if (!vk_shader_set_unique_map(common.texture_semantic_uniform_map, name + "Size",
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, i })) slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j }))
return false; return false;
if (!vk_shader_set_unique_map(common.texture_semantic_map, name + "Feedback", if (!vk_shader_set_unique_map(common.texture_semantic_map, name + "Feedback",
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, i })) slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
return false; return false;
if (!vk_shader_set_unique_map(common.texture_semantic_uniform_map, name + "FeedbackSize", if (!vk_shader_set_unique_map(common.texture_semantic_uniform_map, name + "FeedbackSize",
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, i })) slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j }))
return false; return false;
} }
for (auto &lut : common.luts) for (i = 0; i < common.luts.size(); i++)
{ {
unsigned i = &lut - common.luts.data(); j = &common.luts[i] - common.luts.data();
if (!vk_shader_set_unique_map(common.texture_semantic_map, lut->get_id(), if (!vk_shader_set_unique_map(common.texture_semantic_map,
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, i })) common.luts[i]->get_id(),
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
return false; return false;
if (!vk_shader_set_unique_map(common.texture_semantic_uniform_map, lut->get_id() + "Size", if (!vk_shader_set_unique_map(common.texture_semantic_uniform_map,
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, i })) common.luts[i]->get_id() + "Size",
slang_texture_semantic_map{ SLANG_TEXTURE_SEMANTIC_USER, j }))
return false; return false;
} }
@ -1031,7 +1038,8 @@ void vulkan_filter_chain::set_shader(
passes[pass]->set_shader(stage, spirv, spirv_words); passes[pass]->set_shader(stage, spirv, spirv_words);
} }
void vulkan_filter_chain::add_parameter(unsigned pass, unsigned index, const std::string &id) void vulkan_filter_chain::add_parameter(unsigned pass,
unsigned index, const std::string &id)
{ {
passes[pass]->add_parameter(index, id); passes[pass]->add_parameter(index, id);
} }
@ -1077,15 +1085,15 @@ bool vulkan_filter_chain::init()
for (i = 0; i < passes.size(); i++) for (i = 0; i < passes.size(); i++)
{ {
auto &pass = passes[i]; const string name = passes[i]->get_name();
RARCH_LOG("[slang]: Building pass #%u (%s)\n", i, RARCH_LOG("[slang]: Building pass #%u (%s)\n", i,
pass->get_name().empty() ? name.empty() ?
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE) : msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE) :
pass->get_name().c_str()); name.c_str());
source = pass->set_pass_info(max_input_size, source = passes[i]->set_pass_info(max_input_size,
source, swapchain_info, pass_info[i]); source, swapchain_info, pass_info[i]);
if (!pass->build()) if (!passes[i]->build())
return false; return false;
} }
@ -1957,9 +1965,9 @@ bool Pass::build()
current_framebuffer_size, current_framebuffer_size,
pass_info.rt_format, pass_info.max_levels)); pass_info.rt_format, pass_info.max_levels));
for (auto &param : parameters) for (i = 0; i < parameters.size(); i++)
{ {
if (!vk_shader_set_unique_map(semantic_map, param.id, if (!vk_shader_set_unique_map(semantic_map, parameters[i].id,
slang_semantic_map{ SLANG_SEMANTIC_FLOAT_PARAMETER, j })) slang_semantic_map{ SLANG_SEMANTIC_FLOAT_PARAMETER, j }))
return false; return false;
j++; j++;
@ -2215,7 +2223,7 @@ void Pass::build_commands(
const float *mvp) const float *mvp)
{ {
current_viewport = vp; current_viewport = vp;
auto size = get_output_size( Size2D size = get_output_size(
{ original.texture.width, original.texture.height }, { original.texture.width, original.texture.height },
{ source.texture.width, source.texture.height }); { source.texture.width, source.texture.height });