Skip to content

Conversation

@softcookiepp
Copy link

As the title says, the creation of vk::ShaderModule objects has been moved from kp::Algorithm kp::Module, a new class.
This will make it easier to implement caching of vk::ShaderModule objects, as well as add aditional features for shader module metadata handling in the future.

Copy link
Member

@axsaucedo axsaucedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done an initial review, seems like still a way to go, there's a few inconsistencies that need to be addressed, as well as caveats on existing approach and coding style. There also doesn't seem to be a fully complete implementation as this suggests an optionally owned resource but currently the PR does not introduce the functionaly to make it optionally owned. We also need to ensure new functionality is tested, especially in contexts where these resources are owned, and particularly assessing the memory management / lifecycle aspect.

@@ -0,0 +1,27 @@
#pragma once
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is quite random, what is this here for - remove

/*
* getter for mShaderModule
*/
vk::ShaderModule& getShaderModule() { return mShaderModule; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be const and should not return a mutable reference

public:

/*
* Constructor accepting a device and a SPIR-V binary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment conventions should align to rest of codebase - see manager.hpp

// the vulkan device; not owned by this object
std::weak_ptr<vk::Device> mDevice;

// the shader module handle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous comment, see other classes for examples

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • needs clarity on ownerhsip as this is sometimes owned resource

* Wrapper for Vulkan's shader modules.
* The purpose of this is to manage the module lifetime, while
* building the groundwork for easily integrating things like
* SPIR-V reflection and multiple entry points in the future.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrite as description of class as of now not for future / groundwork

* building the groundwork for easily integrating things like
* SPIR-V reflection and multiple entry points in the future.
*/
class Module : public std::enable_shared_from_this<Module>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming convention here is not consistent, should be Shader as per file - module is a generic keyword

bool mFreeDescriptorSet = false;
std::shared_ptr<vk::ShaderModule> mShaderModule;
bool mFreeShaderModule = false;
std::shared_ptr<Module> mModule = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is suggested as optionally owned resource but it's not handled as such, follow the same convention as per the rest of the optionally owned resources

src/Shader.cpp Outdated
spv.size());
vk::ShaderModuleCreateInfo shaderModuleInfo(vk::ShaderModuleCreateFlags(),
sizeof(uint32_t) * spv.size(), spv.data());
this->mDevice.lock()->createShaderModule(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we don't use device.lock throughout the codebase, let's ensure consitency

class Module : public std::enable_shared_from_this<Module>
{
// the vulkan device; not owned by this object
std::weak_ptr<vk::Device> mDevice;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device is not a weakptr as we need to ensure that this resource doesnt outlive the lifecylce by storing as strong reference and/or ensuring this is handled correctly

src/Shader.cpp Outdated
{
KP_LOG_DEBUG("Kompute Module destructor started");
KP_LOG_DEBUG("Kompute Module Destroying shader module");
if (!mDevice.expired() )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure consistency with other classes, including coding style

@softcookiepp
Copy link
Author

Alright, that should cover everything.

@softcookiepp softcookiepp requested a review from axsaucedo January 8, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants