Jump to content

Coding Conundrum


Josh
 Share

Recommended Posts

Graphics pipelines in Vulkan are tied to both a shader and context. I want to store a map of these in the context, using the shader as the map key. I can use a weak_ptr to the shader for the key so it does not create a circular reference. This is what the third parameter in the map definition below does:

class Context
{
public:
	std::map<weak_ptr<Shader>, shared_ptr<Pipeline>, std::owner_less<std::weak_ptr<Shader> > pipelines;

	void Draw(shared_ptr<Shader> shader)
	{
		auto iter = pipelines.find(shader);
		if (iter == pipelines.end()) pipelines[shader] = CreatePipeline(shader);
		auto pipeline = iter->second;

		//Begin drawing...

	}
};

When the shader goes out of scope and is deleted the associated pipelines in each context will still be stored in the map. Is there any way I can set this up so that the shader being deleted automatically clears all the map values associated with that key, in each context? The only solution I can think of is to loop through a list of all contexts and remove the values in the shader destructor.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...