From a1bebf73dfdaf2cd23286aa74271b87166589901 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 10 Aug 2010 20:39:06 -0700 Subject: [PATCH] i965: Start building 965 FS backend. --- src/mesa/drivers/dri/Makefile.template | 5 ++ src/mesa/drivers/dri/i965/Makefile | 3 + src/mesa/drivers/dri/i965/brw_context.h | 10 +++ src/mesa/drivers/dri/i965/brw_fs.cpp | 82 +++++++++++++++++++++++++ src/mesa/drivers/dri/i965/brw_program.c | 3 + src/mesa/drivers/dri/i965/brw_wm.h | 6 ++ src/mesa/main/shaderobj.c | 32 ++++++---- src/mesa/main/shaderobj.h | 5 ++ 8 files changed, 135 insertions(+), 11 deletions(-) create mode 100644 src/mesa/drivers/dri/i965/brw_fs.cpp diff --git a/src/mesa/drivers/dri/Makefile.template b/src/mesa/drivers/dri/Makefile.template index 35daacfacdc..a00018cafa7 100644 --- a/src/mesa/drivers/dri/Makefile.template +++ b/src/mesa/drivers/dri/Makefile.template @@ -17,6 +17,7 @@ COMMON_SOURCES = $(COMMON_GALLIUM_SOURCES) \ INCLUDES = $(SHARED_INCLUDES) $(EXPAT_INCLUDES) OBJECTS = $(C_SOURCES:.c=.o) \ + $(CXX_SOURCES:.cpp=.o) \ $(ASM_SOURCES:.S=.o) @@ -33,12 +34,16 @@ SHARED_INCLUDES = \ $(LIBDRM_CFLAGS) CFLAGS += $(API_DEFINES) +CXXFLAGS += $(API_DEFINES) ##### RULES ##### .c.o: $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ +.cpp.o: + $(CC) -c $(INCLUDES) $(CXXFLAGS) $(DRIVER_DEFINES) $< -o $@ + .S.o: $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ diff --git a/src/mesa/drivers/dri/i965/Makefile b/src/mesa/drivers/dri/i965/Makefile index e381a5c714b..bc4cfab5c02 100644 --- a/src/mesa/drivers/dri/i965/Makefile +++ b/src/mesa/drivers/dri/i965/Makefile @@ -104,6 +104,9 @@ C_SOURCES = \ $(COMMON_SOURCES) \ $(DRIVER_SOURCES) +CXX_SOURCES = \ + brw_fs.cpp + ASM_SOURCES = DRIVER_DEFINES = -I../intel diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h index 68fc8debc6e..3728a7a122f 100644 --- a/src/mesa/drivers/dri/i965/brw_context.h +++ b/src/mesa/drivers/dri/i965/brw_context.h @@ -179,6 +179,16 @@ struct brw_fragment_program { GLbitfield tex_units_used; }; +struct brw_shader { + struct gl_shader base; + + /** Shader IR transformed for native compile, at link time. */ + struct exec_list *ir; +}; + +struct brw_shader_program { + struct gl_shader_program base; +}; /* Data about a particular attempt to compile a program. Note that * there can be many of these, each in a different GL state diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp new file mode 100644 index 00000000000..9509d932367 --- /dev/null +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -0,0 +1,82 @@ +/* + * Copyright © 2010 Intel Corporation + * + * 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 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + * + * Authors: + * Eric Anholt + * + */ + +extern "C" { +#include "main/macros.h" +#include "main/shaderobj.h" +#include "program/prog_parameter.h" +#include "program/prog_print.h" +#include "program/prog_optimize.h" +#include "brw_context.h" +#include "brw_eu.h" +#include "brw_wm.h" +#include "talloc.h" +} + +struct gl_shader * +brw_new_shader(GLcontext *ctx, GLuint name, GLuint type) +{ + struct brw_shader *shader; + + shader = talloc_zero(NULL, struct brw_shader); + shader->base.Type = type; + shader->base.Name = name; + if (shader) { + _mesa_init_shader(ctx, &shader->base); + } + + return &shader->base; +} + +struct gl_shader_program * +brw_new_shader_program(GLcontext *ctx, GLuint name) +{ + struct brw_shader_program *prog; + prog = talloc_zero(NULL, struct brw_shader_program); + if (prog) { + _mesa_init_shader_program(ctx, &prog->base); + } + return &prog->base; +} + +GLboolean +brw_compile_shader(GLcontext *ctx, struct gl_shader *shader) +{ + if (!_mesa_ir_compile_shader(ctx, shader)) + return GL_FALSE; + + return GL_TRUE; +} + +GLboolean +brw_link_shader(GLcontext *ctx, struct gl_shader_program *prog) +{ + if (!_mesa_ir_link_shader(ctx, prog)) + return GL_FALSE; + + return GL_TRUE; +} diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c index 7e7cd8e6961..b6cf6c000eb 100644 --- a/src/mesa/drivers/dri/i965/brw_program.c +++ b/src/mesa/drivers/dri/i965/brw_program.c @@ -231,5 +231,8 @@ void brwInitFragProgFuncs( struct dd_function_table *functions ) functions->DeleteProgram = brwDeleteProgram; functions->IsProgramNative = brwIsProgramNative; functions->ProgramStringNotify = brwProgramStringNotify; + + functions->CompileShader = brw_compile_shader; + functions->LinkShader = brw_link_shader; } diff --git a/src/mesa/drivers/dri/i965/brw_wm.h b/src/mesa/drivers/dri/i965/brw_wm.h index 34f2d0c3d08..25a72f5dda9 100644 --- a/src/mesa/drivers/dri/i965/brw_wm.h +++ b/src/mesa/drivers/dri/i965/brw_wm.h @@ -459,4 +459,10 @@ void emit_xpd(struct brw_compile *p, const struct brw_reg *arg0, const struct brw_reg *arg1); +GLboolean brw_compile_shader(GLcontext *ctx, + struct gl_shader *shader); +GLboolean brw_link_shader(GLcontext *ctx, struct gl_shader_program *prog); +struct gl_shader *brw_new_shader(GLcontext *ctx, GLuint name, GLuint type); +struct gl_shader_program *brw_new_shader_program(GLcontext *ctx, GLuint name); + #endif diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c index 1755e8a33c7..bcf7d313f94 100644 --- a/src/mesa/main/shaderobj.c +++ b/src/mesa/main/shaderobj.c @@ -87,6 +87,11 @@ _mesa_reference_shader(GLcontext *ctx, struct gl_shader **ptr, } } +void +_mesa_init_shader(GLcontext *ctx, struct gl_shader *shader) +{ + shader->RefCount = 1; +} /** * Allocate a new gl_shader object, initialize it. @@ -99,10 +104,10 @@ _mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type) assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER || type == GL_GEOMETRY_SHADER_ARB); shader = talloc_zero(NULL, struct gl_shader); + shader->Type = type; + shader->Name = name; if (shader) { - shader->Type = type; - shader->Name = name; - shader->RefCount = 1; + _mesa_init_shader(ctx, shader); } return shader; } @@ -224,6 +229,18 @@ _mesa_reference_shader_program(GLcontext *ctx, } } +void +_mesa_init_shader_program(GLcontext *ctx, struct gl_shader_program *prog) +{ + prog->Type = GL_SHADER_PROGRAM_MESA; + prog->RefCount = 1; + prog->Attributes = _mesa_new_parameter_list(); +#if FEATURE_ARB_geometry_shader4 + prog->Geom.VerticesOut = 0; + prog->Geom.InputType = GL_TRIANGLES; + prog->Geom.OutputType = GL_TRIANGLE_STRIP; +#endif +} /** * Allocate a new gl_shader_program object, initialize it. @@ -235,15 +252,8 @@ _mesa_new_shader_program(GLcontext *ctx, GLuint name) struct gl_shader_program *shProg; shProg = talloc_zero(NULL, struct gl_shader_program); if (shProg) { - shProg->Type = GL_SHADER_PROGRAM_MESA; shProg->Name = name; - shProg->RefCount = 1; - shProg->Attributes = _mesa_new_parameter_list(); -#if FEATURE_ARB_geometry_shader4 - shProg->Geom.VerticesOut = 0; - shProg->Geom.InputType = GL_TRIANGLES; - shProg->Geom.OutputType = GL_TRIANGLE_STRIP; -#endif + _mesa_init_shader_program(ctx, shProg); } return shProg; } diff --git a/src/mesa/main/shaderobj.h b/src/mesa/main/shaderobj.h index 1b96316b67b..48000463752 100644 --- a/src/mesa/main/shaderobj.h +++ b/src/mesa/main/shaderobj.h @@ -61,10 +61,15 @@ extern void _mesa_reference_shader_program(GLcontext *ctx, struct gl_shader_program **ptr, struct gl_shader_program *shProg); +extern void +_mesa_init_shader(GLcontext *ctx, struct gl_shader *shader); extern struct gl_shader * _mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type); +extern void +_mesa_init_shader_program(GLcontext *ctx, struct gl_shader_program *prog); + extern struct gl_shader_program * _mesa_lookup_shader_program(GLcontext *ctx, GLuint name); -- 2.30.2