summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <davidxli@google.com>2011-02-07 11:36:43 -0800
committerDavid Li <davidxli@google.com>2011-02-07 11:36:43 -0800
commit0f34e4ed10959fe2a6fefcfbf8bd7b1b6716909d (patch)
tree9e083ee4e2619a9852f101e68fa7002e586c4f5f
parent470970d77c095678830fc512dfe0e97c6bcab15b (diff)
Checkpoint: factor out minimum context required for shader functionality
-rw-r--r--include/pixelflinger2/pixelflinger2_interface.h67
-rw-r--r--src/glsl/builtin_function.cpp6
-rw-r--r--src/glsl/glsl_parser_extras.cpp2
-rw-r--r--src/glsl/glsl_parser_extras.h2
-rw-r--r--src/glsl/main.cpp2
-rw-r--r--src/pixelflinger2/pixelflinger2.cpp2
-rw-r--r--src/pixelflinger2/pixelflinger2.h9
-rw-r--r--src/pixelflinger2/shader.cpp101
8 files changed, 147 insertions, 44 deletions
diff --git a/include/pixelflinger2/pixelflinger2_interface.h b/include/pixelflinger2/pixelflinger2_interface.h
index 1be41c5..0a2102c 100644
--- a/include/pixelflinger2/pixelflinger2_interface.h
+++ b/include/pixelflinger2/pixelflinger2_interface.h
@@ -25,6 +25,7 @@
typedef struct gl_shader gl_shader_t;
typedef struct gl_shader_program gl_shader_program_t;
+typedef struct gl_context gl_context_t;
typedef struct VertexInput {
Vector4 attributes[GGL_MAXVERTEXATTRIBS]; // vert input
@@ -84,6 +85,15 @@ unsigned magFilter :
1; // GL_NEAREST = 0, GL_LINEAR
} GGLTexture_t;
+typedef struct GGLTextureState {
+ // format affects vs and fs jit
+ GGLTexture_t textures[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]; // the active samplers
+ // array of pointers to texture surface data synced to textures; used by LLVM generated texture sampler
+ void * textureData[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS];
+ // array of texture dimensions synced to textures; by LLVM generated texture sampler
+ unsigned textureDimensions[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS * 2];
+} TextureState_t;
+
typedef struct GGLStencilState {
unsigned char ref, mask; // ref is masked during StencilFuncSeparate
@@ -94,12 +104,12 @@ typedef struct GGLStencilState {
// GL_ZERO = 0, GL_KEEP = 1, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP,
// GL_DECR_WRAP = 7; value = 0 | GLenum - GL_KEEP | GL_INVERT | GLenum - GL_INCR_WRAP
unsigned char sFail, dFail, dPass; // operations
-} StencilState_t;
+} GGLStencilState_t;
typedef struct GGLActiveStencilState { // do not change layout, used in GenerateScanLine
unsigned char face; // FRONT = 0, BACK = 1
unsigned char ref, mask;
-} ActiveStencilState_t;
+} GGLActiveStencilState_t;
typedef struct GGLBufferState { // all affect scanline jit
unsigned stencilTest :
@@ -110,7 +120,7 @@ unsigned depthTest :
// GL_GEQUAL, GL_ALWAYS = 7; value = GLenum & 0x7 (GLenum is 0x200-0x207)
unsigned depthFunc :
3;
-} BufferState_t;
+} GGLBufferState_t;
typedef struct GGLBlendState { // all values affect scanline jit
unsigned char color[4]; // rgba[0,255]
@@ -198,7 +208,7 @@ struct GGLInterface {
// compiles a shader given glsl; returns GL_TRUE on success; glsl only used during call; use infoLog to retrieve status
GLboolean (* ShaderCompile)(const GGLInterface_t * iface, gl_shader_t * shader,
const char * glsl, const char ** infoLog);
- // could be used after link if original shaders will not be linked in another program
+
void (* ShaderDelete)(const GGLInterface_t * iface, gl_shader_t * shader);
// creates empty program
@@ -210,7 +220,7 @@ struct GGLInterface {
// detaches a shader from program
void (* ShaderDetach)(const GGLInterface_t * iface, gl_shader_program_t * program, gl_shader_t * shader);
- // duplicates shaders to program, and links varyings / attributes; can link 1 shader
+ // duplicates shaders to program, and links varyings / attributes
GLboolean (* ShaderProgramLink)(const GGLInterface_t * iface, gl_shader_program_t * program,
const char ** infoLog);
// frees program
@@ -218,6 +228,7 @@ struct GGLInterface {
// LLVM JIT and set as active program
void (* ShaderUse)(GGLInterface_t * iface, gl_shader_program_t * program);
+
// bind attribute location before linking
void (* ShaderAttributeBind)(const GGLInterface_t * iface, const gl_shader_program_t * program,
GLuint index, const GLchar * name);
@@ -236,6 +247,7 @@ struct GGLInterface {
// updates linked program uniform value by location; return >= 0 indicates sampler assigned
GLint (* ShaderUniform)(const GGLInterface_t * iface, gl_shader_program_t * program,
GLint location, GLsizei count, const GLvoid *values, GLenum type);
+
// updates linked program uniform matrix value by location
void (* ShaderUniformMatrix)(const GGLInterface_t * iface, gl_shader_program_t * program,
GLint cols, GLint rows, GLint location, GLsizei count,
@@ -250,6 +262,51 @@ extern "C"
GGLInterface_t * CreateGGLInterface();
void DestroyGGLInterface(GGLInterface_t * interface);
+
+ // creates empty shader
+ gl_shader_t * GGLShaderCreate(GLenum type);
+
+ // compiles a shader given glsl; returns GL_TRUE on success; glsl only used during call; use infoLog to retrieve status
+ GLboolean GGLShaderCompile(const struct gl_context * glCtx, gl_shader_t * shader, const char * glsl, const char ** infoLog);
+
+ void GGLShaderDelete(gl_shader_t * shader);
+
+ // creates empty program
+ gl_shader_program_t * GGLShaderProgramCreate();
+
+ // attaches a shader to program
+ unsigned GGLShaderAttach(gl_shader_program_t * program, gl_shader_t * shader);
+
+ // detaches a shader from program
+ unsigned GGLShaderDetach(gl_shader_program_t * program, gl_shader_t * shader);
+
+ // duplicates shaders to program, and links varyings / attributes;
+ GLboolean GGLShaderProgramLink(gl_context_t * glCtx, gl_shader_program_t * program, const char ** infoLog);
+ // frees program
+ void GGLShaderProgramDelete(gl_shader_program_t * program);
+
+ // LLVM JIT and set as active program
+ void GGLShaderUse(gl_shader_program_t * program);
+ // bind attribute location before linking
+ void GGLShaderAttributeBind(const gl_shader_program_t * program,
+ GLuint index, const GLchar * name);
+ GLint GGLShaderAttributeLocation(const gl_shader_program_t * program,
+ const char * name);
+ // returns fragment input location and vertex output location for varying of linked program
+ GLint GGLShaderVaryingLocation(const gl_shader_program_t * program,
+ const char * name, GLint * vertexOutputLocation);
+ // gets uniform location for linked program
+ GLint GGLShaderUniformLocation(const gl_shader_program_t * program,
+ const char * name);
+
+ void GGLProcessVertex(const VertexInput_t * inputs,
+ VertexOutput_t * outputs, const float (*constants[4]));
+
+ // scan line given left and right processed and scizored vertices
+ void GGLScanLine(const VertexOutput_t * v1, const VertexOutput_t * v2);
+
+ void GGLProcessFragment(const VertexOutput_t * inputs, VertexOutput_t * outputs,
+ const float (*constants[4]));
#ifdef __cplusplus
}
diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp
index 8cd90d0..9a5e001 100644
--- a/src/glsl/builtin_function.cpp
+++ b/src/glsl/builtin_function.cpp
@@ -33,11 +33,11 @@ extern "C" struct gl_shader *
_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type);
gl_shader *
-read_builtins(GLenum target, const char *protos, const char **functions, unsigned count)
+read_builtins(void * mem_ctx, GLenum target, const char *protos, const char **functions, unsigned count)
{
struct gl_context fakeCtx;
fakeCtx.API = API_OPENGL;
- gl_shader *sh = _mesa_new_shader(NULL, 0, target);
+ gl_shader *sh = _mesa_new_shader((gl_context *)mem_ctx, 0, target);
struct _mesa_glsl_parse_state *st =
new(sh) _mesa_glsl_parse_state(&fakeCtx, target, sh);
@@ -13556,7 +13556,7 @@ _mesa_read_profile(struct _mesa_glsl_parse_state *state,
gl_shader *sh = builtin_profiles[profile_index];
if (sh == NULL) {
- sh = read_builtins(GL_VERTEX_SHADER, prototypes, functions, count);
+ sh = read_builtins(state, GL_VERTEX_SHADER, prototypes, functions, count);
hieralloc_steal(builtin_mem_ctx, sh);
builtin_profiles[profile_index] = sh;
}
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 174ff47..7c851ca 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -36,7 +36,7 @@ extern "C" {
#include "ir_optimization.h"
#include "loop_analysis.h"
-_mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *ctx,
+_mesa_glsl_parse_state::_mesa_glsl_parse_state(const struct gl_context *ctx,
GLenum target, void *mem_ctx)
{
switch (target) {
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index 496d23c..e65a0a3 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -43,7 +43,7 @@ enum _mesa_glsl_parser_targets {
struct gl_context;
struct _mesa_glsl_parse_state {
- _mesa_glsl_parse_state(struct gl_context *ctx, GLenum target,
+ _mesa_glsl_parse_state(const struct gl_context *ctx, GLenum target,
void *mem_ctx);
/* Callers of this hieralloc-based new need not call delete. It's
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index c624991..2267902 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -46,7 +46,7 @@ static int dump_hir = 1;
static int dump_lir = 0;
extern "C" void
-compile_shader(struct gl_context *ctx, struct gl_shader *shader)
+compile_shader(const struct gl_context *ctx, struct gl_shader *shader)
{
struct _mesa_glsl_parse_state *state =
new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader);
diff --git a/src/pixelflinger2/pixelflinger2.cpp b/src/pixelflinger2/pixelflinger2.cpp
index b33825a..fc37714 100644
--- a/src/pixelflinger2/pixelflinger2.cpp
+++ b/src/pixelflinger2/pixelflinger2.cpp
@@ -25,6 +25,8 @@
void gglError(unsigned error)
{
+ if (GL_NO_ERROR == error)
+ return;
assert(0);
}
diff --git a/src/pixelflinger2/pixelflinger2.h b/src/pixelflinger2/pixelflinger2.h
index 3e5f4da..e6f5057 100644
--- a/src/pixelflinger2/pixelflinger2.h
+++ b/src/pixelflinger2/pixelflinger2.h
@@ -77,14 +77,7 @@ struct GGLContext {
GGLBlendState blendState; // all affect scanline jit
- struct {
- // format affects vs and fs jit
- GGLTexture textures[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]; // the active samplers
- // array of pointers to texture surface data; used by LLVM generated texture sampler
- void * textureData[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS];
- // array of texture dimensions; used by LLVM generated texture sampler
- unsigned textureDimensions[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS * 2];
- } textureState;
+ GGLTextureState textureState;
// called by ShaderUse to set to proper rendering functions
void (* PickScanLine)(GGLInterface * iface);
diff --git a/src/pixelflinger2/shader.cpp b/src/pixelflinger2/shader.cpp
index 6352326..89248d7 100644
--- a/src/pixelflinger2/shader.cpp
+++ b/src/pixelflinger2/shader.cpp
@@ -67,7 +67,7 @@ bool do_mat_op_to_vec(exec_list *instructions);
extern void link_shaders(struct gl_context *ctx, struct gl_shader_program *prog);
-extern "C" void compile_shader(struct gl_context *ctx, struct gl_shader *shader);
+extern "C" void compile_shader(const struct gl_context *ctx, struct gl_shader *shader);
extern "C" void _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
struct gl_shader *sh)
@@ -105,6 +105,11 @@ extern "C" void _mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh
hieralloc_free(shader);
}
+gl_shader * GGLShaderCreate(GLenum type)
+{
+ return _mesa_new_shader(NULL, 0, type);
+}
+
static gl_shader * ShaderCreate(const GGLInterface * iface, GLenum type)
{
GGL_GET_CONST_CONTEXT(ctx, iface);
@@ -119,6 +124,17 @@ static gl_shader * ShaderCreate(const GGLInterface * iface, GLenum type)
return shader;
}
+GLboolean GGLShaderCompile(const gl_context * glCtx, gl_shader * shader,
+ const char * glsl, const char ** infoLog)
+{
+ shader->Source = glsl;
+ compile_shader(glCtx, shader);
+ shader->Source = NULL;
+ if (infoLog)
+ *infoLog = shader->InfoLog;
+ return shader->CompileStatus;
+}
+
static GLboolean ShaderCompile(const GGLInterface * iface, gl_shader * shader,
const char * glsl, const char ** infoLog)
{
@@ -127,12 +143,12 @@ static GLboolean ShaderCompile(const GGLInterface * iface, gl_shader * shader,
gglError(GL_INVALID_VALUE);
return GL_FALSE;
}
- shader->Source = glsl;
- compile_shader(ctx->glCtx, shader);
- shader->Source = NULL;
- if (infoLog)
- *infoLog = shader->InfoLog;
- return shader->CompileStatus;
+ return GGLShaderCompile(ctx->glCtx, shader, glsl, infoLog);
+}
+
+void GGLShaderDelete(gl_shader * shader)
+{
+ _mesa_delete_shader(NULL, shader);
}
static void ShaderDelete(const GGLInterface * iface, gl_shader * shader)
@@ -141,6 +157,24 @@ static void ShaderDelete(const GGLInterface * iface, gl_shader * shader)
_mesa_delete_shader(ctx->glCtx, shader);
}
+gl_shader_program * GGLShaderProgramCreate()
+{
+ gl_shader_program * program = hieralloc_zero(NULL, struct gl_shader_program);
+ if (!program)
+ return NULL;
+ program->Attributes = hieralloc_zero(program, gl_program_parameter_list);
+ if (!program->Attributes) {
+ hieralloc_free(program);
+ return NULL;
+ }
+ program->Varying = hieralloc_zero(program, gl_program_parameter_list);
+ if (!program->Varying) {
+ hieralloc_free(program);
+ return NULL;
+ }
+ return program;
+}
+
static gl_shader_program * ShaderProgramCreate(const GGLInterface * iface)
{
GGL_GET_CONST_CONTEXT(ctx, iface);
@@ -164,45 +198,58 @@ static gl_shader_program * ShaderProgramCreate(const GGLInterface * iface)
return program;
}
-static void ShaderAttach(const GGLInterface * iface, gl_shader_program * program,
- gl_shader * shader)
+unsigned GGLShaderAttach(gl_shader_program * program, gl_shader * shader)
{
for (unsigned i = 0; i < program->NumShaders; i++)
if (program->Shaders[i]->Type == shader->Type || program->Shaders[i] == shader)
- return gglError(GL_INVALID_OPERATION);
+ return GL_INVALID_OPERATION;
program->Shaders = (gl_shader **)hieralloc_realloc
(program, program->Shaders, gl_shader *, program->NumShaders + 1);
if (!program->Shaders) {
- gglError(GL_OUT_OF_MEMORY);
assert(0);
- return;
+ return GL_OUT_OF_MEMORY;
}
program->Shaders[program->NumShaders] = shader;
program->NumShaders++;
shader->RefCount++;
+ return GL_NO_ERROR;
}
-static void ShaderDetach(const GGLInterface * iface, gl_shader_program * program,
+static void ShaderAttach(const GGLInterface * iface, gl_shader_program * program,
gl_shader * shader)
{
+ unsigned error = GGLShaderAttach(program, shader);
+ if (GL_NO_ERROR != error)
+ gglError(error);
+}
+
+unsigned GGLShaderDetach(gl_shader_program * program, gl_shader * shader)
+{
for (unsigned i = 0; i < program->NumShaders; i++)
if (program->Shaders[i] == shader) {
program->NumShaders--;
program->Shaders[i] = program->Shaders[program->NumShaders];
shader->RefCount--;
if (1 == shader->RefCount && shader->DeletePending)
- iface->ShaderDelete(iface, shader);
- return;
+ GGLShaderDelete(shader);
+ return GL_NO_ERROR;
}
- gglError(GL_INVALID_OPERATION);
+ return (GL_INVALID_OPERATION);
}
-static GLboolean ShaderProgramLink(const GGLInterface * iface, gl_shader_program * program,
- const char ** infoLog)
+static void ShaderDetach(const GGLInterface * iface, gl_shader_program * program,
+ gl_shader * shader)
{
- GGL_GET_CONST_CONTEXT(ctx, iface);
- link_shaders(ctx->glCtx, program);
+ unsigned error = GGLShaderDetach(program, shader);
+ if (GL_NO_ERROR != error)
+ gglError(error);
+}
+
+GLboolean GGLShaderProgramLink(gl_context * glCtx, gl_shader_program * program,
+ const char ** infoLog)
+{
+ link_shaders(glCtx, program);
if (infoLog)
*infoLog = program->InfoLog;
if (!program->LinkStatus)
@@ -221,6 +268,12 @@ static GLboolean ShaderProgramLink(const GGLInterface * iface, gl_shader_program
}
return program->LinkStatus;
}
+static GLboolean ShaderProgramLink(const GGLInterface * iface, gl_shader_program * program,
+ const char ** infoLog)
+{
+ GGL_GET_CONST_CONTEXT(ctx, iface);
+ return GGLShaderProgramLink(ctx->glCtx, program, infoLog);
+}
static void GetShaderKey(const GGLContext * ctx, const gl_shader * shader, ShaderKey * key)
{
@@ -431,7 +484,7 @@ static void ShaderUse(GGLInterface * iface, gl_shader_program * program)
debug_printf("jit new shader '%s'(%p) \n", mainName, instance->function);
} else
// debug_printf("use cached shader %p \n", instance->function);
- ;
+ ;
shader->function = instance->function;
@@ -520,8 +573,7 @@ static GLint ShaderUniform(const GGLInterface * iface, gl_shader_program * progr
GLint location, GLsizei count, const GLvoid *values, GLenum type)
{
// TODO: sampler uniform
- if (!program)
- {
+ if (!program) {
gglError(GL_INVALID_OPERATION);
return -2;
}
@@ -574,8 +626,7 @@ static void ShaderUniformMatrix(const GGLInterface * iface, gl_shader_program *
int start = location, slots = cols * count;
if (start < 0 || start + slots > program->Uniforms->Slots)
return gglError(GL_INVALID_OPERATION);
- for (unsigned i = 0; i < slots; i++)
- {
+ for (unsigned i = 0; i < slots; i++) {
float * column = program->ValuesUniform[start + i];
for (unsigned j = 0; j < rows; j++)
column[j] = *(values++);