mirror of
https://github.com/RPCS3/rpcs3.git
synced 2026-05-07 13:37:46 +00:00
gl: Strengthen RAII guarantees for some more objects
This commit is contained in:
parent
b3ac8127ea
commit
59f54caf08
5 changed files with 33 additions and 15 deletions
|
|
@ -220,7 +220,7 @@ namespace gl
|
|||
return (found->second >= 0);
|
||||
}
|
||||
|
||||
auto result = glGetUniformLocation(m_program.id(), name.c_str());
|
||||
auto result = glGetUniformLocation(m_program->id(), name.c_str());
|
||||
locations[name] = result;
|
||||
|
||||
if (location)
|
||||
|
|
@ -247,7 +247,7 @@ namespace gl
|
|||
}
|
||||
}
|
||||
|
||||
auto result = glGetUniformLocation(m_program.id(), name.c_str());
|
||||
auto result = glGetUniformLocation(m_program->id(), name.c_str());
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace gl
|
|||
|
||||
const std::string& get_source() const { return source; }
|
||||
|
||||
fence get_compile_fence_sync() const { return m_compiled_fence; }
|
||||
const fence& get_compile_fence_sync() const { return m_compiled_fence; }
|
||||
|
||||
bool created() const { return m_id != GL_NONE; }
|
||||
|
||||
|
|
@ -106,29 +106,34 @@ namespace gl
|
|||
|
||||
class uniforms_t
|
||||
{
|
||||
program& m_program;
|
||||
program* m_program = nullptr;
|
||||
std::unordered_map<std::string, GLint> locations;
|
||||
|
||||
public:
|
||||
uniforms_t(program* program)
|
||||
: m_program(*program)
|
||||
: m_program(program)
|
||||
{}
|
||||
|
||||
uniforms_t(uniforms_t&&) noexcept = default;
|
||||
uniforms_t& operator = (uniforms_t&&) noexcept = default;
|
||||
|
||||
void clear() { locations.clear(); }
|
||||
|
||||
bool has_location(const std::string& name, int* location = nullptr);
|
||||
|
||||
GLint location(const std::string& name);
|
||||
|
||||
uniform_t operator[](GLint location) { return{ m_program, location }; }
|
||||
uniform_t operator[](GLint location) { return{ *m_program, location }; }
|
||||
|
||||
uniform_t operator[](const std::string& name) { return{ m_program, location(name) }; }
|
||||
uniform_t operator[](const std::string& name) { return{ *m_program, location(name) }; }
|
||||
|
||||
} uniforms{ this };
|
||||
|
||||
public:
|
||||
program() = default;
|
||||
|
||||
program(const program&) = delete;
|
||||
program& operator = (const program&) = delete;
|
||||
|
||||
~program()
|
||||
{
|
||||
|
|
@ -138,6 +143,13 @@ namespace gl
|
|||
}
|
||||
}
|
||||
|
||||
void swap(program&& other) noexcept
|
||||
{
|
||||
std::swap(m_id, other.m_id);
|
||||
std::swap(m_fence, other.m_fence);
|
||||
std::swap(uniforms, other.uniforms);
|
||||
}
|
||||
|
||||
program& recreate()
|
||||
{
|
||||
remove();
|
||||
|
|
|
|||
|
|
@ -283,10 +283,10 @@ namespace gl
|
|||
const auto range = utils::address_range32::start_length(start, length);
|
||||
m_barriers.erase(std::remove_if(m_barriers.begin(), m_barriers.end(), [&range](auto& barrier_)
|
||||
{
|
||||
if (barrier_.range.overlaps(range))
|
||||
if (barrier_->range.overlaps(range))
|
||||
{
|
||||
barrier_.signal.server_wait_sync();
|
||||
barrier_.signal.destroy();
|
||||
barrier_->signal.server_wait_sync();
|
||||
barrier_->signal.destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -301,9 +301,9 @@ namespace gl
|
|||
return;
|
||||
}
|
||||
|
||||
barrier barrier_;
|
||||
barrier_.range = utils::address_range32::start_length(start, length);
|
||||
barrier_.signal.create();
|
||||
m_barriers.emplace_back(barrier_);
|
||||
auto barrier_ = std::make_unique<barrier>();
|
||||
barrier_->range = utils::address_range32::start_length(start, length);
|
||||
barrier_->signal.create();
|
||||
m_barriers.emplace_back(std::move(barrier_));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ namespace gl
|
|||
};
|
||||
|
||||
buffer m_storage;
|
||||
std::vector<barrier> m_barriers;
|
||||
std::vector<std::unique_ptr<barrier>> m_barriers;
|
||||
u64 m_alloc_pointer = 0;
|
||||
|
||||
void pop_barrier(u32 start, u32 length);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@ namespace gl
|
|||
fence() = default;
|
||||
~fence() = default;
|
||||
|
||||
fence(const fence&) = delete;
|
||||
fence& operator = (const fence&) = delete;
|
||||
|
||||
fence(fence&&) noexcept = default;
|
||||
fence& operator = (fence&&) noexcept = default;
|
||||
|
||||
void create()
|
||||
{
|
||||
m_value = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue