18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 02:42:46 +01:00

Windscreen water: the passes of the snow are optional

A snow kernel that doesn't compile (as water_snow.comp did on NVIDIA) leaves the glasses of the snow clear and the rain working, instead of disabling the whole simulation (OpenGL 4.6 and Vulkan).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD
This commit is contained in:
Claude
2026-11-24 12:22:07 +01:00
parent ab3b0e1565
commit 05be4bff29
3 changed files with 37 additions and 10 deletions
+17 -6
View File
@@ -73,10 +73,21 @@ bool opengl46_windscreen_water::gpu_init()
"water_snowlayer.comp"};
for (std::size_t i = 0; i < names.size(); ++i)
{
if (m_programs[i])
continue;
gl::shader shader(PROGRAM_NAMES[i]);
m_programs[i] = std::make_unique<gl::program>(std::vector<std::reference_wrapper<const gl::shader>>{shader});
try
{
gl::shader shader(names[i]);
m_programs[i] = std::make_unique<gl::program>(std::vector<std::reference_wrapper<const gl::shader>>{shader});
}
catch (gl::shader_exception const &e)
{
if (i < pass::snow)
throw;
// the passes of the snow are optional: without them the glasses of the snow stay clear, the rain works on
ErrorLog("windscreen water: can't use " + std::string(names[i]) + ", the glasses of the snow stay clear: " + std::string(e.what()));
m_programs[pass::snow].reset();
m_programs[pass::snowlayer].reset();
break;
}
}
}
catch (gl::shader_exception const &e)
@@ -172,7 +183,7 @@ bool opengl46_windscreen_water::gpu_bake(std::size_t const Slot, texture_handle
bool opengl46_windscreen_water::gpu_snow_layer(std::size_t const Slot, texture_handle const Atlas, texture_handle const Normal, gl::water_ubs const &Block)
{
if ((!m_storage) || (Slot >= gl::WATER_SLOTS) || (Atlas == null_handle) || (Normal == null_handle))
if ((!m_storage) || (!m_programs[pass::snowlayer]) || (Slot >= gl::WATER_SLOTS) || (Atlas == null_handle) || (Normal == null_handle))
return false;
auto &atlas{GfxRenderer->Texture(Atlas)};
auto &normal{GfxRenderer->Texture(Normal)};
@@ -224,7 +235,7 @@ void opengl46_windscreen_water::gpu_step(gl::water_ubs const &Block, std::uint32
run(pass::clear, cell_groups);
run(pass::grid, drop_groups);
// the snow of the glasses of the snow, a texel of their maps a thread
if (Block.snow_slots != glm::vec4{0.f})
if ((Block.snow_slots != glm::vec4{0.f}) && m_programs[pass::snow])
run(pass::snow, groups(static_cast<std::size_t>(gl::WATER_MAP) * gl::WATER_MAP));
gl::program::unbind();
}
+19 -4
View File
@@ -89,6 +89,7 @@ void windscreen_water::destroy()
m_storage.reset();
m_device = VK_NULL_HANDLE;
m_cleared = false;
m_snowkernels = true;
reset();
}
@@ -105,9 +106,23 @@ bool windscreen_water::gpu_init()
"water_snowlayer.comp"};
for (std::size_t i = 0; i < names.size(); ++i)
{
if (false == m_kernels[i].create(m_device, *m_pipelines, m_shaders->get(names[i]), m_passlayout, {}, names[i]))
try
{
throw gfx::shader_exception(std::string("no compute pipeline of ") + names[i]);
if (false == m_kernels[i].create(m_device, *m_pipelines, m_shaders->get(names[i]), m_passlayout, {}, names[i]))
{
throw gfx::shader_exception(std::string("no compute pipeline of ") + names[i]);
}
}
catch (gfx::shader_exception const &e)
{
if (i < pass::snow)
{
throw;
}
// the passes of the snow are optional: without them the glasses of the snow stay clear, the rain works on
ErrorLog("windscreen water: can't use " + std::string(names[i]) + ", the glasses of the snow stay clear: " + std::string(e.what()));
m_snowkernels = false;
break;
}
}
}
@@ -271,7 +286,7 @@ bool windscreen_water::gpu_bake(std::size_t const Slot, texture_handle const Mas
bool windscreen_water::gpu_snow_layer(std::size_t const Slot, texture_handle const Atlas, texture_handle const Normal, gl::water_ubs const &Block)
{
auto const commands{m_host.commands()};
if ((commands == nullptr) || (false == m_full) || (Slot >= gl::WATER_SLOTS))
if ((commands == nullptr) || (false == m_full) || (false == m_snowkernels) || (Slot >= gl::WATER_SLOTS))
{
return false;
}
@@ -341,7 +356,7 @@ void windscreen_water::gpu_step(gl::water_ubs const &Block, std::uint32_t const
run(pass::clear, cell_groups);
run(pass::grid, drop_groups);
// the snow of the glasses of the snow, a texel of their maps a thread
if (Block.snow_slots != glm::vec4{0.f})
if ((Block.snow_slots != glm::vec4{0.f}) && m_snowkernels)
{
run(pass::snow, groups(static_cast<std::size_t>(gl::WATER_MAP) * gl::WATER_MAP));
}
+1
View File
@@ -105,6 +105,7 @@ class windscreen_water : public gfx::windscreen_water
bool m_raincelltried{false};
bool m_full{false}; // the storage is as large as the simulation needs (else a stand-in, the glasses make their water up)
bool m_cleared{false};
bool m_snowkernels{true}; // the passes of the snow made (they are optional: without them the glasses of the snow stay clear)
};
} // namespace vk14