Allow to disable PBO at configure time

* it seems to increase latency if used
This commit is contained in:
Martin Pulec
2012-06-08 18:01:22 +02:00
parent a9da2d02fb
commit e35a641da9
3 changed files with 62 additions and 7 deletions

View File

@@ -89,8 +89,10 @@ struct dxt_decoder
GLuint g_vao;
GLuint g_vao_422;
#ifdef USE_PBO
GLuint pbo_in;
GLuint pbo_out;
#endif
unsigned int legacy:1;
};
@@ -287,6 +289,7 @@ dxt_decoder_create(enum dxt_type type, int width, int height, enum dxt_format ou
#endif
#ifdef USE_PBO
glGenBuffersARB(1, &decoder->pbo_in); //Allocate PBO
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, decoder->pbo_in);
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB,
@@ -299,6 +302,7 @@ dxt_decoder_create(enum dxt_type type, int width, int height, enum dxt_format ou
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, decoder->pbo_out);
glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, ((width + 3) / 4 * 4) * ((height + 3) / 4 * 4) * (out_format == DXT_FORMAT_YUV422 ? 2 : 4), 0, GL_STREAM_READ_ARB);
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
#endif
}
@@ -335,6 +339,7 @@ dxt_decoder_decompress(struct dxt_decoder* decoder, unsigned char* image_compres
int data_size = ((decoder->width + 3) / 4 * 4) * ((decoder->height + 3) / 4 * 4) /
(decoder->type == DXT_TYPE_DXT5_YCOCG ? 1 : 2);
#ifdef USE_PBO
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, decoder->pbo_in); // current pbo
glCompressedTexSubImage2DARB (GL_TEXTURE_2D, 0, 0, 0,
(decoder->width + 3) / 4 * 4,
@@ -350,6 +355,14 @@ dxt_decoder_decompress(struct dxt_decoder* decoder, unsigned char* image_compres
memcpy(ptr, image_compressed, data_size);
glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
}
#else
glCompressedTexSubImage2DARB (GL_TEXTURE_2D, 0, 0, 0,
(decoder->width + 3) / 4 * 4,
(decoder->height + 3) / 4 * 4,
decoder->type == DXT_TYPE_DXT5_YCOCG ? GL_COMPRESSED_RGBA_S3TC_DXT5_EXT : GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
data_size,
image_compressed);
#endif
#ifdef RTDXT_DEBUG
@@ -393,8 +406,8 @@ dxt_decoder_decompress(struct dxt_decoder* decoder, unsigned char* image_compres
#endif
if(decoder->out_format != DXT_FORMAT_YUV422) { /* so RGBA */
// Disable framebuffer
//glReadPixels(0, 0, decoder->width, decoder->height, GL_RGBA, DXT_IMAGE_GL_TYPE, image);
#ifdef USE_PBO
// glReadPixels() should return immediately.
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, decoder->pbo_out);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
@@ -412,6 +425,9 @@ dxt_decoder_decompress(struct dxt_decoder* decoder, unsigned char* image_compres
// back to conventional pixel operation
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
#else
glReadPixels(0, 0, decoder->width, decoder->height, GL_RGBA, DXT_IMAGE_GL_TYPE, image);
#endif
glBindFramebuffer(GL_FRAMEBUFFER, 0);
} else {
@@ -443,6 +459,7 @@ dxt_decoder_decompress(struct dxt_decoder* decoder, unsigned char* image_compres
glPopAttrib();
#ifdef USE_PBO
// glReadPixels() should return immediately.
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, decoder->pbo_out);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
@@ -460,6 +477,9 @@ dxt_decoder_decompress(struct dxt_decoder* decoder, unsigned char* image_compres
// back to conventional pixel operation
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
#else
glReadPixels(0, 0, decoder->width / 2, decoder->height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, image);
#endif
//glReadPixels(0, 0, decoder->width / 2, decoder->height, GL_RGBA, DXT_IMAGE_GL_TYPE, image);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

View File

@@ -87,9 +87,11 @@ struct dxt_encoder
// Texture id
GLuint texture_id;
#ifdef USE_PBO
// PBO
GLuint pbo_in;
GLuint pbo_out;
#endif
// Compressed texture
GLuint texture_compressed_id;
@@ -242,6 +244,7 @@ dxt_encoder_create(enum dxt_type type, int width, int height, enum dxt_format fo
glGenFramebuffers(1, &encoder->fbo_id);
glBindFramebuffer(GL_FRAMEBUFFER, encoder->fbo_id);
#ifdef USE_PBO
int bpp;
if(format == DXT_FORMAT_RGB) {
bpp = 3;
@@ -254,6 +257,12 @@ dxt_encoder_create(enum dxt_type type, int width, int height, enum dxt_format fo
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB,width*height*bpp,0,GL_STREAM_DRAW_ARB);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
glGenBuffersARB(1, &encoder->pbo_out); //Allocate PBO
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, encoder->pbo_out);
glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, ((width + 3) / 4 * 4) * ((height + 3) / 4 * 4) / (encoder->type == DXT_TYPE_DXT5_YCOCG ? 1 : 2), 0, GL_STREAM_READ_ARB);
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
#endif
GLuint fbo_tex;
glGenTextures(1, &fbo_tex);
@@ -269,11 +278,6 @@ dxt_encoder_create(enum dxt_type type, int width, int height, enum dxt_format fo
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fbo_tex, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glGenBuffersARB(1, &encoder->pbo_out); //Allocate PBO
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, encoder->pbo_out);
glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, ((width + 3) / 4 * 4) * ((height + 3) / 4 * 4) / (encoder->type == DXT_TYPE_DXT5_YCOCG ? 1 : 2), 0, GL_STREAM_READ_ARB);
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
// Create program [display] and its shader
encoder->program_compress = glCreateProgram();
// Create fragment shader from file
@@ -460,7 +464,9 @@ dxt_encoder_compress(struct dxt_encoder* encoder, DXT_IMAGE_TYPE* image, unsigne
GPA_BeginPass();
GPA_BeginSample(0);
#endif
#ifdef USE_PBO
GLubyte *ptr;
#endif
int data_size = encoder->width * encoder->height;
switch(encoder->format) {
@@ -485,6 +491,7 @@ dxt_encoder_compress(struct dxt_encoder* encoder, DXT_IMAGE_TYPE* image, unsigne
glPushAttrib(GL_VIEWPORT_BIT);
glViewport( 0, 0, encoder->width, encoder->height);
#ifdef USE_PBO
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, encoder->pbo_in); // current pbo
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width / 2, encoder->height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, data_size, 0, GL_STREAM_DRAW_ARB);
@@ -495,6 +502,9 @@ dxt_encoder_compress(struct dxt_encoder* encoder, DXT_IMAGE_TYPE* image, unsigne
memcpy(ptr, image, data_size);
glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
}
#else
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width / 2, encoder->height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, image);
#endif
glUseProgram(encoder->yuv422_to_444_program);
#ifdef RTDXT_DEBUG
glEndQuery(GL_TIME_ELAPSED_EXT);
@@ -537,6 +547,7 @@ dxt_encoder_compress(struct dxt_encoder* encoder, DXT_IMAGE_TYPE* image, unsigne
case DXT_FORMAT_YUV:
case DXT_FORMAT_RGBA:
glBindTexture(GL_TEXTURE_2D, encoder->texture_id);
#ifdef USE_PBO
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, encoder->pbo_in); // current pbo
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGBA, DXT_IMAGE_GL_TYPE, 0);
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, data_size, 0, GL_STREAM_DRAW_ARB);
@@ -547,10 +558,14 @@ dxt_encoder_compress(struct dxt_encoder* encoder, DXT_IMAGE_TYPE* image, unsigne
memcpy(ptr, image, data_size);
glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
}
#else
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGBA, DXT_IMAGE_GL_TYPE, image);
#endif
break;
case DXT_FORMAT_RGB:
glBindTexture(GL_TEXTURE_2D, encoder->texture_id);
#ifdef USE_PBO
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, encoder->pbo_in); // current pbo
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGB, GL_UNSIGNED_BYTE, 0);
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, data_size, 0, GL_STREAM_DRAW_ARB);
@@ -561,6 +576,9 @@ dxt_encoder_compress(struct dxt_encoder* encoder, DXT_IMAGE_TYPE* image, unsigne
memcpy(ptr, image, data_size);
glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
}
#else
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGB, GL_UNSIGNED_BYTE, image);
#endif
break;
}
#ifdef RTDXT_DEBUG
@@ -612,11 +630,13 @@ dxt_encoder_compress(struct dxt_encoder* encoder, DXT_IMAGE_TYPE* image, unsigne
#endif
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
#ifdef USE_PBO
// Read back
// read pixels from framebuffer to PBO
// glReadPixels() should return immediately.
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, encoder->pbo_out);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
if ( encoder->type == DXT_TYPE_DXT5_YCOCG )
glReadPixels(0, 0, (encoder->width + 3) / 4, (encoder->height + 3) / 4, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_INT, 0);
else
@@ -634,6 +654,10 @@ dxt_encoder_compress(struct dxt_encoder* encoder, DXT_IMAGE_TYPE* image, unsigne
// back to conventional pixel operation
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
#else
glReadPixels(0, 0, (encoder->width + 3) / 4, (encoder->height + 3) / 4, GL_RGBA_INTEGER_EXT,
encoder->type == DXT_TYPE_DXT5_YCOCG ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, image_compressed);
#endif
#ifdef RTDXT_DEBUG_HOST

View File

@@ -1064,6 +1064,11 @@ AC_ARG_ENABLE(rtdxt,
[rtdxt_req=$enableval],
[rtdxt_req=yes])
AC_ARG_ENABLE(rtdxt-pbo,
AS_HELP_STRING([--disable-rtdxt-pbo], [disable use of PBO in RTDXT (default is on)]),
[rtdxt_pbo_req=$enableval],
[rtdxt_pbo_req=yes])
SAVED_LIBS=$LIBS
AC_CHECK_HEADER(GL/glew.h, FOUND_GLEW_H=yes)
@@ -1075,6 +1080,11 @@ AC_CHECK_LIB(X11, XCreateWindow)
LIBS=$SAVED_LIBS
if test $rtdxt_pbo_req = yes
then
AC_DEFINE([USE_PBO], [1], [We want to use PBO])
fi
# Linux
if test $rtdxt_req = yes -a "$ac_cv_lib_X11_XCreateWindow" = yes -a "$FOUND_GLEW_L" = yes -a "$FOUND_GLEW_H" = yes -a "$FOUND_GLX_L" = yes -a "$FOUND_GLX_H" = yes \
-a "$FOUND_GL_H" = yes -a "$system" = Linux
@@ -1105,6 +1115,7 @@ then
AC_SUBST(RTDXT_DECOMPRESS_LIB_TARGET, "lib/ultragrid/vdecompress_rtdxt.so.$video_decompress_abi_version")
fi
AC_SUBST(GL_COMMON_OBJ)
AC_SUBST(RTDXT_COMMON_OBJ)
AC_SUBST(RTDXT_COMMON_HEADERS)