diff options
author | Zack Rusin <[email protected]> | 2010-07-09 22:40:04 -0400 |
---|---|---|
committer | Zack Rusin <[email protected]> | 2010-07-09 22:40:04 -0400 |
commit | 9808308f9ad05c5fd6916cb808c66be23f21db60 (patch) | |
tree | 04a16000fd68c5e15ad77eb21dfea214076ff645 | |
parent | 7b8726a99da961fe0ace7c7ee567f82217715fe4 (diff) |
mesa: initial support for emitting 2D registers from slang
-rw-r--r-- | src/mesa/slang/slang_builtin.c | 66 | ||||
-rw-r--r-- | src/mesa/slang/slang_builtin.h | 3 | ||||
-rw-r--r-- | src/mesa/slang/slang_codegen.c | 25 | ||||
-rw-r--r-- | src/mesa/slang/slang_emit.c | 3 | ||||
-rw-r--r-- | src/mesa/slang/slang_ir.c | 34 | ||||
-rw-r--r-- | src/mesa/slang/slang_ir.h | 7 |
6 files changed, 98 insertions, 40 deletions
diff --git a/src/mesa/slang/slang_builtin.c b/src/mesa/slang/slang_builtin.c index e3ac7d38e2d..a7e0efcb7b5 100644 --- a/src/mesa/slang/slang_builtin.c +++ b/src/mesa/slang/slang_builtin.c @@ -756,47 +756,48 @@ struct input_info GLuint Attrib; GLenum Type; GLuint Swizzle; + GLboolean Array; }; /** Predefined vertex shader inputs/attributes */ static const struct input_info vertInputs[] = { - { "gl_Vertex", VERT_ATTRIB_POS, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_Normal", VERT_ATTRIB_NORMAL, GL_FLOAT_VEC3, SWIZZLE_NOOP }, - { "gl_Color", VERT_ATTRIB_COLOR0, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_SecondaryColor", VERT_ATTRIB_COLOR1, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_FogCoord", VERT_ATTRIB_FOG, GL_FLOAT, SWIZZLE_XXXX }, - { "gl_MultiTexCoord0", VERT_ATTRIB_TEX0, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_MultiTexCoord1", VERT_ATTRIB_TEX1, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_MultiTexCoord2", VERT_ATTRIB_TEX2, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_MultiTexCoord3", VERT_ATTRIB_TEX3, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_MultiTexCoord4", VERT_ATTRIB_TEX4, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_MultiTexCoord5", VERT_ATTRIB_TEX5, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_MultiTexCoord6", VERT_ATTRIB_TEX6, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_MultiTexCoord7", VERT_ATTRIB_TEX7, GL_FLOAT_VEC4, SWIZZLE_NOOP } + { "gl_Vertex", VERT_ATTRIB_POS, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_Normal", VERT_ATTRIB_NORMAL, GL_FLOAT_VEC3, SWIZZLE_NOOP, GL_FALSE }, + { "gl_Color", VERT_ATTRIB_COLOR0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_SecondaryColor", VERT_ATTRIB_COLOR1, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_FogCoord", VERT_ATTRIB_FOG, GL_FLOAT, SWIZZLE_XXXX, GL_FALSE }, + { "gl_MultiTexCoord0", VERT_ATTRIB_TEX0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_MultiTexCoord1", VERT_ATTRIB_TEX1, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_MultiTexCoord2", VERT_ATTRIB_TEX2, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_MultiTexCoord3", VERT_ATTRIB_TEX3, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_MultiTexCoord4", VERT_ATTRIB_TEX4, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_MultiTexCoord5", VERT_ATTRIB_TEX5, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_MultiTexCoord6", VERT_ATTRIB_TEX6, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_MultiTexCoord7", VERT_ATTRIB_TEX7, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE } }; static const struct input_info geomInputs[] = { - { "gl_PrimitiveIDIn", GEOM_ATTRIB_PRIMITIVE_ID, GL_FLOAT, SWIZZLE_NOOP }, - { "gl_FrontColorIn", GEOM_ATTRIB_COLOR0, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_BackColorIn", GEOM_ATTRIB_COLOR1, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_FrontSecondaryColorIn", GEOM_ATTRIB_SECONDARY_COLOR0, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_BackSecondaryColorIn", GEOM_ATTRIB_SECONDARY_COLOR1, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_TexCoordIn", GEOM_ATTRIB_TEX_COORD, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_FogFragCoordIn", GEOM_ATTRIB_FOG_FRAG_COORD, GL_FLOAT, SWIZZLE_NOOP }, - { "gl_PositionIn", GEOM_ATTRIB_POSITION, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_ClipVertexIn", GEOM_ATTRIB_CLIP_VERTEX, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_PointSizeIn", GEOM_ATTRIB_POINT_SIZE, GL_FLOAT, SWIZZLE_NOOP } + { "gl_PrimitiveIDIn", GEOM_ATTRIB_PRIMITIVE_ID, GL_FLOAT, SWIZZLE_NOOP, GL_FALSE }, + { "gl_FrontColorIn", GEOM_ATTRIB_COLOR0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE }, + { "gl_BackColorIn", GEOM_ATTRIB_COLOR1, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE }, + { "gl_FrontSecondaryColorIn", GEOM_ATTRIB_SECONDARY_COLOR0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE }, + { "gl_BackSecondaryColorIn", GEOM_ATTRIB_SECONDARY_COLOR1, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE }, + { "gl_TexCoordIn", GEOM_ATTRIB_TEX_COORD, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE }, + { "gl_FogFragCoordIn", GEOM_ATTRIB_FOG_FRAG_COORD, GL_FLOAT, SWIZZLE_NOOP, GL_TRUE }, + { "gl_PositionIn", GEOM_ATTRIB_POSITION, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE }, + { "gl_ClipVertexIn", GEOM_ATTRIB_CLIP_VERTEX, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE }, + { "gl_PointSizeIn", GEOM_ATTRIB_POINT_SIZE, GL_FLOAT, SWIZZLE_NOOP, GL_TRUE } }; /** Predefined fragment shader inputs */ static const struct input_info fragInputs[] = { - { "gl_FragCoord", FRAG_ATTRIB_WPOS, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_Color", FRAG_ATTRIB_COL0, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_SecondaryColor", FRAG_ATTRIB_COL1, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_TexCoord", FRAG_ATTRIB_TEX0, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - { "gl_FogFragCoord", FRAG_ATTRIB_FOGC, GL_FLOAT, SWIZZLE_XXXX }, - { "gl_FrontFacing", FRAG_ATTRIB_FACE, GL_FLOAT, SWIZZLE_XXXX }, - { "gl_PointCoord", FRAG_ATTRIB_PNTC, GL_FLOAT_VEC2, SWIZZLE_XYZW } + { "gl_FragCoord", FRAG_ATTRIB_WPOS, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_Color", FRAG_ATTRIB_COL0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_SecondaryColor", FRAG_ATTRIB_COL1, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_TexCoord", FRAG_ATTRIB_TEX0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }, + { "gl_FogFragCoord", FRAG_ATTRIB_FOGC, GL_FLOAT, SWIZZLE_XXXX, GL_FALSE }, + { "gl_FrontFacing", FRAG_ATTRIB_FACE, GL_FLOAT, SWIZZLE_XXXX, GL_FALSE }, + { "gl_PointCoord", FRAG_ATTRIB_PNTC, GL_FLOAT_VEC2, SWIZZLE_XYZW, GL_FALSE } }; @@ -807,7 +808,8 @@ static const struct input_info fragInputs[] = { * XXX return size too */ GLint -_slang_input_index(const char *name, GLenum target, GLuint *swizzleOut) +_slang_input_index(const char *name, GLenum target, GLuint *swizzleOut, + GLboolean *is_array) { const struct input_info *inputs; GLuint i, n; @@ -836,6 +838,8 @@ _slang_input_index(const char *name, GLenum target, GLuint *swizzleOut) if (strcmp(inputs[i].Name, name) == 0) { /* found */ *swizzleOut = inputs[i].Swizzle; + if (is_array) + *is_array = inputs[i].Array; return inputs[i].Attrib; } } diff --git a/src/mesa/slang/slang_builtin.h b/src/mesa/slang/slang_builtin.h index cef18afdd55..ed9ae80b3c3 100644 --- a/src/mesa/slang/slang_builtin.h +++ b/src/mesa/slang/slang_builtin.h @@ -38,7 +38,8 @@ _slang_alloc_statevar(slang_ir_node *n, extern GLint -_slang_input_index(const char *name, GLenum target, GLuint *swizzleOut); +_slang_input_index(const char *name, GLenum target, GLuint *swizzleOut, + GLboolean *is_array); extern GLint _slang_output_index(const char *name, GLenum target); diff --git a/src/mesa/slang/slang_codegen.c b/src/mesa/slang/slang_codegen.c index 79072cb3569..11a9074d1ec 100644 --- a/src/mesa/slang/slang_codegen.c +++ b/src/mesa/slang/slang_codegen.c @@ -5155,7 +5155,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, /* fragment program input */ GLuint swizzle; GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB, - &swizzle); + &swizzle, NULL); assert(index >= 0); assert(index < FRAG_ATTRIB_MAX); store = _slang_new_ir_storage_swz(PROGRAM_INPUT, index, @@ -5171,9 +5171,10 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, size, swizzle); } else { /* geometry program input */ + GLboolean is_array = GL_FALSE; GLuint swizzle; GLint index = _slang_input_index(varName, MESA_GEOMETRY_PROGRAM, - &swizzle); + &swizzle, &is_array); if (index < 0) { /* geometry program output */ index = _slang_output_index(varName, MESA_GEOMETRY_PROGRAM); @@ -5187,8 +5188,12 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, } else { assert(index >= 0); /* assert(index < GEOM_ATTRIB_MAX); */ - store = _slang_new_ir_storage_swz(PROGRAM_INPUT, index, - size, swizzle); + if (is_array) + store = _slang_new_ir_storage_2d(PROGRAM_INPUT, 0, index, + size, swizzle); + else + store = _slang_new_ir_storage_swz(PROGRAM_INPUT, index, + size, swizzle); } } if (dbg) printf("V/F "); @@ -5217,7 +5222,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, } else { /* pre-defined vertex attrib */ - index = _slang_input_index(varName, GL_VERTEX_PROGRAM_ARB, &swizzle); + index = _slang_input_index(varName, GL_VERTEX_PROGRAM_ARB, &swizzle, NULL); assert(index >= 0); } store = _slang_new_ir_storage_swz(PROGRAM_INPUT, index, size, swizzle); @@ -5227,12 +5232,16 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, GLuint swizzle = SWIZZLE_XYZW; /* silence compiler warning */ if (type == SLANG_UNIT_FRAGMENT_BUILTIN) { GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB, - &swizzle); + &swizzle, NULL); store = _slang_new_ir_storage_swz(PROGRAM_INPUT, index, size, swizzle); } else if (type == SLANG_UNIT_GEOMETRY_BUILTIN) { + GLboolean is_array; GLint index = _slang_input_index(varName, MESA_GEOMETRY_PROGRAM, - &swizzle); - store = _slang_new_ir_storage_swz(PROGRAM_INPUT, index, size, swizzle); + &swizzle, &is_array); + if (is_array) + store = _slang_new_ir_storage_2d(PROGRAM_INPUT, 0, index, size, swizzle); + else + store = _slang_new_ir_storage_swz(PROGRAM_INPUT, index, size, swizzle); } if (dbg) printf("INPUT "); } diff --git a/src/mesa/slang/slang_emit.c b/src/mesa/slang/slang_emit.c index 42d778a3084..4a02ba6d466 100644 --- a/src/mesa/slang/slang_emit.c +++ b/src/mesa/slang/slang_emit.c @@ -379,6 +379,9 @@ storage_to_src_reg(struct prog_src_register *src, const slang_ir_storage *st) assert(GET_SWZ(swizzle, 3) <= SWIZZLE_W); src->Swizzle = swizzle; + src->HasIndex2D = st->Is2D; + src->Index2D = st->Index2D; + src->RelAddr = relAddr; } diff --git a/src/mesa/slang/slang_ir.c b/src/mesa/slang/slang_ir.c index d78ba52505a..131093d2a7e 100644 --- a/src/mesa/slang/slang_ir.c +++ b/src/mesa/slang/slang_ir.c @@ -133,6 +133,8 @@ _slang_init_ir_storage(slang_ir_storage *st, st->Swizzle = swizzle; st->Parent = NULL; st->IsIndirect = GL_FALSE; + st->Is2D = GL_FALSE; + st->Index2D = 0; } @@ -151,6 +153,8 @@ _slang_new_ir_storage(gl_register_file file, GLint index, GLint size) st->Swizzle = SWIZZLE_NOOP; st->Parent = NULL; st->IsIndirect = GL_FALSE; + st->Is2D = GL_FALSE; + st->Index2D = 0; } return st; } @@ -172,10 +176,36 @@ _slang_new_ir_storage_swz(gl_register_file file, GLint index, GLint size, st->Swizzle = swizzle; st->Parent = NULL; st->IsIndirect = GL_FALSE; + st->Is2D = GL_FALSE; + st->Index2D = 0; } return st; } +/** + * Return a new slang_ir_storage object. + */ +slang_ir_storage * +_slang_new_ir_storage_2d(gl_register_file file, + GLint index, GLint index2d, + GLint size, GLuint swizzle) +{ + slang_ir_storage *st; + st = (slang_ir_storage *) _slang_alloc(sizeof(slang_ir_storage)); + if (st) { + st->File = file; + st->Index = index; + st->Size = size; + st->Swizzle = swizzle; + st->Parent = NULL; + st->IsIndirect = GL_FALSE; + st->Is2D = GL_TRUE; + st->Index2D = index2d; + } + return st; +} + + /** * Return a new slang_ir_storage object. @@ -193,6 +223,8 @@ _slang_new_ir_storage_relative(GLint index, GLint size, st->Swizzle = SWIZZLE_NOOP; st->Parent = parent; st->IsIndirect = GL_FALSE; + st->Is2D = GL_FALSE; + st->Index2D = 0; } return st; } @@ -217,6 +249,8 @@ _slang_new_ir_storage_indirect(gl_register_file file, st->IndirectFile = indirectFile; st->IndirectIndex = indirectIndex; st->IndirectSwizzle = indirectSwizzle; + st->Is2D = GL_FALSE; + st->Index2D = 0; } return st; } diff --git a/src/mesa/slang/slang_ir.h b/src/mesa/slang/slang_ir.h index e9af079a1e3..543cf0acc78 100644 --- a/src/mesa/slang/slang_ir.h +++ b/src/mesa/slang/slang_ir.h @@ -189,6 +189,9 @@ struct slang_ir_storage_ GLuint IndirectSwizzle; GLuint TexTarget; /**< If File==PROGRAM_SAMPLER, one of TEXTURE_x_INDEX */ + GLboolean Is2D; + GLint Index2D; + /** If Parent is non-null, Index is relative to parent. * The other fields are ignored. */ @@ -252,6 +255,10 @@ _slang_new_ir_storage_swz(gl_register_file file, GLint index, GLint size, GLuint swizzle); extern slang_ir_storage * +_slang_new_ir_storage_2d(gl_register_file file, GLint index, GLint index2d, + GLint size, GLuint swizzle); + +extern slang_ir_storage * _slang_new_ir_storage_relative(GLint index, GLint size, slang_ir_storage *parent); |