Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/ruis/render/directx/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,7 @@ context::~context()
}
this->pipelines.clear();

// release the compiled shader blobs
for (auto& blob : this->shader_blobs) {
if (blob != nullptr) {
blob->Release();
}
}
// release the compiled shader blobs (the vector elements invoke ID3DBlob::Release())
this->shader_blobs.clear();

// the screen depth
Expand Down
13 changes: 12 additions & 1 deletion src/ruis/render/directx/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ class texture_2d;
class texture_depth;
class index_buffer;

// com unique_ptr for ID3DBlob: the COM object is released (not deleted)
struct shader_blob_deleter {
void operator()(ID3DBlob* blob) const noexcept
{
if (blob != nullptr) {
blob->Release();
}
}
};
using shader_blob_ptr = std::unique_ptr<ID3DBlob, shader_blob_deleter>;

// a key identifying a unique ID3D12PipelineState (PSO). The pipeline is
// independent of the particular vertex array, since the vertex input layout
// depends only on the shader (determining the attributes), and the actual
Expand Down Expand Up @@ -230,7 +241,7 @@ class context : public ruis::render::context
std::unordered_map<pipeline_key, ID3D12PipelineState*, pipeline_key_hash> pipelines;
// the shader blobs compiled for the pipelines created this frame
// (they must stay alive while their PSOs are alive)
std::vector<std::unique_ptr<ID3DBlob>> shader_blobs;
std::vector<shader_blob_ptr> shader_blobs;

// ---- current frame state ----
bool frame_begun = false;
Expand Down
Loading