GPU: UniformBuffer: Add possibility to bind as SSBO
This way UBOs can be modified directly in shader just like VBOs and IBOs.
This commit is contained in:
@@ -39,6 +39,7 @@ void GPU_uniformbuf_free(GPUUniformBuf *ubo);
|
||||
void GPU_uniformbuf_update(GPUUniformBuf *ubo, const void *data);
|
||||
|
||||
void GPU_uniformbuf_bind(GPUUniformBuf *ubo, int slot);
|
||||
void GPU_uniformbuf_bind_as_ssbo(GPUUniformBuf *ubo, int slot);
|
||||
void GPU_uniformbuf_unbind(GPUUniformBuf *ubo);
|
||||
void GPU_uniformbuf_unbind_all(void);
|
||||
|
||||
|
||||
@@ -218,6 +218,11 @@ void GPU_uniformbuf_bind(GPUUniformBuf *ubo, int slot)
|
||||
unwrap(ubo)->bind(slot);
|
||||
}
|
||||
|
||||
void GPU_uniformbuf_bind_as_ssbo(GPUUniformBuf *ubo, int slot)
|
||||
{
|
||||
unwrap(ubo)->bind_as_ssbo(slot);
|
||||
}
|
||||
|
||||
void GPU_uniformbuf_unbind(GPUUniformBuf *ubo)
|
||||
{
|
||||
unwrap(ubo)->unbind();
|
||||
|
||||
@@ -39,6 +39,7 @@ class UniformBuf {
|
||||
|
||||
virtual void update(const void *data) = 0;
|
||||
virtual void bind(int slot) = 0;
|
||||
virtual void bind_as_ssbo(int slot) = 0;
|
||||
virtual void unbind() = 0;
|
||||
|
||||
/** Used to defer data upload at drawing time.
|
||||
|
||||
@@ -35,6 +35,7 @@ class MTLUniformBuf : public UniformBuf {
|
||||
|
||||
void update(const void *data) override;
|
||||
void bind(int slot) override;
|
||||
void bind_as_ssbo(int slot) override;
|
||||
void unbind() override;
|
||||
|
||||
id<MTLBuffer> get_metal_buffer(int *r_offset);
|
||||
|
||||
@@ -113,6 +113,16 @@ void MTLUniformBuf::bind(int slot)
|
||||
}
|
||||
}
|
||||
|
||||
void MTLUniformBuf::bind_as_ssbo(int slot)
|
||||
{
|
||||
if (slot < 0) {
|
||||
MTL_LOG_WARNING("Failed to bind UBO %p as SSBO. uniform location %d invalid.\n", this, slot);
|
||||
return;
|
||||
}
|
||||
|
||||
BLI_assert_msg(0, "Not implemented yet");
|
||||
}
|
||||
|
||||
void MTLUniformBuf::unbind()
|
||||
{
|
||||
/* Unbind in debug mode to validate missing binds.
|
||||
|
||||
@@ -92,6 +92,19 @@ void GLUniformBuf::bind(int slot)
|
||||
#endif
|
||||
}
|
||||
|
||||
void GLUniformBuf::bind_as_ssbo(int slot)
|
||||
{
|
||||
if (ubo_id_ == 0) {
|
||||
this->init();
|
||||
}
|
||||
if (data_ != nullptr) {
|
||||
this->update(data_);
|
||||
MEM_SAFE_FREE(data_);
|
||||
}
|
||||
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, slot, ubo_id_);
|
||||
}
|
||||
|
||||
void GLUniformBuf::unbind()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
|
||||
@@ -30,6 +30,7 @@ class GLUniformBuf : public UniformBuf {
|
||||
|
||||
void update(const void *data) override;
|
||||
void bind(int slot) override;
|
||||
void bind_as_ssbo(int slot) override;
|
||||
void unbind() override;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user