Merge branch 'arb_half_float_vertex'

This commit is contained in:
Dave Airlie 2010-01-23 12:29:33 +10:00
commit 782b6885c2
14 changed files with 2524 additions and 2228 deletions

View file

@ -160,6 +160,7 @@ SOURCES = \
vbo-drawelements.c \
vbo-drawrange.c \
vp-array.c \
vp-array-hf.c \
vp-array-int.c \
vp-clip.c \
vp-line-clip.c \

215
progs/trivial/vp-array-hf.c Normal file
View file

@ -0,0 +1,215 @@
/* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glew.h>
#include <GL/glut.h>
typedef union { GLfloat f; GLint i; } fi_type;
/**
* Convert a 4-byte float to a 2-byte half float.
* Based on code from:
* http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/008786.html
*/
static GLhalf
_mesa_float_to_half(GLfloat val)
{
const fi_type fi = {val};
const int flt_m = fi.i & 0x7fffff;
const int flt_e = (fi.i >> 23) & 0xff;
const int flt_s = (fi.i >> 31) & 0x1;
int s, e, m = 0;
GLhalf result;
/* sign bit */
s = flt_s;
/* handle special cases */
if ((flt_e == 0) && (flt_m == 0)) {
/* zero */
/* m = 0; - already set */
e = 0;
}
else if ((flt_e == 0) && (flt_m != 0)) {
/* denorm -- denorm float maps to 0 half */
/* m = 0; - already set */
e = 0;
}
else if ((flt_e == 0xff) && (flt_m == 0)) {
/* infinity */
/* m = 0; - already set */
e = 31;
}
else if ((flt_e == 0xff) && (flt_m != 0)) {
/* NaN */
m = 1;
e = 31;
}
else {
/* regular number */
const int new_exp = flt_e - 127;
if (new_exp < -24) {
/* this maps to 0 */
/* m = 0; - already set */
e = 0;
}
else if (new_exp < -14) {
/* this maps to a denorm */
unsigned int exp_val = (unsigned int) (-14 - new_exp); /* 2^-exp_val*/
e = 0;
switch (exp_val) {
case 0:
/* m = 0; - already set */
break;
case 1: m = 512 + (flt_m >> 14); break;
case 2: m = 256 + (flt_m >> 15); break;
case 3: m = 128 + (flt_m >> 16); break;
case 4: m = 64 + (flt_m >> 17); break;
case 5: m = 32 + (flt_m >> 18); break;
case 6: m = 16 + (flt_m >> 19); break;
case 7: m = 8 + (flt_m >> 20); break;
case 8: m = 4 + (flt_m >> 21); break;
case 9: m = 2 + (flt_m >> 22); break;
case 10: m = 1; break;
}
}
else if (new_exp > 15) {
/* map this value to infinity */
/* m = 0; - already set */
e = 31;
}
else {
/* regular */
e = new_exp + 15;
m = flt_m >> 13;
}
}
result = (s << 15) | (e << 10) | m;
return result;
}
GLfloat verts[][4] = {
{ 0.9, -0.9, 0.0, 1.0 },
{ 0.9, 0.9, 0.0, 1.0 },
{ -0.9, 0.9, 0.0, 1.0 },
{ -0.9, -0.9, 0.0, 1.0 },
};
GLhalf hverts[16];
GLubyte color[][4] = {
{ 0x00, 0x00, 0xff, 0x00 },
{ 0x00, 0xff, 0x00, 0x00 },
{ 0xff, 0x00, 0x00, 0x00 },
{ 0xff, 0xff, 0xff, 0x00 },
};
GLuint indices[] = { 0, 1, 2, 3 };
static void Init( void )
{
GLint errno;
GLuint prognum;
GLuint i, j;
static const char *prog1 =
"!!ARBvp1.0\n"
"MOV result.color, vertex.color;\n"
"MOV result.position, vertex.position;\n"
"END\n";
if (!glutExtensionSupported("GL_ARB_half_float_vertex")) {
printf("GL_ARB_half_float_vertex not found!\n");
exit(0);
}
glGenProgramsARB(1, &prognum);
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(prog1), (const GLubyte *) prog1);
assert(glIsProgramARB(prognum));
errno = glGetError();
printf("glGetError = %d\n", errno);
if (errno != GL_NO_ERROR)
{
GLint errorpos;
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
printf("errorpos: %d\n", errorpos);
printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
}
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
hverts[i * 4 + j] = _mesa_float_to_half(verts[i][j]);
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glVertexPointer( 4, GL_HALF_FLOAT, 8, hverts );
glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );
}
static void Display( void )
{
glClearColor(0.3, 0.3, 0.3, 1);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable(GL_VERTEX_PROGRAM_NV);
glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices );
glFlush();
}
static void Reshape( int width, int height )
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
/*glTranslatef( 0.0, 0.0, -15.0 );*/
}
static void Key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
int main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 250, 250 );
glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
glutCreateWindow(argv[0]);
glewInit();
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutDisplayFunc( Display );
Init();
glutMainLoop();
return 0;
}

View file

@ -73,6 +73,7 @@ __glCallLists_size(GLenum e)
case GL_SHORT:
case GL_UNSIGNED_SHORT:
case GL_2_BYTES:
case GL_HALF_FLOAT:
return 2;
case GL_3_BYTES:
return 3;

View file

@ -59,6 +59,14 @@ static GLuint float_types[5] = {
BRW_SURFACEFORMAT_R32G32B32A32_FLOAT
};
static GLuint half_float_types[5] = {
0,
BRW_SURFACEFORMAT_R16_FLOAT,
BRW_SURFACEFORMAT_R16G16_FLOAT,
0, /* can't seem to render this one */
BRW_SURFACEFORMAT_R16G16B16A16_FLOAT
};
static GLuint uint_types_norm[5] = {
0,
BRW_SURFACEFORMAT_R32_UNORM,
@ -172,6 +180,7 @@ static GLuint get_surface_type( GLenum type, GLuint size,
switch (type) {
case GL_DOUBLE: return double_types[size];
case GL_FLOAT: return float_types[size];
case GL_HALF_FLOAT: return half_float_types[size];
case GL_INT: return int_types_norm[size];
case GL_SHORT: return short_types_norm[size];
case GL_BYTE: return byte_types_norm[size];
@ -194,6 +203,7 @@ static GLuint get_surface_type( GLenum type, GLuint size,
switch (type) {
case GL_DOUBLE: return double_types[size];
case GL_FLOAT: return float_types[size];
case GL_HALF_FLOAT: return half_float_types[size];
case GL_INT: return int_types_scale[size];
case GL_SHORT: return short_types_scale[size];
case GL_BYTE: return byte_types_scale[size];
@ -211,6 +221,7 @@ static GLuint get_size( GLenum type )
switch (type) {
case GL_DOUBLE: return sizeof(GLdouble);
case GL_FLOAT: return sizeof(GLfloat);
case GL_HALF_FLOAT: return sizeof(GLhalfARB);
case GL_INT: return sizeof(GLint);
case GL_SHORT: return sizeof(GLshort);
case GL_BYTE: return sizeof(GLbyte);

View file

@ -154,6 +154,7 @@ static const struct dri_extension brw_extensions[] = {
{ "GL_ARB_fragment_program_shadow", NULL },
{ "GL_ARB_fragment_shader", NULL },
{ "GL_ARB_framebuffer_object", GL_ARB_framebuffer_object_functions},
{ "GL_ARB_half_float_vertex", NULL },
{ "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions },
{ "GL_ARB_point_sprite", NULL },
{ "GL_ARB_seamless_cube_map", NULL },

View file

@ -97,6 +97,7 @@ static const struct dri_extension card_extensions[] = {
/* *INDENT-OFF* */
{"GL_ARB_depth_texture", NULL},
{"GL_ARB_fragment_program", NULL},
{"GL_ARB_half_float_vertex", NULL},
{"GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions},
{"GL_ARB_multitexture", NULL},
{"GL_ARB_point_parameters", GL_ARB_point_parameters_functions},

View file

@ -56,6 +56,8 @@ static int getTypeSize(GLenum type)
switch (type) {
case GL_DOUBLE:
return sizeof(GLdouble);
case GL_HALF_FLOAT:
return sizeof(GLhalfARB);
case GL_FLOAT:
return sizeof(GLfloat);
case GL_INT:
@ -385,6 +387,18 @@ static void r300TranslateAttrib(GLcontext *ctx, GLuint attr, int count, const st
r300_attr._signed = 0;
r300_attr.normalize = 0;
break;
case GL_HALF_FLOAT:
switch (input->Size) {
case 1:
case 2:
r300_attr.data_type = R300_DATA_TYPE_FLT16_2;
break;
case 3:
case 4:
r300_attr.data_type = R300_DATA_TYPE_FLT16_4;
break;
}
break;
case GL_SHORT:
r300_attr._signed = 1;
r300_attr.normalize = input->Normalized;

View file

@ -230,6 +230,9 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
# define R300_DATA_TYPE_SHORT_4 7
# define R300_DATA_TYPE_VECTOR_3_TTT 8
# define R300_DATA_TYPE_VECTOR_3_EET 9
# define R300_DATA_TYPE_FLT16_2 11
# define R300_DATA_TYPE_FLT16_4 12
# define R300_SKIP_DWORDS_SHIFT 4
# define R300_DST_VEC_LOC_SHIFT 8
# define R300_LAST_VEC (1 << 13)

View file

@ -866,6 +866,9 @@
<enum name="4_BYTES" count="4" value="0x1409">
<size name="CallLists"/>
</enum>
<enum name="HALF_FLOAT" count="2" value="0x140B">
<size name="CallLists"/>
</enum>
<enum name="CLEAR" value="0x1500"/>
<enum name="AND" value="0x1501"/>
<enum name="AND_REVERSE" value="0x1502"/>

File diff suppressed because it is too large Load diff

View file

@ -56,6 +56,7 @@ static const struct {
{ OFF, "GL_ARB_fragment_shader", F(ARB_fragment_shader) },
{ OFF, "GL_ARB_framebuffer_object", F(ARB_framebuffer_object) },
{ OFF, "GL_ARB_half_float_pixel", F(ARB_half_float_pixel) },
{ OFF, "GL_ARB_half_float_vertex", F(ARB_half_float_vertex) },
{ OFF, "GL_ARB_imaging", F(ARB_imaging) },
{ OFF, "GL_ARB_map_buffer_range", F(ARB_map_buffer_range) },
{ ON, "GL_ARB_multisample", F(ARB_multisample) },
@ -220,6 +221,7 @@ _mesa_enable_sw_extensions(GLcontext *ctx)
ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
#endif
ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
ctx->Extensions.ARB_imaging = GL_TRUE;
ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
ctx->Extensions.ARB_multitexture = GL_TRUE;

View file

@ -2403,6 +2403,7 @@ struct gl_extensions
GLboolean ARB_fragment_shader;
GLboolean ARB_framebuffer_object;
GLboolean ARB_half_float_pixel;
GLboolean ARB_half_float_vertex;
GLboolean ARB_imaging;
GLboolean ARB_map_buffer_range;
GLboolean ARB_multisample;

View file

@ -121,6 +121,9 @@ _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
case GL_DOUBLE:
elementSize = size * sizeof(GLdouble);
break;
case GL_HALF_FLOAT:
elementSize = size * sizeof(GLhalfARB);
break;
#if FEATURE_fixedpt
case GL_FIXED:
elementSize = size * sizeof(GLfixed);
@ -174,6 +177,9 @@ _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
case GL_DOUBLE:
elementSize = 3 * sizeof(GLdouble);
break;
case GL_HALF_FLOAT:
elementSize = 3 * sizeof(GLhalfARB);
break;
#if FEATURE_fixedpt
case GL_FIXED:
elementSize = 3 * sizeof(GLfixed);
@ -250,6 +256,9 @@ _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
case GL_DOUBLE:
elementSize = size * sizeof(GLdouble);
break;
case GL_HALF_FLOAT:
elementSize = size * sizeof(GLhalfARB);
break;
#if FEATURE_fixedpt
case GL_FIXED:
elementSize = size * sizeof(GLfixed);
@ -285,6 +294,9 @@ _mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
case GL_DOUBLE:
elementSize = sizeof(GLdouble);
break;
case GL_HALF_FLOAT:
elementSize = sizeof(GLhalfARB);
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glFogCoordPointer(type)" );
return;
@ -394,6 +406,9 @@ _mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
case GL_DOUBLE:
elementSize = size * sizeof(GLdouble);
break;
case GL_HALF_FLOAT:
elementSize = size * sizeof(GLhalfARB);
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glSecondaryColorPointer(type=%s)",
_mesa_lookup_enum_by_nr(type));
@ -441,6 +456,9 @@ _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
case GL_DOUBLE:
elementSize = size * sizeof(GLdouble);
break;
case GL_HALF_FLOAT:
elementSize = size * sizeof(GLhalfARB);
break;
#if FEATURE_fixedpt
case GL_FIXED:
elementSize = size * sizeof(GLfixed);
@ -670,6 +688,9 @@ _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
case GL_DOUBLE:
elementSize = size * sizeof(GLdouble);
break;
case GL_HALF_FLOAT:
elementSize = size * sizeof(GLhalfARB);
break;
#if FEATURE_fixedpt
case GL_FIXED:
elementSize = size * sizeof(GLfixed);

View file

@ -108,6 +108,22 @@ convert_bgra_to_float(const struct gl_client_array *input,
}
}
static void
convert_half_to_float(const struct gl_client_array *input,
const GLubyte *ptr, GLfloat *fptr,
GLuint count, GLuint sz)
{
GLuint i, j;
for (i = 0; i < count; i++) {
GLhalfARB *in = (GLhalfARB *)ptr;
for (j = 0; j < sz; j++) {
*fptr++ = _mesa_half_to_float(in[j]);
}
ptr += input->StrideB;
}
}
/* Adjust pointer to point at first requested element, convert to
* floating point, populate VB->AttribPtr[].
@ -155,6 +171,9 @@ static void _tnl_import_array( GLcontext *ctx,
case GL_DOUBLE:
CONVERT(GLdouble, (GLfloat));
break;
case GL_HALF_FLOAT:
convert_half_to_float(input, ptr, fptr, count, sz);
break;
default:
assert(0);
break;