summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorCorbin Simpson <[email protected]>2009-03-30 23:54:53 -0700
committerCorbin Simpson <[email protected]>2009-03-31 18:32:10 -0700
commit63529c731a090c5e41c1224ca79b544243a1e570 (patch)
treec55679c93a310f761988e0c44d0f296d29f8836b /src/gallium/drivers
parenta44f54912e4bc0f6be0b7303f8b7a1b934c5819a (diff)
r300-gallium: Stubs for vertex shaders.
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/r300/Makefile1
-rw-r--r--src/gallium/drivers/r300/r300_context.h22
-rw-r--r--src/gallium/drivers/r300/r300_state_shader.c5
-rw-r--r--src/gallium/drivers/r300/r300_state_tcl.c196
-rw-r--r--src/gallium/drivers/r300/r300_state_tcl.h72
5 files changed, 293 insertions, 3 deletions
diff --git a/src/gallium/drivers/r300/Makefile b/src/gallium/drivers/r300/Makefile
index 0e4e1155325..9330c286d2b 100644
--- a/src/gallium/drivers/r300/Makefile
+++ b/src/gallium/drivers/r300/Makefile
@@ -16,6 +16,7 @@ C_SOURCES = \
r300_state_derived.c \
r300_state_invariant.c \
r300_state_shader.c \
+ r300_state_tcl.c \
r300_surface.c \
r300_swtcl_emit.c \
r300_texture.c
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h
index ed6480bea79..0ca445c0918 100644
--- a/src/gallium/drivers/r300/r300_context.h
+++ b/src/gallium/drivers/r300/r300_context.h
@@ -231,6 +231,26 @@ struct r300_vertex_format {
int tab[16];
};
+struct r300_vertex_shader {
+ /* Parent class */
+ struct pipe_shader_state state;
+ struct tgsi_shader_info info;
+
+ /* Has this shader been translated yet? */
+ boolean translated;
+
+ /* Number of used instructions */
+ int instruction_count;
+
+ /* Machine instructions */
+ struct {
+ uint32_t inst0;
+ uint32_t inst1;
+ uint32_t inst2;
+ uint32_t inst3;
+ } instructions[128]; /*< XXX magic number */
+};
+
struct r300_context {
/* Parent class */
struct pipe_context context;
@@ -270,6 +290,8 @@ struct r300_context {
int vertex_buffer_count;
/* Vertex information. */
struct r300_vertex_format vertex_info;
+ /* Vertex shader. */
+ struct r300_vertex_shader* vs;
/* Viewport state. */
struct r300_viewport_state* viewport_state;
/* Bitmask of dirty state objects. */
diff --git a/src/gallium/drivers/r300/r300_state_shader.c b/src/gallium/drivers/r300/r300_state_shader.c
index 5dc7266f9b1..1b02239ee76 100644
--- a/src/gallium/drivers/r300/r300_state_shader.c
+++ b/src/gallium/drivers/r300/r300_state_shader.c
@@ -623,15 +623,14 @@ void r300_translate_fragment_shader(struct r300_context* r300,
}
break;
}
-
}
- debug_printf("r300: %d texs and %d colors, first free reg is %d\n",
+ debug_printf("r300: fs: %d texs and %d colors, first free reg is %d\n",
assembler->tex_count, assembler->color_count,
assembler->tex_count + assembler->color_count);
consts->count = consts->user_count + assembler->imm_count;
- debug_printf("r300: %d total constants, "
+ debug_printf("r300: fs: %d total constants, "
"%d from user and %d from immediates\n", consts->count,
consts->user_count, assembler->imm_count);
r300_fs_finalize(fs, assembler);
diff --git a/src/gallium/drivers/r300/r300_state_tcl.c b/src/gallium/drivers/r300/r300_state_tcl.c
new file mode 100644
index 00000000000..ddf43604b9a
--- /dev/null
+++ b/src/gallium/drivers/r300/r300_state_tcl.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2009 Corbin Simpson <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "r300_state_tcl.h"
+
+static void r300_vs_declare(struct r300_vs_asm* assembler,
+ struct tgsi_full_declaration* decl)
+{
+ switch (decl->Declaration.File) {
+ case TGSI_FILE_INPUT:
+ switch (decl->Semantic.SemanticName) {
+ case TGSI_SEMANTIC_COLOR:
+ assembler->color_count++;
+ break;
+ case TGSI_SEMANTIC_GENERIC:
+ assembler->tex_count++;
+ break;
+ default:
+ debug_printf("r300: vs: Bad semantic declaration %d\n",
+ decl->Semantic.SemanticName);
+ break;
+ }
+ break;
+ case TGSI_FILE_OUTPUT:
+ case TGSI_FILE_CONSTANT:
+ break;
+ case TGSI_FILE_TEMPORARY:
+ assembler->temp_count++;
+ break;
+ default:
+ debug_printf("r300: vs: Bad file %d\n", decl->Declaration.File);
+ break;
+ }
+
+ assembler->temp_offset = assembler->color_count + assembler->tex_count;
+}
+
+static INLINE unsigned r300_vs_src(struct r300_vs_asm* assembler,
+ struct tgsi_src_register* src)
+{
+ switch (src->File) {
+ case TGSI_FILE_NULL:
+ return 0;
+ case TGSI_FILE_INPUT:
+ /* XXX may be wrong */
+ return src->Index;
+ break;
+ case TGSI_FILE_TEMPORARY:
+ return src->Index + assembler->temp_offset;
+ break;
+ case TGSI_FILE_IMMEDIATE:
+ return (src->Index + assembler->imm_offset) | (1 << 8);
+ break;
+ case TGSI_FILE_CONSTANT:
+ /* XXX magic */
+ return src->Index | (1 << 8);
+ break;
+ default:
+ debug_printf("r300: vs: Unimplemented src %d\n", src->File);
+ break;
+ }
+ return 0;
+}
+
+static INLINE unsigned r300_vs_dst(struct r300_vs_asm* assembler,
+ struct tgsi_dst_register* dst)
+{
+ switch (dst->File) {
+ case TGSI_FILE_NULL:
+ /* This happens during KIL instructions. */
+ return 0;
+ break;
+ case TGSI_FILE_OUTPUT:
+ return 0;
+ break;
+ case TGSI_FILE_TEMPORARY:
+ return dst->Index + assembler->temp_offset;
+ break;
+ default:
+ debug_printf("r300: vs: Unimplemented dst %d\n", dst->File);
+ break;
+ }
+ return 0;
+}
+
+static void r300_vs_emit_inst(struct r300_vertex_shader* vs,
+ struct r300_vs_asm* assembler,
+ struct tgsi_full_src_register* src,
+ struct tgsi_full_dst_register* dst)
+{
+ int i = vs->instruction_count;
+ vs->instructions[i].inst0 = R300_PVS_DST_OPCODE(R300_VE_ADD) |
+ R300_PVS_DST_REG_TYPE(R300_PVS_DST_REG_OUT) |
+ R300_PVS_DST_OFFSET(dst->DstRegister.Index);
+}
+
+static void r300_vs_instruction(struct r300_vertex_shader* vs,
+ struct r300_vs_asm* assembler,
+ struct tgsi_full_instruction* inst)
+{
+ switch (inst->Instruction.Opcode) {
+ case TGSI_OPCODE_MOV:
+ r300_vs_emit_inst(vs, assembler, inst->FullSrcRegisters,
+ &inst->FullDstRegisters[0]);
+ break;
+ case TGSI_OPCODE_END:
+ break;
+ default:
+ debug_printf("r300: vs: Bad opcode %d\n",
+ inst->Instruction.Opcode);
+ break;
+ }
+}
+
+void r300_translate_vertex_shader(struct r300_context* r300,
+ struct r300_vertex_shader* vs)
+{
+ struct tgsi_parse_context parser;
+ int i;
+ struct r300_constant_buffer* consts =
+ &r300->shader_constants[PIPE_SHADER_VERTEX];
+
+ struct r300_vs_asm* assembler = CALLOC_STRUCT(r300_vs_asm);
+ if (assembler == NULL) {
+ return;
+ }
+ /* Setup starting offset for immediates. */
+ assembler->imm_offset = consts->user_count;
+
+ tgsi_parse_init(&parser, vs->state.tokens);
+
+ while (!tgsi_parse_end_of_tokens(&parser)) {
+ tgsi_parse_token(&parser);
+
+ /* This is seriously the lamest way to create fragment programs ever.
+ * I blame TGSI. */
+ switch (parser.FullToken.Token.Type) {
+ case TGSI_TOKEN_TYPE_DECLARATION:
+ /* Allocated registers sitting at the beginning
+ * of the program. */
+ r300_vs_declare(assembler, &parser.FullToken.FullDeclaration);
+ break;
+ case TGSI_TOKEN_TYPE_IMMEDIATE:
+ debug_printf("r300: Emitting immediate to constant buffer, "
+ "position %d\n",
+ assembler->imm_offset + assembler->imm_count);
+ /* I am not amused by the length of these. */
+ for (i = 0; i < 4; i++) {
+ consts->constants[assembler->imm_offset +
+ assembler->imm_count][i] =
+ parser.FullToken.FullImmediate.u.ImmediateFloat32[i]
+ .Float;
+ }
+ assembler->imm_count++;
+ break;
+ case TGSI_TOKEN_TYPE_INSTRUCTION:
+ r300_vs_instruction(vs, assembler,
+ &parser.FullToken.FullInstruction);
+ break;
+ }
+ }
+
+ debug_printf("r300: vs: %d texs and %d colors, first free reg is %d\n",
+ assembler->tex_count, assembler->color_count,
+ assembler->tex_count + assembler->color_count);
+
+ consts->count = consts->user_count + assembler->imm_count;
+ debug_printf("r300: vs: %d total constants, "
+ "%d from user and %d from immediates\n", consts->count,
+ consts->user_count, assembler->imm_count);
+
+ tgsi_dump(vs->state.tokens);
+ /* XXX finish r300 vertex shader dumper */
+
+ tgsi_parse_free(&parser);
+ FREE(assembler);
+}
diff --git a/src/gallium/drivers/r300/r300_state_tcl.h b/src/gallium/drivers/r300/r300_state_tcl.h
new file mode 100644
index 00000000000..54900cc191a
--- /dev/null
+++ b/src/gallium/drivers/r300/r300_state_tcl.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2009 Corbin Simpson <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#ifndef R300_STATE_TCL_H
+#define R300_STATE_TCL_H
+
+#include "tgsi/tgsi_parse.h"
+
+#include "r300_context.h"
+#include "r300_debug.h"
+#include "r300_reg.h"
+#include "r300_screen.h"
+
+/* XXX get these to r300_reg */
+#define R300_PVS_DST_OPCODE(x) ((x) << 0)
+# define R300_VE_ADD 3
+#define R300_PVS_DST_REG_TYPE(x) ((x) << 8)
+# define R300_PVS_DST_REG_TEMPORARY 0
+# define R300_PVS_DST_REG_A0 1
+# define R300_PVS_DST_REG_OUT 2
+# define R300_PVS_DST_REG_OUT_REPL_X 3
+# define R300_PVS_DST_REG_ALT_TEMPORARY 4
+# define R300_PVS_DST_REG_INPUT 5
+#define R300_PVS_DST_OFFSET(x) ((x) << 13)
+#define R300_PVS_DST_WE_SHIFT 20
+
+/* Temporary struct used to hold assembly state while putting together
+ * fragment programs. */
+struct r300_vs_asm {
+ /* Pipe context. */
+ struct r300_context* r300;
+ /* Number of colors. */
+ unsigned color_count;
+ /* Number of texcoords. */
+ unsigned tex_count;
+ /* Offset for temporary registers. Inputs and temporaries have no
+ * distinguishing markings, so inputs start at 0 and the first usable
+ * temporary register is after all inputs. */
+ unsigned temp_offset;
+ /* Number of requested temporary registers. */
+ unsigned temp_count;
+ /* Offset for immediate constants. Neither R300 nor R500 can do four
+ * inline constants per source, so instead we copy immediates into the
+ * constant buffer. */
+ unsigned imm_offset;
+ /* Number of immediate constants. */
+ unsigned imm_count;
+};
+
+void r300_translate_vertex_shader(struct r300_context* r300,
+ struct r300_vertex_shader* vs);
+
+#endif /* R300_STATE_TCL_H */