Skip to content

Commit

Permalink
Changes to work with libAgl2 to implement GL ES 2.0
Browse files Browse the repository at this point in the history
Fixed blend mode constants.
Implemented some GL ES 2.0 functions.
Fixed sampler uniform linking and assigning.
Various other changes.

Change-Id: Icbc6c85747c6bf89fefcec613eabfea6b1141f65
  • Loading branch information
David Li committed Feb 26, 2011
1 parent 8e39977 commit 01e6ff9
Show file tree
Hide file tree
Showing 16 changed files with 889 additions and 464 deletions.
4 changes: 2 additions & 2 deletions Android.mk
Expand Up @@ -3,7 +3,7 @@ USE_LLVM_EXECUTIONENGINE := false
# if using libLLVMExecutionEngine,
# need to add files to several Android.mk in external/llvm, and comment out some stuff in llvm DynamicLibrary.cpp and Intercept.cpp

DEBUG_BUILD := true
DEBUG_BUILD := false

ifneq ($(TARGET_SIMULATOR),true)

Expand Down Expand Up @@ -100,14 +100,14 @@ libMesa_SRC_FILES := \
src/glsl/s_expression.cpp \
src/glsl/strtod.c \
src/glsl/ir_to_llvm.cpp \
src/glsl/ir_to_llvm_helper.cpp \
src/mesa/main/shaderobj.c \
src/mesa/program/hash_table.c \
src/mesa/program/prog_parameter.cpp \
src/mesa/program/symbol_table.c \
src/pixelflinger2/buffer.cpp \
src/pixelflinger2/format.cpp \
src/pixelflinger2/llvm_scanline.cpp \
src/pixelflinger2/llvm_texture.cpp \
src/pixelflinger2/pixelflinger2.cpp \
src/pixelflinger2/raster.cpp \
src/pixelflinger2/scanline.cpp \
Expand Down
38 changes: 19 additions & 19 deletions include/pixelflinger2/pixelflinger2_format.h
Expand Up @@ -28,38 +28,38 @@ enum GGLPixelFormat {

GGL_PIXEL_FORMAT_RGBA_8888 = 1, // 4x8-bit ARGB
GGL_PIXEL_FORMAT_RGBX_8888 = 2, // 3x8-bit RGB stored in 32-bit chunks
// GGL_PIXEL_FORMAT_RGB_888 = 3, // 3x8-bit RGB
GGL_PIXEL_FORMAT_RGB_888 = 3, // 3x8-bit RGB
GGL_PIXEL_FORMAT_RGB_565 = 4, // 16-bit RGB
// GGL_PIXEL_FORMAT_BGRA_8888 = 5, // 4x8-bit BGRA
// GGL_PIXEL_FORMAT_RGBA_5551 = 6, // 16-bit RGBA
// GGL_PIXEL_FORMAT_RGBA_4444 = 7, // 16-bit RGBA
GGL_PIXEL_FORMAT_BGRA_8888 = 5, // 4x8-bit BGRA
GGL_PIXEL_FORMAT_RGBA_5551 = 6, // 16-bit RGBA
GGL_PIXEL_FORMAT_RGBA_4444 = 7, // 16-bit RGBA

GGL_PIXEL_FORMAT_A_8 = 8, // 8-bit A
// GGL_PIXEL_FORMAT_L_8 = 9, // 8-bit L (R=G=B = L)
// GGL_PIXEL_FORMAT_LA_88 = 0xA, // 16-bit LA
// GGL_PIXEL_FORMAT_RGB_332 = 0xB, // 8-bit RGB (non paletted)
GGL_PIXEL_FORMAT_L_8 = 9, // 8-bit L (R=G=B = L)
GGL_PIXEL_FORMAT_LA_88 = 0xA, // 16-bit LA
GGL_PIXEL_FORMAT_RGB_332 = 0xB, // 8-bit RGB (non paletted)

// reserved range. don't use.
// GGL_PIXEL_FORMAT_RESERVED_10 = 0x10,
// GGL_PIXEL_FORMAT_RESERVED_11 = 0x11,
// GGL_PIXEL_FORMAT_RESERVED_12 = 0x12,
// GGL_PIXEL_FORMAT_RESERVED_13 = 0x13,
// GGL_PIXEL_FORMAT_RESERVED_14 = 0x14,
// GGL_PIXEL_FORMAT_RESERVED_15 = 0x15,
// GGL_PIXEL_FORMAT_RESERVED_16 = 0x16,
// GGL_PIXEL_FORMAT_RESERVED_17 = 0x17,
GGL_PIXEL_FORMAT_RESERVED_10 = 0x10,
GGL_PIXEL_FORMAT_RESERVED_11 = 0x11,
GGL_PIXEL_FORMAT_RESERVED_12 = 0x12,
GGL_PIXEL_FORMAT_RESERVED_13 = 0x13,
GGL_PIXEL_FORMAT_RESERVED_14 = 0x14,
GGL_PIXEL_FORMAT_RESERVED_15 = 0x15,
GGL_PIXEL_FORMAT_RESERVED_16 = 0x16,
GGL_PIXEL_FORMAT_RESERVED_17 = 0x17,

// reserved/special formats
GGL_PIXEL_FORMAT_Z_16 = 0x18,
GGL_PIXEL_FORMAT_S_8 = 0x19,
// GGL_PIXEL_FORMAT_SZ_24 = 0x1A,
// GGL_PIXEL_FORMAT_SZ_8 = 0x1B,
GGL_PIXEL_FORMAT_SZ_24 = 0x1A,
GGL_PIXEL_FORMAT_SZ_8 = 0x1B,

GGL_PIXEL_FORMAT_Z_32 = 0x1C,

// reserved range. don't use.
// GGL_PIXEL_FORMAT_RESERVED_20 = 0x20,
// GGL_PIXEL_FORMAT_RESERVED_21 = 0x21,
GGL_PIXEL_FORMAT_RESERVED_20 = 0x20,
GGL_PIXEL_FORMAT_RESERVED_21 = 0x21,


// must be last
Expand Down
44 changes: 28 additions & 16 deletions include/pixelflinger2/pixelflinger2_interface.h
Expand Up @@ -103,6 +103,7 @@ typedef struct GGLActiveStencil { // do not change layout, used in GenerateScanL
} GGLActiveStencil_t;

typedef struct GGLBufferState { // all affect scanline jit
enum GGLPixelFormat colorFormat, depthFormat, stencilFormat;
unsigned stencilTest :
1;
unsigned depthTest :
Expand Down Expand Up @@ -220,7 +221,7 @@ struct GGLInterface {

// creates empty shader
gl_shader_t * (* ShaderCreate)(const GGLInterface_t * iface, GLenum type);

void (* ShaderSource)(gl_shader_t * shader, GLsizei count, const char ** string, const int * length);

// compiles a shader given glsl; returns GL_TRUE on success; glsl only used during call
Expand Down Expand Up @@ -248,9 +249,13 @@ struct GGLInterface {
// LLVM JIT and set as active program
void (* ShaderUse)(GGLInterface_t * iface, gl_shader_program_t * program);

void (* ShaderGetiv)(gl_shader_t * shader, const GLenum pname, GLint * params);
void (* ShaderGetiv)(const gl_shader_t * shader, const GLenum pname, GLint * params);

void (* ShaderGetInfoLog)(const gl_shader_t * shader, GLsizei bufsize, GLsizei* length, GLchar* infolog);

void (* ShaderProgramGetiv)(gl_shader_program_t * program, const GLenum pname, GLint * params);
void (* ShaderProgramGetiv)(const gl_shader_program_t * program, const GLenum pname, GLint * params);

void (* ShaderProgramGetInfoLog)(const gl_shader_program_t * program, GLsizei bufsize, GLsizei* length, GLchar* infolog);

// bind attribute location before linking
void (* ShaderAttributeBind)(const gl_shader_program_t * program,
Expand All @@ -267,15 +272,15 @@ struct GGLInterface {
GLint location, GLfloat * params);
void (* ShaderUniformGetiv)(gl_shader_program_t * program,
GLint location, GLint * params);

// retrieves the tmu each sampler is set to, sampler2tmu[sampler] == -1 means not used
void (* ShaderUniformGetSamplers)(const gl_shader_program_t * program,
int sampler2tmu[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]);
void (* ShaderUniformGetSamplers)(const gl_shader_program_t * program,
int sampler2tmu[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]);

// updates linked program uniform value by location; return >= 0 indicates sampler assigned
GLint (* ShaderUniform)(gl_shader_program_t * program,
GLint location, GLsizei count, const GLvoid *values, GLenum type);

// updates linked program uniform matrix value by location
void (* ShaderUniformMatrix)(gl_shader_program_t * program, GLint cols,
GLint rows, GLint location, GLsizei count,
Expand Down Expand Up @@ -317,9 +322,13 @@ extern "C"
// LLVM JIT and set as active program, also call after gglState change to re-JIT
void GGLShaderUse(void * llvmCtx, const GGLState_t * gglState, gl_shader_program_t * program);

void GGLShaderGetiv(gl_shader_t * shader, const GLenum pname, GLint * params);
void GGLShaderGetiv(const gl_shader_t * shader, const GLenum pname, GLint * params);

void GGLShaderProgramGetiv(gl_shader_program_t * program, const GLenum pname, GLint * params);
void GGLShaderGetInfoLog(const gl_shader_t * shader, GLsizei bufsize, GLsizei* length, GLchar* infolog);

void GGLShaderProgramGetiv(const gl_shader_program_t * program, const GLenum pname, GLint * params);

void GGLShaderProgramGetInfoLog(const gl_shader_program_t * program, GLsizei bufsize, GLsizei* length, GLchar* infolog);

// bind attribute location before linking
void GGLShaderAttributeBind(const gl_shader_program_t * program,
Expand All @@ -332,20 +341,23 @@ extern "C"
// gets uniform location for linked program
GLint GGLShaderUniformLocation(const gl_shader_program_t * program,
const char * name);


void GGLShaderUniformMatrix(gl_shader_program_t * program, GLint cols, GLint rows,
GLint location, GLsizei count, GLboolean transpose, const GLfloat *values);

// retrieves the tmu each sampler is set to, sampler2tmu[sampler] == -1 means not used
void GGLShaderUniformGetSamplers(const gl_shader_program_t * program,
int sampler2tmu[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]);
void GGLShaderUniformGetSamplers(const gl_shader_program_t * program,
int sampler2tmu[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]);

void GGLProcessVertex(const gl_shader_program_t * program, const VertexInput_t * input,
VertexOutput_t * output, const float (*constants)[4]);

// scan line given left and right processed and scizored vertices
// depth value bitcast float->int, if negative then ^= 0x7fffffff
void GGLScanLine(const gl_shader_program_t * program, unsigned * frameBuffer,
int * depthBuffer, unsigned char * stencilBuffer, unsigned bufferWidth,
unsigned bufferHeight, GGLActiveStencil_t * activeStencil, const VertexOutput_t * start,
const VertexOutput_t * end, const float (*constants)[4]);
void GGLScanLine(const gl_shader_program_t * program, const enum GGLPixelFormat colorFormat,
void * frameBuffer, int * depthBuffer, unsigned char * stencilBuffer,
unsigned bufferWidth, unsigned bufferHeight, GGLActiveStencil_t * activeStencil,
const VertexOutput_t * start, const VertexOutput_t * end, const float (*constants)[4]);

// void GGLProcessFragment(const VertexOutput_t * inputs, VertexOutput_t * outputs,
// const float (*constants[4]));
Expand Down
2 changes: 1 addition & 1 deletion libMesa.project
Expand Up @@ -134,7 +134,6 @@
<File Name="src/glsl/opt_constant_folding.cpp"/>
<File Name="src/glsl/ast_function.cpp"/>
<File Name="src/glsl/lower_jumps.cpp"/>
<File Name="src/glsl/ir_to_llvm_helper.cpp"/>
<File Name="src/glsl/ast_expr.cpp"/>
<File Name="src/glsl/ir_print_visitor.cpp"/>
<File Name="src/glsl/opt_noop_swizzle.cpp"/>
Expand Down Expand Up @@ -188,6 +187,7 @@
<File Name="src/pixelflinger2/buffer.cpp"/>
<File Name="src/pixelflinger2/llvm_helper.h"/>
<File Name="src/pixelflinger2/scanline.cpp"/>
<File Name="src/pixelflinger2/llvm_texture.cpp"/>
</VirtualDirectory>
</VirtualDirectory>
<Description/>
Expand Down
19 changes: 10 additions & 9 deletions src/glsl/ir_to_llvm.cpp
Expand Up @@ -1255,22 +1255,23 @@ class ir_to_llvm_visitor : public ir_visitor {
if (!(ir->write_mask & mask))
return;

if(ir->rhs->type->vector_elements < width)
{
if (ir->rhs->type->vector_elements < width) {
int expand_mask[4] = {-1, -1, -1, -1};
for(unsigned i = 0; i < ir->lhs->type->vector_elements; ++i)
for (unsigned i = 0; i < ir->lhs->type->vector_elements; ++i)
expand_mask[i] = i;
// printf("ve: %u w %u issw: %i\n", ir->rhs->type->vector_elements, width, !!ir->rhs->as_swizzle());
rhs = llvm_shuffle(rhs, expand_mask, width, "assign.expand");
}

if(width > 1 && (ir->write_mask & mask) != mask)
{
if (width > 1 && (ir->write_mask & mask) != mask) {
llvm::Constant* blend_mask[4];
for(unsigned i = 0; i < width; ++i)
{
if(ir->write_mask & (1 << i))
blend_mask[i] = llvm_int(width + i);
// refer to ir.h: ir_assignment::write_mask
// A partially-set write mask means that each enabled channel gets
// the value from a consecutive channel of the rhs.
unsigned rhsChannel = 0;
for (unsigned i = 0; i < width; ++i) {
if (ir->write_mask & (1 << i))
blend_mask[i] = llvm_int(width + rhsChannel++);
else
blend_mask[i] = llvm_int(i);
}
Expand Down
16 changes: 5 additions & 11 deletions src/glsl/linker.cpp
Expand Up @@ -1124,6 +1124,7 @@ assign_uniform_locations(struct gl_shader_program *prog)

prog->Uniforms = ul;
prog->Uniforms->Slots = next_position;
prog->Uniforms->SamplerSlots = next_sampler_pos;

hieralloc_free(mem_ctx);
}
Expand Down Expand Up @@ -1741,20 +1742,13 @@ link_shaders(const struct gl_context *ctx, struct gl_shader_program *prog)
//prog->InputOuputBase = malloc(1024 * 8);
//memset(prog->InputOuputBase, 0xdd, 1024 * 8);
prog->InputOuputBase = hieralloc_realloc(prog, prog->InputOuputBase, char,
prog->Uniforms->Slots * 16 + sizeof(VertexInput) + sizeof(VertexOutput) + 16);
prog->ValuesVertexInput = (float (*)[4])((((unsigned long)prog->InputOuputBase) + 15) & (~15L));
(prog->Uniforms->Slots + prog->Uniforms->SamplerSlots) * sizeof(float) * 4 + sizeof(VertexInput) + sizeof(VertexOutput) + 16);
prog->ValuesVertexInput = (float (*)[4])((((unsigned long)prog->InputOuputBase) + 15L) & (~15L));
prog->ValuesVertexOutput = (float (*)[4])((unsigned long)prog->ValuesVertexInput + sizeof(VertexInput));
prog->ValuesUniform = (float (*)[4])((unsigned long)prog->ValuesVertexOutput + sizeof(VertexOutput));

// default mapping of tmu to sampler
for (unsigned i = 0; i < prog->Uniforms->NumUniforms; i++)
{
const gl_uniform & uniform = prog->Uniforms->Uniforms[i];
if (uniform.Type->is_sampler())
prog->ValuesUniform[uniform.Pos][0] = uniform.Pos;
else if (uniform.Type->is_array() && uniform.Type->fields.array->is_sampler())
assert(0);
}
// initialize uniforms to zero after link
memset(prog->ValuesUniform, 0, sizeof(float) * 4 * (prog->Uniforms->Slots + prog->Uniforms->SamplerSlots));

done:
free(vert_shader_list);
Expand Down
2 changes: 1 addition & 1 deletion src/mesa/main/mtypes.h
Expand Up @@ -2140,7 +2140,7 @@ struct gl_shader_program
* \c NULL.
*/
struct gl_shader *_LinkedShaders[MESA_SHADER_TYPES];
GLfloat (*ValuesUniform)[4];
GLfloat (*ValuesUniform)[4]; /** < samplers are at ValuesUniform[gl_uniform_list::Slots + sampler.Pos]*/
GLfloat (*ValuesVertexInput)[4]; /**< actually a VertexInput */
GLfloat (*ValuesVertexOutput)[4]; /**< actually a VertexOutput */
void * InputOuputBase; /**< allocation base for Values* */
Expand Down
3 changes: 2 additions & 1 deletion src/mesa/program/prog_uniform.h
Expand Up @@ -63,7 +63,8 @@ struct gl_uniform_list
{
GLuint Size; /**< allocated size of Uniforms array */
GLuint NumUniforms; /**< number of uniforms in the array */
GLuint Slots; /**< number of float[4] slots uniforms will occupy */
GLuint Slots; /**< number of float[4] slots non-sampler uniforms occupy */
GLuint SamplerSlots; /**< number of float[4] slots samplers occupy */
struct gl_uniform *Uniforms; /**< Array [Size] */
};

Expand Down

0 comments on commit 01e6ff9

Please sign in to comment.