Move GetSSBOSize to gl_buffer.
PiperOrigin-RevId: 264452709
This commit is contained in:
parent
130a306ff7
commit
4362caba07
tensorflow/lite/delegates/gpu
@ -35,6 +35,17 @@ Status CopyBuffer(const GlBuffer& read_buffer, const GlBuffer& write_buffer) {
|
||||
write_buffer.offset(), read_buffer.bytes_size());
|
||||
}
|
||||
|
||||
Status GetSSBOSize(GLuint id, int64_t* size_bytes) {
|
||||
GLuint prev_id;
|
||||
RETURN_IF_ERROR(TFLITE_GPU_CALL_GL(glGetIntegerv,
|
||||
GL_SHADER_STORAGE_BUFFER_BINDING,
|
||||
reinterpret_cast<GLint*>(&prev_id)));
|
||||
gl_buffer_internal::BufferBinder binder(GL_SHADER_STORAGE_BUFFER, id,
|
||||
prev_id);
|
||||
return TFLITE_GPU_CALL_GL(glGetBufferParameteri64v, GL_SHADER_STORAGE_BUFFER,
|
||||
GL_BUFFER_SIZE, size_bytes);
|
||||
}
|
||||
|
||||
GlBuffer::GlBuffer(GlBuffer&& buffer)
|
||||
: GlBuffer(buffer.target_, buffer.id_, buffer.bytes_size_, buffer.offset_,
|
||||
buffer.has_ownership_) {
|
||||
|
@ -114,6 +114,8 @@ class GlBuffer {
|
||||
|
||||
Status CopyBuffer(const GlBuffer& read_buffer, const GlBuffer& write_buffer);
|
||||
|
||||
Status GetSSBOSize(GLuint id, int64_t* size_bytes);
|
||||
|
||||
// Creates new shader storage buffer that will be modified and used many
|
||||
// times.
|
||||
//
|
||||
@ -204,16 +206,22 @@ class BufferId {
|
||||
// RAII for binding and unbinding a buffer.
|
||||
class BufferBinder {
|
||||
public:
|
||||
BufferBinder(GLenum target, GLuint id) : target_(target) {
|
||||
BufferBinder(GLenum target, GLuint id) : target_(target), prev_id_(0) {
|
||||
TFLITE_GPU_CALL_GL(glBindBuffer, target_, id).IgnoreError();
|
||||
}
|
||||
|
||||
BufferBinder(GLenum target, GLuint id, GLuint prev_id)
|
||||
: target_(target), prev_id_(prev_id) {
|
||||
TFLITE_GPU_CALL_GL(glBindBuffer, target_, id).IgnoreError();
|
||||
}
|
||||
|
||||
~BufferBinder() {
|
||||
TFLITE_GPU_CALL_GL(glBindBuffer, target_, 0).IgnoreError();
|
||||
TFLITE_GPU_CALL_GL(glBindBuffer, target_, prev_id_).IgnoreError();
|
||||
}
|
||||
|
||||
private:
|
||||
const GLenum target_;
|
||||
GLuint prev_id_;
|
||||
};
|
||||
|
||||
// RAII for mapping and unmapping a buffer.
|
||||
|
@ -119,12 +119,7 @@ class Delegate {
|
||||
|
||||
Status BindBufferToTensor(GLuint ssbo, int tensor_index) {
|
||||
int64_t bytes_size;
|
||||
{
|
||||
gl_buffer_internal::BufferBinder binder(GL_SHADER_STORAGE_BUFFER, ssbo);
|
||||
RETURN_IF_ERROR(TFLITE_GPU_CALL_GL(glGetBufferParameteri64v,
|
||||
GL_SHADER_STORAGE_BUFFER,
|
||||
GL_BUFFER_SIZE, &bytes_size));
|
||||
}
|
||||
RETURN_IF_ERROR(GetSSBOSize(ssbo, &bytes_size));
|
||||
return bhwc_objects_.RegisterBuffer(
|
||||
tensor_index, GlBuffer(GL_SHADER_STORAGE_BUFFER, ssbo, bytes_size,
|
||||
/* offset = */ 0,
|
||||
|
Loading…
Reference in New Issue
Block a user