mesa: Branch 'glsl-compiler-1' - 2 commits
Brian Paul
brianp at kemper.freedesktop.org
Wed Feb 28 18:58:51 UTC 2007
docs/shading.html | 53 +++++++++++++++++++++++++++++++++++++++++++++++--
src/mesa/main/matrix.c | 12 +++++------
src/mesa/main/mtypes.h | 18 ++++++++--------
3 files changed, 66 insertions(+), 17 deletions(-)
New commits:
diff-tree 07e62084bbfbce20b03b23664445c3ce6dcbd965 (from 0e1bd2302537a9684158cb353b876af4ce6346e7)
Author: Brian <brian at yutani.localnet.net>
Date: Tue Feb 27 16:45:40 2007 -0700
info about how the compiler works
diff --git a/docs/shading.html b/docs/shading.html
index 412c893..48ae15f 100644
--- a/docs/shading.html
+++ b/docs/shading.html
@@ -23,9 +23,10 @@ Contents
</p>
<ul>
<li><a href="#unsup">Unsupported Features</a>
-<li><a href="#impl">Implementation Notes</a>
+<li><a href="#notes">Implementation Notes</a>
<li><a href="#hints">Programming Hints</a>
<li><a href="#standalone">Stand-alone Compiler</a>
+<li><a href="#implementation">Compiler Implementation</a>
</ul>
@@ -50,7 +51,7 @@ All other major features of the shading
</p>
-<a name="impl">
+<a name="notes">
<h2>Implementation Notes</h2>
<ul>
@@ -188,5 +189,53 @@ Over time, the correctness of the GPU pr
and NV languagues, should improve.
</p>
+
+
+<a name="implementation">
+<h2>Compiler Implementation</h2>
+
+<p>
+The source code for Mesa's shading language compiler is in the
+<code>src/mesa/shader/slang/</code> directory.
+</p>
+
+<p>
+The compiler follows a fairly standard design and basically works as follows:
+</p>
+<ul>
+<li>The input string is tokenized (see grammar.c) and parsed
+(see slang_compiler_*.c) to produce an Abstract Syntax Tree (AST).
+The nodes in this tree are slang_operation structures
+(see slang_compile_operation.h).
+The nodes are decorated with symbol table, scoping and datatype information.
+<li>The AST is converted into an Intermediate representation (IR) tree
+(see the slang_codegen.c file).
+The IR nodes represent basic GPU instructions, like add, dot product,
+move, etc.
+The IR tree is mostly a binary tree, but a few nodes have three or four
+children.
+In principle, the IR tree could be executed by doing an in-order traversal.
+<li>The IR tree is traversed in-order to emit code (see slang_emit.c).
+This is also when registers are allocated to store variables and temps.
+<li>In the future, a pattern-matching code generator-generator may be
+used for code generation.
+Programs such as L-BURG (Bottom-Up Rewrite Generator) and Twig look for
+patterns in IR trees, compute weights for subtrees and use the weights
+to select the best instructions to represent the sub-tree.
+<li>The emitted GPU instructions (see prog_instruction.h) are stored in a
+gl_program object (see mtypes.h).
+<li>When a fragment shader and vertex shader are linked (see slang_link.c)
+the varying vars are matched up, uniforms are merged, and vertex
+attributes are resolved (rewriting instructions as needed).
+</ul>
+
+<p>
+The final vertex and fragment programs may be interpreted in software
+(see prog_execute.c) or translated into a specific hardware architecture
+(see drivers/dri/i915/i915_fragprog.c for example).
+</p>
+
+
+
</BODY>
</HTML>
diff-tree 0e1bd2302537a9684158cb353b876af4ce6346e7 (from 2cf8d24131edec78778d7b6ce49ead9157c2b266)
Author: Brian <brian at yutani.localnet.net>
Date: Tue Feb 27 09:54:50 2007 -0700
s/matrix_stack/gl_matrix_stack/ and s/mesa_list_state/gl_dlist_state/
diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c
index b2aa83e..0f96f94 100644
--- a/src/mesa/main/matrix.c
+++ b/src/mesa/main/matrix.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.3
+ * Version: 6.5.3
*
- * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -230,7 +230,7 @@ void GLAPIENTRY
_mesa_PushMatrix( void )
{
GET_CURRENT_CONTEXT(ctx);
- struct matrix_stack *stack = ctx->CurrentStack;
+ struct gl_matrix_stack *stack = ctx->CurrentStack;
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (MESA_VERBOSE&VERBOSE_API)
@@ -270,7 +270,7 @@ void GLAPIENTRY
_mesa_PopMatrix( void )
{
GET_CURRENT_CONTEXT(ctx);
- struct matrix_stack *stack = ctx->CurrentStack;
+ struct gl_matrix_stack *stack = ctx->CurrentStack;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
if (MESA_VERBOSE&VERBOSE_API)
@@ -766,7 +766,7 @@ void _mesa_update_modelview_project( GLc
* initialize it.
*/
static void
-init_matrix_stack( struct matrix_stack *stack,
+init_matrix_stack( struct gl_matrix_stack *stack,
GLuint maxDepth, GLuint dirtyFlag )
{
GLuint i;
@@ -792,7 +792,7 @@ init_matrix_stack( struct matrix_stack *
* frees the array.
*/
static void
-free_matrix_stack( struct matrix_stack *stack )
+free_matrix_stack( struct gl_matrix_stack *stack )
{
GLuint i;
for (i = 0; i < stack->MaxDepth; i++) {
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 0a25666..410d2d3 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2584,7 +2584,7 @@ struct gl_extensions
/**
* A stack of matrices (projection, modelview, color, texture, etc).
*/
-struct matrix_stack
+struct gl_matrix_stack
{
GLmatrix *Top; /**< points into Stack */
GLmatrix *Stack; /**< array [MaxDepth] of GLmatrix */
@@ -2815,7 +2815,7 @@ struct mesa_display_list
/**
* State used during display list compilation and execution.
*/
-struct mesa_list_state
+struct gl_dlist_state
{
struct mesa_display_list *CallStack[MAX_LIST_NESTING];
GLuint CallDepth; /**< Current recursion calling depth */
@@ -2893,19 +2893,19 @@ struct __GLcontextRec
/** \name The various 4x4 matrix stacks */
/*@{*/
- struct matrix_stack ModelviewMatrixStack;
- struct matrix_stack ProjectionMatrixStack;
- struct matrix_stack ColorMatrixStack;
- struct matrix_stack TextureMatrixStack[MAX_TEXTURE_COORD_UNITS];
- struct matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
- struct matrix_stack *CurrentStack; /**< Points to one of the above stacks */
+ struct gl_matrix_stack ModelviewMatrixStack;
+ struct gl_matrix_stack ProjectionMatrixStack;
+ struct gl_matrix_stack ColorMatrixStack;
+ struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_COORD_UNITS];
+ struct gl_matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
+ struct gl_matrix_stack *CurrentStack; /**< Points to one of the above stacks */
/*@}*/
/** Combined modelview and projection matrix */
GLmatrix _ModelProjectMatrix;
/** \name Display lists */
- struct mesa_list_state ListState;
+ struct gl_dlist_state ListState;
GLboolean ExecuteFlag; /**< Execute GL commands? */
GLboolean CompileFlag; /**< Compile GL commands into display list? */
More information about the mesa-commit
mailing list