Skip to content

Commit

Permalink
Add debugRecompileAllPipelines, "Recompile All Shaders" button to Scr…
Browse files Browse the repository at this point in the history
…ipt Debugger
  • Loading branch information
past-due committed Jan 13, 2024
1 parent 50c8585 commit 92c20e7
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/ivis_opengl/gfx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ namespace gfx_api
virtual bool supportsInstancedRendering() = 0;
virtual void draw_instanced(const std::size_t& offset, const std::size_t &count, const primitive_type &primitive, std::size_t instance_count) = 0;
virtual void draw_elements_instanced(const std::size_t& offset, const std::size_t& count, const primitive_type& primitive, const index_type& index, std::size_t instance_count) = 0;
// debug apis for recompiling pipelines
virtual bool debugRecompileAllPipelines() = 0;
public:
// High-level API for getting a texture object from file / uncompressed bitmap
gfx_api::texture* loadTextureFromFile(const char *filename, gfx_api::texture_type textureType, int maxWidth = -1, int maxHeight = -1, bool quiet = false);
Expand Down
14 changes: 14 additions & 0 deletions lib/ivis_opengl/gfx_api_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4361,6 +4361,20 @@ bool gl_context::setShadowConstants(gfx_api::lighting_constants newValues)
return true;
}

bool gl_context::debugRecompileAllPipelines()
{
bool patchFragmentShaderMipLodBias = true; // provide the constant to the shader directly
for (auto& pipelineInfo : createdPipelines)
{
if (pipelineInfo.pso)
{
delete pipelineInfo.pso;
pipelineInfo.pso = new gl_pipeline_state_object(gles, fragmentHighpFloatAvailable, fragmentHighpIntAvailable, patchFragmentShaderMipLodBias, pipelineInfo.createInfo, mipLodBias, shadowConstants);
}
}
return true;
}

static const char *cbframebuffererror(GLenum err)
{
switch (err)
Expand Down
2 changes: 2 additions & 0 deletions lib/ivis_opengl/gfx_api_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ struct gl_context final : public gfx_api::context
virtual bool supportsInstancedRendering() override;
virtual void draw_instanced(const std::size_t& offset, const std::size_t &count, const gfx_api::primitive_type &primitive, std::size_t instance_count) override;
virtual void draw_elements_instanced(const std::size_t& offset, const std::size_t& count, const gfx_api::primitive_type& primitive, const gfx_api::index_type& index, std::size_t instance_count) override;
// debug apis for recompiling pipelines
virtual bool debugRecompileAllPipelines() override;
private:
virtual bool _initialize(const gfx_api::backend_Impl_Factory& impl, int32_t antialiasing, swap_interval_mode mode, optional<float> mipLodBias, uint32_t depthMapResolution) override;
void initPixelFormatsSupport();
Expand Down
5 changes: 5 additions & 0 deletions lib/ivis_opengl/gfx_api_null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ bool null_context::setShadowConstants(gfx_api::lighting_constants newValues)
return true;
}

bool null_context::debugRecompileAllPipelines()
{
return true;
}

bool null_context::supportsInstancedRendering()
{
return false;
Expand Down
2 changes: 2 additions & 0 deletions lib/ivis_opengl/gfx_api_null.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ struct null_context final : public gfx_api::context
virtual bool supportsInstancedRendering() override;
virtual void draw_instanced(const std::size_t& offset, const std::size_t &count, const gfx_api::primitive_type &primitive, std::size_t instance_count) override;
virtual void draw_elements_instanced(const std::size_t& offset, const std::size_t& count, const gfx_api::primitive_type& primitive, const gfx_api::index_type& index, std::size_t instance_count) override;
// debug apis for recompiling pipelines
virtual bool debugRecompileAllPipelines() override;
private:
virtual bool _initialize(const gfx_api::backend_Impl_Factory& impl, int32_t antialiasing, swap_interval_mode mode, optional<float> mipLodBias, uint32_t depthMapResolution) override;
private:
Expand Down
22 changes: 22 additions & 0 deletions lib/ivis_opengl/gfx_api_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6185,4 +6185,26 @@ bool VkRoot::setShadowConstants(gfx_api::lighting_constants newValues)
return true;
}

bool VkRoot::debugRecompileAllPipelines()
{
for (auto& pipelineInfo : createdPipelines)
{
for (size_t renderPassId = 0; renderPassId < pipelineInfo.renderPassPSO.size(); ++renderPassId)
{
auto pipeline = pipelineInfo.renderPassPSO[renderPassId];
if (pipeline == nullptr)
{
continue;
}

auto& renderPass = renderPasses[renderPassId];

ASSERT(pipeline->renderpass_compat, "Pipeline has no associated renderpass compat structure");
buffering_mechanism::get_current_resources().pso_to_delete.emplace_back(pipeline);
pipelineInfo.renderPassPSO[renderPassId] = new VkPSO(dev, physDeviceProps.limits, pipelineInfo.createInfo, renderPass.rp, renderPass.rp_compat_info, renderPass.msaaSamples, vkDynLoader, *this);
}
}
return true;
}

#endif // defined(WZ_VULKAN_ENABLED)
2 changes: 2 additions & 0 deletions lib/ivis_opengl/gfx_api_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,8 @@ struct VkRoot final : gfx_api::context
virtual bool supportsInstancedRendering() override;
virtual void draw_instanced(const std::size_t& offset, const std::size_t &count, const gfx_api::primitive_type &primitive, std::size_t instance_count) override;
virtual void draw_elements_instanced(const std::size_t& offset, const std::size_t& count, const gfx_api::primitive_type& primitive, const gfx_api::index_type& index, std::size_t instance_count) override;
// debug apis for recompiling pipelines
virtual bool debugRecompileAllPipelines() override;
private:
virtual bool _initialize(const gfx_api::backend_Impl_Factory& impl, int32_t antialiasing, swap_interval_mode mode, optional<float> mipLodBias, uint32_t depthMapResolution) override;
void initPixelFormatsSupport();
Expand Down
11 changes: 3 additions & 8 deletions src/wzscriptdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,16 +927,11 @@ class WzGraphicsPanel : public W_FORM
debug(LOG_INFO, "Done");
}, prevButton);

prevButton = panel->createButton(1, "Recompile terrain", [](){
debug(LOG_INFO, "Recompiling terrain");
gfx_api::TerrainLayer::get().recompile();
prevButton = panel->createButton(1, "Recompile All Shaders", [](){
debug(LOG_INFO, "Recompiling all shader pipelines");
gfx_api::context::get().debugRecompileAllPipelines();
debug(LOG_INFO, "Done");
});
prevButton =panel->createButton(1, "Recompile decals", [](){
debug(LOG_INFO, "Recompiling decals");
gfx_api::TerrainDecals::get().recompile();
debug(LOG_INFO, "Done");
}, prevButton);
prevButton =panel->createButton(1, "Recompile terrainCombined", [](){
debug(LOG_INFO, "Recompiling terrainCombined");
switch (getTerrainShaderQuality())
Expand Down

0 comments on commit 92c20e7

Please sign in to comment.