summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <davidxli@google.com>2011-02-03 13:35:23 -0800
committerDavid Li <davidxli@google.com>2011-02-03 13:35:23 -0800
commited77b4a192d693bc2697c5d99e0f4c8db81ccbf5 (patch)
tree9ace9622d5f75797e2858d0225bf8d432b1c1355
parenta15cd3d6d90715bf22a292ac63e2fbf72ec48959 (diff)
Change build target to static library and a test executable.
Signed-off-by: David Li <davidxli@google.com>
-rw-r--r--Android.mk64
-rw-r--r--include/pixelflinger2/pixelflinger2_interface.h9
-rw-r--r--libMesa.project320
-rw-r--r--src/glsl/main.cpp387
-rw-r--r--src/pixelflinger2/pixelflinger2.cpp10
-rw-r--r--src/pixelflinger2/shader.cpp19
-rw-r--r--test/Android.mk55
-rw-r--r--test/Debug/android.tgabin0 -> 36355 bytes
-rw-r--r--test/Debug/fs.frag47
-rw-r--r--test/Debug/stress_fs.frag88
-rw-r--r--test/Debug/vs.vert24
-rw-r--r--test/cmain.c9
-rw-r--r--test/egl.cpp (renamed from egl.cpp)4
-rw-r--r--test/image_file.h (renamed from src/glsl/image_file.h)6
-rw-r--r--test/main.cpp397
-rw-r--r--test/mesa.project91
16 files changed, 1101 insertions, 429 deletions
diff --git a/Android.mk b/Android.mk
index 94edae6..929e42c 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,10 +1,9 @@
-USE_LLVM_EXECUTIONENGINE := false
-# using libbcc:
-# need to remove FORCE_ARM_CODEGEN and add some libs in libbcc/Android.mk
-
+# USE_LLVM_EXECUTIONENGINE not fully implemented
+USE_LLVM_EXECUTIONENGINE := false
# if using libLLVMExecutionEngine,
-# need to #define USE_LLVM_EXECUTIONENGINE 1" in mesa.h and uncomment LOCAL_STATIC_LIBRARIES
-# also need to add files to several Android.mk in llvm, and comment out some stuff in llvm DynamicLibrary.cpp and Intercept.cpp
+# 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
ifneq ($(TARGET_SIMULATOR),true)
@@ -13,7 +12,7 @@ LLVM_ROOT_PATH := external/llvm
# these are for using llvm::ExecutionEngine, also remove libbcc
#libLLVMX86CodeGen;libLLVMX86Info;libLLVMBitReader;libLLVMSelectionDAG;libLLVMAsmPrinter;libLLVMJIT;libLLVMCodeGen;libLLVMTarget;libLLVMMC;libLLVMScalarOpts;libLLVMipo;libLLVMTransformUtils;libLLVMCore;libLLVMSupport;libLLVMSystem;libLLVMAnalysis;libLLVMInstCombine;libLLVMipa;libLLVMMCParser;libLLVMExecutionEngine;
-mesa_STATIC_LIBS := \
+libMesa_STATIC_LIBS := \
libLLVMBitReader \
libLLVMSelectionDAG \
libLLVMAsmPrinter \
@@ -33,7 +32,7 @@ mesa_STATIC_LIBS := \
libLLVMMCParser \
libLLVMExecutionEngine
-mesa_SRC_FILES := \
+libMesa_SRC_FILES := \
src/glsl/glcpp/pp.c \
src/glsl/glcpp/glcpp-lex.c \
src/glsl/glcpp/glcpp-parse.c \
@@ -115,29 +114,30 @@ mesa_SRC_FILES := \
src/pixelflinger2/texture.cpp \
src/talloc/hieralloc.c
-# Executable for host
+# Static library for host
# ========================================================
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
-LOCAL_CPPFLAGS := -DDEBUG -UNDEBUG -O0 -g
-LOCAL_CFLAGS := -DDEBUG -UNDEBUG -O0 -g
+ifeq ($(DEBUG_BUILD),true)
+LOCAL_CPPFLAGS += -DDEBUG -UNDEBUG -O0 -g
+LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g
+endif
-LOCAL_MODULE := mesa
-LOCAL_SRC_FILES := $(mesa_SRC_FILES)
+LOCAL_MODULE := libMesa
+LOCAL_SRC_FILES := $(libMesa_SRC_FILES)
ifeq ($(USE_LLVM_EXECUTIONENGINE),true)
LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1
LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1
-LOCAL_STATIC_LIBRARIES := libLLVMX86CodeGen libLLVMX86Info $(mesa_STATIC_LIBS)
+LOCAL_STATIC_LIBRARIES := libLLVMX86CodeGen libLLVMX86Info $(libMesa_STATIC_LIBS)
else
LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0
LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0
LOCAL_SHARED_LIBRARIES := libbcc
endif
-LOCAL_LDLIBS := -ldl -lpthread
LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
$(LOCAL_PATH)/src/glsl \
@@ -148,41 +148,29 @@ LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../libbcc/include
include $(LLVM_ROOT_PATH)/llvm-host-build.mk
-include $(BUILD_HOST_EXECUTABLE)
+include $(BUILD_HOST_STATIC_LIBRARY)
-# Executable for target
+# Static library for target
# ========================================================
include $(CLEAR_VARS)
#LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_TAGS := optional
-#LOCAL_CPPFLAGS += -fPIC
-#LOCAL_CFLAGS += -fPIC
-
-#LOCAL_CPPFLAGS += -mfpu=neon
-#LOCAL_CFLAGS += -mfpu=neon
+ifeq ($(DEBUG_BUILD),true)
LOCAL_CPPFLAGS += -DDEBUG -UNDEBUG -O0 -g
LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g
+endif
-LOCAL_MODULE := mesa
-LOCAL_SRC_FILES := $(mesa_SRC_FILES)
-
-LOCAL_SHARED_LIBRARIES := libstlport libcutils libdl
-
-LOCAL_SRC_FILES += egl.cpp
-#libutils libhardware libsurfaceflinger_client libpixelflinger
-# libsurfaceflinger_client and libpixelflinger causes hieralloc assertion
-LOCAL_SHARED_LIBRARIES += libutils libhardware libsurfaceflinger_client
-LOCAL_CPPFLAGS += -DDRAW_TO_SCREEN=1
-#LOCAL_CFLAGS += -fvisibility=hidden
-#LOCAL_CPPFLAGS += -fvisibility=hidden
+LOCAL_MODULE := libMesa
+LOCAL_SRC_FILES := $(libMesa_SRC_FILES)
+LOCAL_SHARED_LIBRARIES := libstlport libcutils libdl libutils
ifeq ($(USE_LLVM_EXECUTIONENGINE),true)
LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1
LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1
-LOCAL_STATIC_LIBRARIES := libLLVMARMCodeGen libLLVMARMInfo libLLVMARMDisassembler libLLVMARMAsmPrinter $(mesa_STATIC_LIBS)
+LOCAL_STATIC_LIBRARIES := libLLVMARMCodeGen libLLVMARMInfo libLLVMARMDisassembler libLLVMARMAsmPrinter $(libMesa_STATIC_LIBS)
else
LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0
LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0
@@ -199,6 +187,10 @@ LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../libbcc/include
include $(LLVM_ROOT_PATH)/llvm-device-build.mk
-include $(BUILD_EXECUTABLE)
+include $(BUILD_STATIC_LIBRARY)
+
+# Build children
+# ========================================================
+include $(call all-makefiles-under,$(LOCAL_PATH))
endif # TARGET_SIMULATOR != true
diff --git a/include/pixelflinger2/pixelflinger2_interface.h b/include/pixelflinger2/pixelflinger2_interface.h
index e597d07..d40e271 100644
--- a/include/pixelflinger2/pixelflinger2_interface.h
+++ b/include/pixelflinger2/pixelflinger2_interface.h
@@ -154,14 +154,14 @@ struct GGLInterface {
gl_shader_program_t * (* ShaderProgramCreate)(const GGLInterface_t * iface);
// attaches a shader to program
- void (* ShaderAttach)(const GGLInterface * iface, gl_shader_program_t * program, gl_shader_t * shader);
+ void (* ShaderAttach)(const GGLInterface_t * iface, gl_shader_program_t * program, gl_shader_t * shader);
// detaches a shader from program
- void (* ShaderDetach)(const GGLInterface * iface, gl_shader_program_t * program, gl_shader_t * shader);
+ 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
GLboolean (* ShaderProgramLink)(const GGLInterface_t * iface, gl_shader_program_t * program,
- char ** infoLog);
+ const char ** infoLog);
// frees program
void (* ShaderProgramDelete)(const GGLInterface_t * iface, gl_shader_program_t * program);
@@ -172,6 +172,9 @@ struct GGLInterface {
GLuint index, const GLchar * name);
GLint (* ShaderAttributeLocation)(const GGLInterface_t * iface, const gl_shader_program_t * program,
const char * name);
+ // returns fragment input location and vertex output location for varying of linked program
+ GLint (* ShaderVaryingLocation)(const GGLInterface_t * iface, const gl_shader_program_t * program,
+ const char * name, GLint * vertexOutputLocation);
// gets uniform location for linked program
GLint (* ShaderUniformLocation)(const GGLInterface_t * iface, const gl_shader_program_t * program,
const char * name);
diff --git a/libMesa.project b/libMesa.project
new file mode 100644
index 0000000..b8aec92
--- /dev/null
+++ b/libMesa.project
@@ -0,0 +1,320 @@
+<?xml version="1.0" encoding="utf-8"?>
+<CodeLite_Project Name="libMesa" InternalType="Static Library">
+ <Plugins>
+ <Plugin Name="qmake">
+ <![CDATA[00020001N0005Debug0000000000000001N0007Release000000000000]]>
+ </Plugin>
+ </Plugins>
+ <VirtualDirectory Name="include">
+ <VirtualDirectory Name="pixelflinger2">
+ <File Name="include/pixelflinger2/pixelflinger2_constants.h"/>
+ <File Name="include/pixelflinger2/pixelflinger2_vector4.h"/>
+ <File Name="include/pixelflinger2/pixelflinger2_format.h"/>
+ <File Name="include/pixelflinger2/pixelflinger2_interface.h"/>
+ </VirtualDirectory>
+ <VirtualDirectory Name="GLES2">
+ <File Name="include/GLES2/gl2ext.h"/>
+ <File Name="include/GLES2/gl2.h"/>
+ <File Name="include/GLES2/gl2platform.h"/>
+ </VirtualDirectory>
+ <VirtualDirectory Name="c99">
+ <File Name="include/c99/inttypes.h"/>
+ <File Name="include/c99/stdint.h"/>
+ <File Name="include/c99/stdbool.h"/>
+ </VirtualDirectory>
+ </VirtualDirectory>
+ <VirtualDirectory Name="src">
+ <VirtualDirectory Name="mesa">
+ <VirtualDirectory Name="math">
+ <File Name="src/mesa/math/m_xform.h"/>
+ <File Name="src/mesa/math/m_clip_tmp.h"/>
+ <File Name="src/mesa/math/m_dotprod_tmp.h"/>
+ <File Name="src/mesa/math/m_copy_tmp.h"/>
+ <File Name="src/mesa/math/m_xform_tmp.h"/>
+ <File Name="src/mesa/math/m_norm_tmp.h"/>
+ <File Name="src/mesa/math/m_matrix.h"/>
+ <File Name="src/mesa/math/m_vector.h"/>
+ <File Name="src/mesa/math/m_debug_util.h"/>
+ <File Name="src/mesa/math/m_eval.h"/>
+ <File Name="src/mesa/math/m_debug.h"/>
+ <File Name="src/mesa/math/m_translate.h"/>
+ <File Name="src/mesa/math/m_trans_tmp.h"/>
+ </VirtualDirectory>
+ <VirtualDirectory Name="main">
+ <File Name="src/mesa/main/config.h"/>
+ <File Name="src/mesa/main/get.h"/>
+ <File Name="src/mesa/main/hash.h"/>
+ <File Name="src/mesa/main/imports.h"/>
+ <File Name="src/mesa/main/mfeatures.h"/>
+ <File Name="src/mesa/main/version.h"/>
+ <File Name="src/mesa/main/debug.h"/>
+ <File Name="src/mesa/main/core.h"/>
+ <File Name="src/mesa/main/dd.h"/>
+ <File Name="src/mesa/main/shaderobj.h"/>
+ <File Name="src/mesa/main/glapidispatch.h"/>
+ <File Name="src/mesa/main/macros.h"/>
+ <File Name="src/mesa/main/glheader.h"/>
+ <File Name="src/mesa/main/compiler.h"/>
+ <File Name="src/mesa/main/context.h"/>
+ <File Name="src/mesa/main/simple_list.h"/>
+ <File Name="src/mesa/main/mtypes.h"/>
+ </VirtualDirectory>
+ <VirtualDirectory Name="program">
+ <File Name="src/mesa/program/prog_parameter.cpp"/>
+ <File Name="src/mesa/program/symbol_table.h"/>
+ <File Name="src/mesa/program/prog_uniform.h"/>
+ <File Name="src/mesa/program/hash_table.c"/>
+ <File Name="src/mesa/program/prog_statevars.h"/>
+ <File Name="src/mesa/program/hash_table.h"/>
+ <File Name="src/mesa/program/symbol_table.c"/>
+ <File Name="src/mesa/program/ir_to_mesa.h"/>
+ <File Name="src/mesa/program/prog_parameter.h"/>
+ </VirtualDirectory>
+ </VirtualDirectory>
+ <VirtualDirectory Name="glsl">
+ <VirtualDirectory Name="glcpp">
+ <File Name="src/glsl/glcpp/glcpp.h"/>
+ <File Name="src/glsl/glcpp/pp.c"/>
+ <File Name="src/glsl/glcpp/glcpp-lex.c"/>
+ <File Name="src/glsl/glcpp/glcpp-parse.c"/>
+ <File Name="src/glsl/glcpp/glcpp-parse.h"/>
+ </VirtualDirectory>
+ <File Name="src/glsl/opt_swizzle_swizzle.cpp"/>
+ <File Name="src/glsl/list.h"/>
+ <File Name="src/glsl/opt_dead_code.cpp"/>
+ <File Name="src/glsl/image_file.h"/>
+ <File Name="src/glsl/opt_copy_propagation.cpp"/>
+ <File Name="src/glsl/strtod.h"/>
+ <File Name="src/glsl/loop_analysis.cpp"/>
+ <File Name="src/glsl/loop_unroll.cpp"/>
+ <File Name="src/glsl/ir_if_return.cpp"/>
+ <File Name="src/glsl/linker.cpp"/>
+ <File Name="src/glsl/ir_basic_block.h"/>
+ <File Name="src/glsl/opt_algebraic.cpp"/>
+ <File Name="src/glsl/link_functions.cpp"/>
+ <File Name="src/glsl/glsl_parser_extras.h"/>
+ <File Name="src/glsl/opt_discard_simplification.cpp"/>
+ <File Name="src/glsl/glsl_parser.h"/>
+ <File Name="src/glsl/ir_expression_flattening.cpp"/>
+ <File Name="src/glsl/builtin_variables.h"/>
+ <File Name="src/glsl/ir_print_visitor.h"/>
+ <File Name="src/glsl/ir_function_can_inline.cpp"/>
+ <File Name="src/glsl/s_expression.cpp"/>
+ <File Name="src/glsl/lower_discard.cpp"/>
+ <File Name="src/glsl/ir_to_llvm.cpp"/>
+ <File Name="src/glsl/opt_redundant_jumps.cpp"/>
+ <File Name="src/glsl/ir_div_to_mul_rcp.cpp"/>
+ <File Name="src/glsl/ir_mod_to_fract.cpp"/>
+ <File Name="src/glsl/glsl_types.h"/>
+ <File Name="src/glsl/glsl_symbol_table.cpp"/>
+ <File Name="src/glsl/ir_set_program_inouts.cpp"/>
+ <File Name="src/glsl/lower_variable_index_to_cond_assign.cpp"/>
+ <File Name="src/glsl/glsl_symbol_table.h"/>
+ <File Name="src/glsl/builtin_function.cpp"/>
+ <File Name="src/glsl/lower_noise.cpp"/>
+ <File Name="src/glsl/ir_reader.cpp"/>
+ <File Name="src/glsl/strtod.c"/>
+ <File Name="src/glsl/opt_constant_variable.cpp"/>
+ <File Name="src/glsl/ir_variable_refcount.cpp"/>
+ <File Name="src/glsl/ir_hierarchical_visitor.cpp"/>
+ <File Name="src/glsl/program.h"/>
+ <File Name="src/glsl/ast_type.cpp"/>
+ <File Name="src/glsl/hir_field_selection.cpp"/>
+ <File Name="src/glsl/glsl_parser_extras.cpp"/>
+ <File Name="src/glsl/opt_constant_propagation.cpp"/>
+ <File Name="src/glsl/ir_clone.cpp"/>
+ <File Name="src/glsl/main.cpp"/>
+ <File Name="src/glsl/ir_reader.h"/>
+ <File Name="src/glsl/ir_variable.cpp"/>
+ <File Name="src/glsl/loop_analysis.h"/>
+ <File Name="src/glsl/glsl_types.cpp"/>
+ <File Name="src/glsl/glsl_parser.cpp"/>
+ <File Name="src/glsl/lower_instructions.cpp"/>
+ <File Name="src/glsl/ir_optimization.h"/>
+ <File Name="src/glsl/ir_constant_expression.cpp"/>
+ <File Name="src/glsl/ir_import_prototypes.cpp"/>
+ <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"/>
+ <File Name="src/glsl/ir.h"/>
+ <File Name="src/glsl/ir_validate.cpp"/>
+ <File Name="src/glsl/ir_visitor.h"/>
+ <File Name="src/glsl/ir_function.cpp"/>
+ <File Name="src/glsl/opt_function_inlining.cpp"/>
+ <File Name="src/glsl/opt_dead_code_local.cpp"/>
+ <File Name="src/glsl/lower_vec_index_to_cond_assign.cpp"/>
+ <File Name="src/glsl/lower_vector.cpp"/>
+ <File Name="src/glsl/ir_expression_flattening.h"/>
+ <File Name="src/glsl/opt_dead_functions.cpp"/>
+ <File Name="src/glsl/ir_hierarchical_visitor.h"/>
+ <File Name="src/glsl/lower_vec_index_to_swizzle.cpp"/>
+ <File Name="src/glsl/ir_variable_refcount.h"/>
+ <File Name="src/glsl/ir_to_llvm.h"/>
+ <File Name="src/glsl/opt_tree_grafting.cpp"/>
+ <File Name="src/glsl/ir_rvalue_visitor.cpp"/>
+ <File Name="src/glsl/ir_rvalue_visitor.h"/>
+ <File Name="src/glsl/lower_texture_projection.cpp"/>
+ <File Name="src/glsl/ir.cpp"/>
+ <File Name="src/glsl/linker.h"/>
+ <File Name="src/glsl/ir_basic_block.cpp"/>
+ <File Name="src/glsl/builtin_types.h"/>
+ <File Name="src/glsl/opt_structure_splitting.cpp"/>
+ <File Name="src/glsl/ast_to_hir.cpp"/>
+ <File Name="src/glsl/ir_function_inlining.h"/>
+ <File Name="src/glsl/ir_hv_accept.cpp"/>
+ <File Name="src/glsl/opt_if_simplification.cpp"/>
+ <File Name="src/glsl/glsl_lexer.cpp"/>
+ <File Name="src/glsl/s_expression.h"/>
+ <File Name="src/glsl/loop_controls.cpp"/>
+ <File Name="src/glsl/lower_if_to_cond_assign.cpp"/>
+ <File Name="src/glsl/lower_mat_op_to_vec.cpp"/>
+ <File Name="src/glsl/ast.h"/>
+ </VirtualDirectory>
+ <VirtualDirectory Name="mapi">
+ <VirtualDirectory Name="mapi">
+ <File Name="src/mapi/mapi/u_thread.h"/>
+ <File Name="src/mapi/mapi/entry_x86_tls.h"/>
+ <File Name="src/mapi/mapi/stub.h"/>
+ <File Name="src/mapi/mapi/entry.h"/>
+ <File Name="src/mapi/mapi/u_current.h"/>
+ <File Name="src/mapi/mapi/u_macros.h"/>
+ <File Name="src/mapi/mapi/entry_x86-64_tls.h"/>
+ <File Name="src/mapi/mapi/u_compiler.h"/>
+ <File Name="src/mapi/mapi/u_execmem.h"/>
+ <File Name="src/mapi/mapi/mapi_tmp.h"/>
+ <File Name="src/mapi/mapi/mapi.h"/>
+ <File Name="src/mapi/mapi/table.h"/>
+ <File Name="src/mapi/mapi/entry_x86_tsd.h"/>
+ </VirtualDirectory>
+ <VirtualDirectory Name="glapi">
+ <File Name="src/mapi/glapi/glapitable.h"/>
+ <File Name="src/mapi/glapi/glapi_priv.h"/>
+ <File Name="src/mapi/glapi/glapi.h"/>
+ <File Name="src/mapi/glapi/glapitemp.h"/>
+ <File Name="src/mapi/glapi/glprocs.h"/>
+ <File Name="src/mapi/glapi/glthread.h"/>
+ </VirtualDirectory>
+ </VirtualDirectory>
+ <VirtualDirectory Name="talloc">
+ <File Name="src/talloc/hieralloc.c"/>
+ <File Name="src/talloc/hieralloc.h"/>
+ </VirtualDirectory>
+ <VirtualDirectory Name="pixelflinger2">
+ <File Name="src/pixelflinger2/texture.cpp"/>
+ <File Name="src/pixelflinger2/pixelflinger2.h"/>
+ <File Name="src/pixelflinger2/pixelflinger2.cpp"/>
+ <File Name="src/pixelflinger2/texture.h"/>
+ <File Name="src/pixelflinger2/format.cpp"/>
+ <File Name="src/pixelflinger2/raster.cpp"/>
+ <File Name="src/pixelflinger2/shader.cpp"/>
+ <File Name="src/pixelflinger2/llvm_scanline.cpp"/>
+ <File Name="src/pixelflinger2/buffer.cpp"/>
+ <File Name="src/pixelflinger2/llvm_helper.h"/>
+ <File Name="src/pixelflinger2/scanline.cpp"/>
+ </VirtualDirectory>
+ </VirtualDirectory>
+ <Description/>
+ <Dependencies/>
+ <Dependencies Name="Release"/>
+ <Dependencies Name="Debug"/>
+ <Settings Type="Static Library">
+ <Configuration Name="Debug" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Static Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
+ <Compiler Options="-g;-D__STDC_LIMIT_MACROS;-D__STDC_CONSTANT_MACROS;-m32 -march=i686;-DDEBUG;-UNDEBUG;-O0" Required="yes" PreCompiledHeader="">
+ <IncludePath Value="src/mesa/"/>
+ <IncludePath Value="include/"/>
+ <IncludePath Value="src/talloc/"/>
+ <IncludePath Value="src/mapi/"/>
+ <IncludePath Value="../../../external/llvm/include"/>
+ <IncludePath Value="../../../external/llvm/host/include"/>
+ <IncludePath Value="../libbcc/include"/>
+ <IncludePath Value="../../base/opengl/include"/>
+ </Compiler>
+ <Linker Options="-m32 -lstdc++ -ldl -lpthread" Required="yes">
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMX86CodeGen_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMX86Info_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMBitReader_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSelectionDAG_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMAsmPrinter_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMJIT_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMCodeGen_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMTarget_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMMC_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMScalarOpts_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMipo_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMTransformUtils_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMCore_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSystem_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMAnalysis_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMInstCombine_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMipa_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMExecutionEngine_intermediates"/>
+ <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMMCParser_intermediates"/>
+ <Library Value="libbcc"/>
+ </Linker>
+ <ResourceCompiler Options="" Required="no"/>
+ <General OutputFile="./Debug/$(ProjectName).a" IntermediateDirectory="./Debug/obj" Command="./$(ProjectName)" CommandArguments="--dump-hir --glsl-es stress_fs.frag" WorkingDirectory="./Debug" PauseExecWhenProcTerminates="yes"/>
+ <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="">
+ <PostConnectCommands/>
+ <StartupCommands/>
+ </Debugger>
+ <PreBuild/>
+ <PostBuild/>
+ <CustomBuild Enabled="no">
+ <RebuildCommand/>
+ <CleanCommand/>
+ <BuildCommand/>
+ <PreprocessFileCommand/>
+ <SingleFileCommand/>
+ <MakefileGenerationCommand/>
+ <ThirdPartyToolName>None</ThirdPartyToolName>
+ <WorkingDirectory/>
+ </CustomBuild>
+ <AdditionalRules>
+ <CustomPostBuild/>
+ <CustomPreBuild/>
+ </AdditionalRules>
+ </Configuration>
+ <Configuration Name="Release" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
+ <Compiler Options="" Required="yes" PreCompiledHeader="">
+ <IncludePath Value="."/>
+ </Compiler>
+ <Linker Options="-O2" Required="yes"/>
+ <ResourceCompiler Options="" Required="no"/>
+ <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/>
+ <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="">
+ <PostConnectCommands/>
+ <StartupCommands/>
+ </Debugger>
+ <PreBuild/>
+ <PostBuild/>
+ <CustomBuild Enabled="no">
+ <RebuildCommand/>
+ <CleanCommand/>
+ <BuildCommand/>
+ <PreprocessFileCommand/>
+ <SingleFileCommand/>
+ <MakefileGenerationCommand/>
+ <ThirdPartyToolName>None</ThirdPartyToolName>
+ <WorkingDirectory/>
+ </CustomBuild>
+ <AdditionalRules>
+ <CustomPostBuild/>
+ <CustomPreBuild/>
+ </AdditionalRules>
+ </Configuration>
+ <GlobalSettings>
+ <Compiler Options="">
+ <IncludePath Value="."/>
+ </Compiler>
+ <Linker Options="">
+ <LibraryPath Value="."/>
+ </Linker>
+ <ResourceCompiler Options=""/>
+ </GlobalSettings>
+ </Settings>
+</CodeLite_Project>
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index c131021..c624991 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -41,84 +41,9 @@
#include "src/pixelflinger2/pixelflinger2.h"
-GGLInterface * ggl = NULL;
-
-/* Returned string will have 'ctx' as its hieralloc owner. */
-static char *
-load_text_file(void *ctx, const char *file_name)
-{
- char *text = NULL;
- struct stat st;
- ssize_t total_read = 0;
- int fd = open(file_name, O_RDONLY);
-
- if (fd < 0) {
- return NULL;
- }
-
- if (fstat(fd, & st) == 0) {
- text = (char *) hieralloc_size(ctx, st.st_size + 1);
- if (text != NULL) {
- do {
- ssize_t bytes = read(fd, text + total_read,
- st.st_size - total_read);
- if (bytes < 0) {
- free(text);
- text = NULL;
- break;
- }
-
- if (bytes == 0) {
- break;
- }
-
- total_read += bytes;
- } while (total_read < st.st_size);
-
- text[total_read] = '\0';
- }
- }
-
- close(fd);
-
- return text;
-}
-
-int glsl_es = 0;
-int dump_ast = 0;
-int dump_hir = 0;
-int dump_lir = 0;
-int do_link = 0;
-int do_jit = 0;
-
-const struct option compiler_opts[] = {
- { "glsl-es", 0, &glsl_es, 1 },
- { "dump-ast", 0, &dump_ast, 1 },
- { "dump-hir", 0, &dump_hir, 1 },
- { "dump-lir", 0, &dump_lir, 1 },
- { "link", 0, &do_link, 1 },
- { "do-jit", 0, &do_jit, 1 },
- { NULL, 0, NULL, 0 }
-};
-
-/**
- * \brief Print proper usage and exit with failure.
- */
-void
-usage_fail(const char *name)
-{
-
- const char *header =
- "usage: %s [options] <file.vert | file.geom | file.frag>\n"
- "\n"
- "Possible options are:\n";
- printf(header, name, name);
- for (const struct option *o = compiler_opts; o->name != 0; ++o) {
- printf(" --%s\n", o->name);
- }
- exit(EXIT_FAILURE);
-}
-
+static int dump_ast = 0;
+static int dump_hir = 1;
+static int dump_lir = 0;
extern "C" void
compile_shader(struct gl_context *ctx, struct gl_shader *shader)
@@ -189,309 +114,3 @@ compile_shader(struct gl_context *ctx, struct gl_shader *shader)
return;
}
-
-#if 1 // build executable
-
-#define DRAW_TO_SCREEN 1
-#include "image_file.h"
-
-#if defined __arm__ && defined DRAW_TO_SCREEN
-extern "C" int SetupDrawingSurface(unsigned * width, unsigned * height, unsigned * bpp);
-extern "C" void * PresentDrawingSurface();
-extern "C" void DisposeDrawingSurface();
-#endif
-
-void execute(const GGLContext * ctx)
-{
- const gl_shader * shader = ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_FRAGMENT];
-#if defined __arm__ && DRAW_TO_SCREEN
- unsigned width = 0, height = 0, bpp = 0;
- int err = SetupDrawingSurface(&width, &height, &bpp);
- assert(!err);
- assert(32 == bpp);
- unsigned * frameSurface = (unsigned *)PresentDrawingSurface();
-#else
- const unsigned width = 1280, height = 800;
- unsigned * frameSurface = new unsigned [width * height];
-#endif
- //const unsigned scale = 16, portWidth = 80, portHeight = 50;
- unsigned scale = 1, portWidth = width / scale, portHeight = height / scale;
- //unsigned scale = 1, portWidth = width / 4, portHeight = height / 4;
-
- GGLSurface colorSurface = {width, height, GGL_PIXEL_FORMAT_RGBA_8888, frameSurface, width, sizeof(GGLSurface)};
- ggl->SetBuffer(ggl, GL_COLOR_BUFFER_BIT, &colorSurface);
- ggl->EnableDisable(ggl, GL_DEPTH_TEST, false);
-
- float * uniform = (float *)ctx->glCtx->CurrentProgram->ValuesUniform;
- float * attribute = (float *)ctx->glCtx->CurrentProgram->ValuesVertexInput;
- float * varying = (float *)ctx->glCtx->CurrentProgram->ValuesVertexOutput;
- float * output = ((VertexOutput*)ctx->glCtx->CurrentProgram->ValuesVertexOutput)->fragColor[0].f;
- int glFragColorLocation = 0;
- int vTexCoordLocation = -1;
- if (shader->symbols->get_variable("vTexCoord"))
- vTexCoordLocation = shader->symbols->get_variable("vTexCoord")->location;
- int vNormalLocation = -1;
- if (shader->symbols->get_variable("vNormal"))
- vNormalLocation = shader->symbols->get_variable("vNormal")->location;
- if (shader->symbols->get_variable("uRotM") && 0)
- {
- ir_variable * var = shader->symbols->get_variable("uRotM");
- float * matrix = uniform + 4 * 1 + 4 * shader->symbols->get_variable("uRotM")->location;
- memset(matrix, 0, 16 * sizeof(*matrix));
- matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1;
- matrix[28] = 0;
- matrix[29] = 0;
- matrix[30] = 0;
- matrix[31] = 0;
- }
- printf("executing... \n function=%p \n", shader->function);
-
- /*
- #ifdef __arm__
- {
- volatile unsigned wait = 1;
- printf("waiting for attach, set wait(%p) to 0 \n", &wait);
- puts("");
- while (wait);
- }
- #endif
- //*/
-
-
-
- unsigned frames = 1;
- clock_t c0 = clock();
-
- //while(true)
- for (frames = 1; frames <= 20; frames++)
- {
- for (unsigned y = 0; y < portHeight; y++) {
- VertexOutput v0, v1;
- v0.position = Vector4(0, y, 0, 0);
- v1.position = Vector4(portWidth - 1, y ,0 ,0);
- if (vTexCoordLocation > -1)
- {
- v0.varyings[vTexCoordLocation - 2] = Vector4(0, (float)y / (portHeight - 1), 0, 1);
- v1.varyings[vTexCoordLocation - 2] = Vector4(1, (float)y / (portHeight - 1), 0, 1);
- }
- ggl->ScanLine(ggl, &v0, &v1);
-
-// for (unsigned x = 0; x < portWidth; x++) {
-// if (vTexCoordLocation > -1)
-// {
-// varying[vTexCoordLocation * 4 + 0] = ((float)x) / (portWidth - 1);
-// varying[vTexCoordLocation * 4 + 1] = ((float)y) / (portHeight - 1);
-// varying[vTexCoordLocation * 4 + 2] = 0;
-// varying[vTexCoordLocation * 4 + 3] = 1;
-// }
-//// if (vNormalLocation > -1)
-//// {
-//// varying[vNormalLocation * 4 + 0] = 0;
-//// varying[vNormalLocation * 4 + 1] = 1;
-//// varying[vNormalLocation * 4 + 2] = 0;
-//// varying[vNormalLocation * 4 + 3] = 1;
-//// }
-// shader->function();
-// unsigned r = output[0] * 255;
-// unsigned g = output[1] * 255;
-// unsigned b = output[2] * 255;
-// unsigned a = output[3] * 255;
-// frameSurface[y * width + x] = (a << 24) | (b << 16) | (g << 8) | r;
-// }
- }
- //*
- if (scale > 1)
- for (int y = portHeight - 1; y >= 0; y--)
- for (int x = portWidth - 1; x >= 0; x--)
- {
- unsigned pixel = ((unsigned *)frameSurface)[y * width + x];
- for (unsigned xx = 0; xx < scale; xx++)
- for (unsigned yy = 0; yy < scale; yy++)
- ((unsigned *)frameSurface)[(y * scale + yy) * width + x * scale + xx] = pixel;
- }
- //*/
-#if defined __arm__ && DRAW_TO_SCREEN
- frameSurface = (unsigned *)PresentDrawingSurface();
- colorSurface.data = frameSurface;
- ggl->SetBuffer(ggl, GL_COLOR_BUFFER_BIT, &colorSurface);
-#endif
- }
-
- float elapsed = (float)(clock() - c0) / CLOCKS_PER_SEC;
- printf ("\n *** test_scan elapsed CPU time: %fs \n *** fps=%.2f, tpf=%.2fms \n",
- elapsed, frames / elapsed, elapsed / frames * 1000);
- printf("gl_FragColor=%.2f, %.2f, %.2f %.2f \n", output[0], output[1], output[2], output[3]);
-#if defined __arm__
- SaveBMP("/sdcard/mesa.bmp", frameSurface, width, height);
-#else
- SaveBMP("mesa.bmp", frameSurface, width, height);
-#endif
- assert(0.1f < output[3]);
-#if DRAW_TO_SCREEN
- void DisposeDrawingSurface();
-#else
- delete frameSurface;
-#endif
-
-}
-
-int
-main(int argc, char **argv)
-{
- static char basePath [256] = {0};
- static char texturePath [256] = {0};
- static char fragPath [256] = {0};
- static char vertPath [256] = {0};
- static char cubeTexturePath [256] = {0};
- static const char fragFile[] = "fs.frag";
- static const char vertFile[] = "vs.vert";
- static const char textureFile[] = "android.tga";
- static const char cubeTextureFile[] = "cube.tga";
-
- strncpy(basePath, argv[0], strrchr(argv[0], '/') - argv[0] + 1);
- strcpy(fragPath, basePath);
- strcat(fragPath, fragFile);
- strcpy(vertPath, basePath);
- strcat(vertPath, vertFile);
- strcpy(texturePath, basePath);
- strcat(texturePath, textureFile);
- strcpy(cubeTexturePath, basePath);
- strcat(cubeTexturePath, cubeTextureFile);
- //*
- if (1 == argc) {
- const char * args [] = {argv[0], "--dump-hir", "--do-jit", "--link", "--glsl-es", fragPath, vertPath};
- argc = sizeof(args) / sizeof(*args);
- argv = (char **)args;
- }
- //*/
- int status = EXIT_SUCCESS;
- int c;
- int idx = 0;
- while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1)
- /* empty */ ;
-
-
- if (argc <= optind)
- usage_fail(argv[0]);
-
- //initialize_context(ctx, (glsl_es) ? API_OPENGLES2 : API_OPENGL);
- ggl = CreateGGLInterface();
- gl_context * ctx = ((GGLContext *)ggl)->glCtx;
- struct gl_shader_program * program = ggl->ShaderProgramCreate(ggl);
- for (/* empty */; argc > optind; optind++) {
- const unsigned len = strlen(argv[optind]);
- if (len < 6)
- usage_fail(argv[0]);
-
- const char *const ext = & argv[optind][len - 5];
- GLenum Type;
- if (strncmp(".vert", ext, 5) == 0)
- Type = GL_VERTEX_SHADER;
- else if (strncmp(".geom", ext, 5) == 0)
- Type = GL_GEOMETRY_SHADER;
- else if (strncmp(".frag", ext, 5) == 0)
- Type = GL_FRAGMENT_SHADER;
- else
- usage_fail(argv[0]);
-
- struct gl_shader * shader = ggl->ShaderCreate(ggl, Type);
-
-
- char * source = load_text_file(program, argv[optind]);
- if (source == NULL) {
- printf("File \"%s\" does not exist.\n", argv[optind]);
- exit(EXIT_FAILURE);
- }
-
- char * infoLog = NULL;
- if (!ggl->ShaderCompile(ggl, shader, source, &infoLog)) {
- printf("Info log for %s:\n%s\n", argv[optind], infoLog);
- status = EXIT_FAILURE;
- break;
- }
- hieralloc_free(source);
- ggl->ShaderAttach(ggl, program, shader);
- }
-
- puts("link");
-
- if ((status == EXIT_SUCCESS) && do_link) {
- ggl->ShaderProgramLink(ggl, program, NULL);
- status = (program->LinkStatus) ? EXIT_SUCCESS : EXIT_FAILURE;
- assert(program->LinkStatus);
- if (strlen(program->InfoLog) > 0)
- printf("Info log for linking:\n%s\n", program->InfoLog);
- }
-
- for (unsigned i = 0; i < program->Attributes->NumParameters; i++)
- {
- const gl_program_parameter & attribute = program->Attributes->Parameters[i];
- printf("attribute '%s': location=%d slots=%d \n", attribute.Name, attribute.Location, attribute.Slots);
- }
- for (unsigned i = 0; i < program->Varying->NumParameters; i++)
- {
- const gl_program_parameter & varying = program->Varying->Parameters[i];
- printf("varying '%s': vs_location=%d fs_location=%d \n", varying.Name, varying.BindLocation, varying.Location);
- }
- for (unsigned i = 0; i < program->Uniforms->NumUniforms; i++)
- {
- const gl_uniform & uniform = program->Uniforms->Uniforms[i];
- printf("uniform '%s': location=%d type=%s \n", uniform.Name, uniform.Pos, uniform.Type->name);
- }
-
- puts("jit");
-
- GGLTexture texture = {0};
- LoadTGA(texturePath, &texture.width, &texture.height, &texture.levels);
- texture.format = GGL_PIXEL_FORMAT_RGBA_8888;
- texture.type = GL_TEXTURE_2D;
- texture.levelCount = 1;
- texture.wrapS = texture.wrapT = 0; // repeat = 0 fastest, clamp = 1, mirrored = 2
- texture.minFilter = texture.magFilter = 0; // nearest = 0, linear = 1
- ggl->SetSampler(ggl, 0, &texture);
-
- ggl->ShaderUse(ggl, program);
-
- texture.minFilter = texture.magFilter = 1; // nearest = 0, linear = 1
- ggl->SetSampler(ggl, 0, &texture);
-
- ggl->ShaderUse(ggl, program);
-
- static unsigned cubeTextureSurface [6] = {0xff0000ff, 0xff00ff00, 0xffff0000,
- 0xff00ffff, 0xffffff00, 0xffff00ff};
- GGLTexture cubeTexture = {GL_TEXTURE_CUBE_MAP, GGL_PIXEL_FORMAT_RGBA_8888, 1, 1, 1, cubeTextureSurface, 1, 2, 1, 1};
-
-
- int samplerLocation = -1;
- if (0 <= (samplerLocation = ggl->ShaderUniformLocation(ggl, program, "samp2D")))
- ggl->SetSampler(ggl, samplerLocation, &texture);
- if (0 <= (samplerLocation = ggl->ShaderUniformLocation(ggl, program, "samp2DA")))
- ggl->SetSampler(ggl, samplerLocation, &texture);
- if (0 <= (samplerLocation = ggl->ShaderUniformLocation(ggl, program, "sampCube")))
- ggl->SetSampler(ggl, samplerLocation, &texture);
-
- execute((GGLContext *)ggl);
-// puts("\n *** IR for JIT *** \n");
-// //_mesa_print_ir(ir, NULL);
-//
-// shader->executable = hieralloc_zero(shader, Executable);
-// llvm::Module * module = glsl_ir_to_llvm_module(shader->ir, (GGLContext *)ggl);
-// assert(module);
-// shader->executable->module = module;
-// puts("\n *** Module for JIT *** \n");
-// //module->dump();
-// jit(shader, program, (GGLContext *)ggl);
-// puts("jitted");
-
- free(texture.levels);
-
- ggl->ShaderProgramDelete(ggl, program);
-
- DestroyGGLInterface((GGLInterface *)ggl);
-
- printf("mesa exit(%d) \n", status);
- hieralloc_report_brief(NULL, stdout);
- return status;
-}
-
-#endif // build executable
diff --git a/src/pixelflinger2/pixelflinger2.cpp b/src/pixelflinger2/pixelflinger2.cpp
index 06d3443..bc4b827 100644
--- a/src/pixelflinger2/pixelflinger2.cpp
+++ b/src/pixelflinger2/pixelflinger2.cpp
@@ -235,4 +235,14 @@ void DestroyGGLInterface(GGLInterface * iface)
ctx->glCtx = NULL;
free(ctx);
+
+#if USE_LLVM_TEXTURE_SAMPLER
+ puts("USE_LLVM_TEXTURE_SAMPLER");
+#endif
+#if USE_LLVM_SCANLINE
+ puts("USE_LLVM_SCANLINE");
+#endif
+#if USE_LLVM_EXECUTIONENGINE
+ puts("USE_LLVM_EXECUTIONENGINE");
+#endif
} \ No newline at end of file
diff --git a/src/pixelflinger2/shader.cpp b/src/pixelflinger2/shader.cpp
index 7537f2f..c36c796 100644
--- a/src/pixelflinger2/shader.cpp
+++ b/src/pixelflinger2/shader.cpp
@@ -197,7 +197,7 @@ static void ShaderDetach(const GGLInterface * iface, gl_shader_program * program
}
static GLboolean ShaderProgramLink(const GGLInterface * iface, gl_shader_program * program,
- char ** infoLog)
+ const char ** infoLog)
{
GGL_GET_CONST_CONTEXT(ctx, iface);
link_shaders(ctx->glCtx, program);
@@ -465,7 +465,19 @@ static GLint ShaderAttributeLocation(const GGLInterface * iface, const gl_shader
int i = _mesa_get_parameter(program->Attributes, name);
if (i >= 0)
return program->Attributes->Parameters[i].Location;
- return -2;
+ return -1;
+}
+
+static GLint ShaderVaryingLocation(const GGLInterface_t * iface, const gl_shader_program_t * program,
+ const char * name, GLint * vertexOutputLocation)
+{
+ for (unsigned int i = 0; i < program->Varying->NumParameters; i++)
+ if (!strcmp(program->Varying->Parameters[i].Name, name)) {
+ if (vertexOutputLocation)
+ *vertexOutputLocation = program->Varying->Parameters[i].BindLocation;
+ return program->Varying->Parameters[i].Location;
+ }
+ return -1;
}
static GLint ShaderUniformLocation(const GGLInterface * iface, const gl_shader_program * program,
@@ -475,7 +487,7 @@ static GLint ShaderUniformLocation(const GGLInterface * iface, const gl_shader_p
for (unsigned i = 0; i < program->Uniforms->NumUniforms; i++)
if (!strcmp(program->Uniforms->Uniforms[i].Name, name))
return program->Uniforms->Uniforms[i].Pos;
- return -2;
+ return -1;
}
static void ShaderUniformGetfv(const GGLInterface * iface, gl_shader_program * program,
@@ -634,6 +646,7 @@ void InitializeShaderFunctions(struct GGLInterface * iface)
iface->ShaderProgramDelete = ShaderProgramDelete;
iface->ShaderAttributeBind = ShaderAttributeBind;
iface->ShaderAttributeLocation = ShaderAttributeLocation;
+ iface->ShaderVaryingLocation = ShaderVaryingLocation;
iface->ShaderUniformLocation = ShaderUniformLocation;
iface->ShaderUniformGetfv = ShaderUniformGetfv;
iface->ShaderUniformGetiv = ShaderUniformGetiv;
diff --git a/test/Android.mk b/test/Android.mk
new file mode 100644
index 0000000..f5f62f2
--- /dev/null
+++ b/test/Android.mk
@@ -0,0 +1,55 @@
+DEBUG_BUILD := true
+
+ifneq ($(TARGET_SIMULATOR),true)
+
+LOCAL_PATH := $(call my-dir)
+
+mesa_SRC_FILES := \
+ egl.cpp \
+ cmain.c \
+ main.cpp
+
+# Executable for host
+# ========================================================
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+ifeq ($(DEBUG_BUILD),true)
+LOCAL_CPPFLAGS += -DDEBUG -UNDEBUG -O0 -g
+LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g
+endif
+
+LOCAL_MODULE := mesa
+LOCAL_SRC_FILES := $(mesa_SRC_FILES)
+LOCAL_STATIC_LIBRARIES := libMesa
+LOCAL_SHARED_LIBRARIES := libbcc
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH) \
+ frameworks/compile/mesa/include
+
+include $(BUILD_HOST_EXECUTABLE)
+
+# Executable for target
+# ========================================================
+include $(CLEAR_VARS)
+
+#LOCAL_PRELINK_MODULE := false
+LOCAL_MODULE_TAGS := optional
+
+ifeq ($(DEBUG_BUILD),true)
+LOCAL_CPPFLAGS += -DDEBUG -UNDEBUG -O0 -g
+LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g
+endif
+
+LOCAL_MODULE := mesa
+LOCAL_SRC_FILES := $(mesa_SRC_FILES)
+LOCAL_STATIC_LIBRARIES := libMesa
+LOCAL_SHARED_LIBRARIES := libstlport libcutils libutils libhardware libsurfaceflinger_client libbcc libdl
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH) \
+ frameworks/compile/mesa/include
+
+include $(BUILD_EXECUTABLE)
+
+endif # TARGET_SIMULATOR != true
diff --git a/test/Debug/android.tga b/test/Debug/android.tga
new file mode 100644
index 0000000..cd009ad
--- /dev/null
+++ b/test/Debug/android.tga
Binary files differ
diff --git a/test/Debug/fs.frag b/test/Debug/fs.frag
new file mode 100644
index 0000000..ba9719f
--- /dev/null
+++ b/test/Debug/fs.frag
@@ -0,0 +1,47 @@
+uniform sampler2D samp2DArray[9];
+uniform samplerCube sampCube;
+uniform sampler2D samp2D;
+uniform sampler2D samp2DA;
+uniform vec4 uFragmentColor;
+uniform mat4 uRotM;
+
+varying vec4 vTexCoord;
+varying vec4 vNormal;
+
+void main(void)
+{
+ //gl_FragColor.xy = gl_FragCoord.xy / vec2(480, 800);
+ //gl_FragColor.z = !gl_FrontFacing ? 1 : 0;
+
+ //gl_FragColor += vec4(0,0,0,0);
+ //gl_FragColor = vTexCoord.xyzw;
+ //gl_FragColor = texture2D(samp2DArray[int(vTexCoord.z)], vTexCoord.xy);
+ gl_FragColor = texture2D(samp2D, vTexCoord.xy) * vTexCoord;
+ //gl_FragColor = textureCube(sampCube, vTexCoord.xyz);
+ //gl_FragColor *= vNormal;
+ //gl_FragColor = textureCube(samplercube, vNormal.xyz);
+ //gl_FragColor.rgb = vec3(sin(gl_FragColor.r));
+ //gl_FragColor.a = 1;
+ //gl_FragColor *= (vTexCoord.wwww - vTexCoord * vTexCoord);
+
+
+ //gl_FragColor = gl_FragColor * gl_FragColor * gl_FragColor;
+
+
+ //gl_FragColor = gl_FragColor * gl_FragColor;
+ //gl_FragColor -= vec4(0.5);
+ //gl_FragColor.a = 0;
+ //gl_FragColor = uRotM * gl_FragColor;
+ //gl_FragColor += vec4(0.5);
+
+ //float dot = dot(vNormal.xyz, vec3(-1.414213562373095, 0, -1.414213562373095));
+ //float dot = dot(vNormal.xyz, vNormal.xyz);
+ //gl_FragColor.rgb *= vec3(dot);
+ //gl_FragColor.rgb += vNormal.xyz;
+ //gl_FragColor = (gl_FragCoord / vec4(480, 800, 1, 1));
+ //gl_FragColor.r = gl_FrontFacing == true ? 1.0 : 0.0;
+ //gl_FragColor.gb = gl_PointCoord;
+ //gl_FragColor = vTexCoord;
+
+ //gl_FragColor.a = 1;
+}
diff --git a/test/Debug/stress_fs.frag b/test/Debug/stress_fs.frag
new file mode 100644
index 0000000..0943ede
--- /dev/null
+++ b/test/Debug/stress_fs.frag
@@ -0,0 +1,88 @@
+uniform float t;
+varying vec4 vTexCoord;
+
+const float BLOWUP=66.0; /* 86.0 */
+const float MAXSTEPSHIFT=8.0; /* 6.0 */
+const int MAXITERS=34; /* 26 */
+
+const float pi=3.1415926535;
+
+float sum(vec3 v) { return v.x+v.y+v.z; }
+
+int func(vec3 pos,float stepshift)
+{
+ vec3 v2=abs(fract(pos)-vec3(0.5,0.5,0.5))/2.0;
+ float r=0.0769*sin(t*-0.0708);
+ float blowup=BLOWUP/pow(2.0,stepshift+8.0);
+
+ if(sum(v2)-0.1445+r<blowup) return 1;
+ v2=vec3(0.25,0.25,0.25)-v2;
+ if(sum(v2)-0.1445-r<blowup) return 2;
+
+ int hue;
+ float width;
+ if(abs(sum(v2)-3.0*r-0.375)<0.03846)
+ {
+ width=0.1445;
+ hue=4;
+ }
+ else
+ {
+ width=0.0676;
+ hue=3;
+ }
+
+ if(sum(abs(v2.zxy-v2.xyz))-width<blowup) return hue;
+
+ return 0;
+}
+
+void main()
+{
+ float x=vTexCoord.x*0.5;
+ float y=vTexCoord.y*0.5;
+
+ float sin_a=sin(t*0.00564);
+ float cos_a=cos(t*0.00564);
+
+ vec3 dir=vec3(x,-y,0.33594-x*x-y*y);
+ dir=vec3(dir.y,dir.z*cos_a-dir.x*sin_a,dir.x*cos_a+dir.z*sin_a);
+ dir=vec3(dir.y,dir.z*cos_a-dir.x*sin_a,dir.x*cos_a+dir.z*sin_a);
+ dir=vec3(dir.y,dir.z*cos_a-dir.x*sin_a,dir.x*cos_a+dir.z*sin_a);
+
+ vec3 pos=vec3(0.5,1.1875,0.875)+vec3(1.0,1.0,1.0)*0.0134*t;
+
+ float stepshift=MAXSTEPSHIFT;
+
+ if(fract(pow(x,y)*t*1000.0)>0.5) pos+=dir/pow(2.0,stepshift);
+ else pos-=dir/pow(2.0,stepshift);
+
+ int i=0;
+ int c;
+ do
+ {
+ c=func(pos,stepshift);
+ if(c>0)
+ {
+ stepshift+=1.0;
+ pos-=dir/pow(2.0,stepshift);
+ }
+ else
+ {
+ if(stepshift>0.0) stepshift-=1.0;
+ pos+=dir/pow(2.0,stepshift);
+ i++;
+ }
+ }
+ while(stepshift<MAXSTEPSHIFT&&i<MAXITERS);
+
+
+ vec3 col;
+ if(c==0) col=vec3(0.0,0.0,0.0);
+ else if(c==1) col=vec3(1.0,0.5,0.0);
+ else if(c==2) col=vec3(0.0,1.0,0.0);
+ else if(c==3) col=vec3(1.0,1.0,1.0);
+ else if(c==4) col=vec3(0.5,0.5,0.5);
+
+ gl_FragColor=vec4(col*(1.0-(float(i)-stepshift)/32.0),1.0);
+}
diff --git a/test/Debug/vs.vert b/test/Debug/vs.vert
new file mode 100644
index 0000000..39cc6ea
--- /dev/null
+++ b/test/Debug/vs.vert
@@ -0,0 +1,24 @@
+uniform sampler2D sampler2d;
+uniform mat4 uMatrix;
+uniform mat4 uRotM;
+uniform vec4 uIndex;
+
+attribute vec4 aPosition;
+attribute vec4 aTexCoord;
+attribute mat4 aTransM;
+
+varying vec4 vTexCoord;
+varying vec4 vNormal;
+
+void main()
+{
+ vTexCoord = aTexCoord;// + texture2D(sampler2d, aTexCoord.xy);
+ //gl_Position = uMatrix * aPosition;// * vec4(0.5,0.5,0.5,1);
+ gl_Position = aPosition;
+ gl_Position = aTransM * gl_Position;
+ //gl_Position = aPosition * vec4(0.2, 0.2, 0.2, 1);
+ vNormal = aPosition / vec4(vec3(1.732050807568877),1);
+ gl_PointSize = aTexCoord.z;
+ //vNormal = vec4(vec3(0.01),1);
+ //vNormal = (uRotM * vec4(vNormal, 0)).xyz;
+}
diff --git a/test/cmain.c b/test/cmain.c
new file mode 100644
index 0000000..2b1b55c
--- /dev/null
+++ b/test/cmain.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+#include <pixelflinger2/pixelflinger2_interface.h>
+
+int cmain(int argc, char **argv)
+{
+ printf("hello world\n");
+ return 0;
+}
diff --git a/egl.cpp b/test/egl.cpp
index 017e2b7..cfdf74e 100644
--- a/egl.cpp
+++ b/test/egl.cpp
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#ifdef __arm__
+
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
@@ -2008,3 +2010,5 @@ extern "C" void DisposeDrawingSurface()
puts("DisposeDrawingSurface");
}
+
+#endif // #ifdef __arm__ \ No newline at end of file
diff --git a/src/glsl/image_file.h b/test/image_file.h
index 19ddd9d..2fd29a7 100644
--- a/src/glsl/image_file.h
+++ b/test/image_file.h
@@ -249,7 +249,7 @@ static int LoadTGA(const char * filePath, unsigned int * width, unsigned int * h
static unsigned GenerateMipmaps(void ** data, const unsigned width, const unsigned height)
{
unsigned levels = 1;
- unsigned dim = MAX2(width, height) >> 1;
+ unsigned dim = (width > height ? width : height) >> 1;
unsigned size = 0, w = width, h = height;
while (dim)
{
@@ -275,8 +275,8 @@ static unsigned GenerateMipmaps(void ** data, const unsigned width, const unsign
{
unsigned s = x * 2 + xx;
unsigned t = y * 2 + yy;
- s = MIN2(s, w - 1);
- t = MIN2(t, h - 1);
+ s = s < w - 1 ? s : w - 1;
+ t = t < h - 1 ? t : h - 1;
const Pixel * p = previous + t * w + s;
for (unsigned i = 0; i < 4; i++)
channels[i] += p->channels[i];
diff --git a/test/main.cpp b/test/main.cpp
new file mode 100644
index 0000000..fdb7dea
--- /dev/null
+++ b/test/main.cpp
@@ -0,0 +1,397 @@
+/*
+ * Copyright © 2008, 2009 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.
+ */
+#include <cstdlib>
+#include <cstdio>
+#include <getopt.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <pixelflinger2/pixelflinger2_interface.h>
+#include "../src/talloc/hieralloc.h"
+
+GGLInterface * ggl = NULL;
+
+/* Returned string will have 'ctx' as its hieralloc owner. */
+static char *
+load_text_file(void *ctx, const char *file_name)
+{
+ char *text = NULL;
+ struct stat st;
+ ssize_t total_read = 0;
+ int fd = open(file_name, O_RDONLY);
+
+ if (fd < 0) {
+ return NULL;
+ }
+
+ if (fstat(fd, & st) == 0) {
+ text = (char *) hieralloc_size(ctx, st.st_size + 1);
+ if (text != NULL) {
+ do {
+ ssize_t bytes = read(fd, text + total_read,
+ st.st_size - total_read);
+ if (bytes < 0) {
+ free(text);
+ text = NULL;
+ break;
+ }
+
+ if (bytes == 0) {
+ break;
+ }
+
+ total_read += bytes;
+ } while (total_read < st.st_size);
+
+ text[total_read] = '\0';
+ }
+ }
+
+ close(fd);
+
+ return text;
+}
+
+int glsl_es = 0;
+int dump_ast = 0;
+int dump_hir = 0;
+int dump_lir = 0;
+int do_link = 0;
+int do_jit = 0;
+
+const struct option compiler_opts[] = {
+ { "glsl-es", 0, &glsl_es, 1
+ }, { "dump-ast", 0, &dump_ast, 1 }, { "dump-hir", 0, &dump_hir, 1 }, { "dump-lir", 0, &dump_lir, 1 }, { "link", 0, &do_link, 1 }, { "do-jit", 0, &do_jit, 1 }, { NULL, 0, NULL, 0 }
+};
+
+/**
+ * \brief Print proper usage and exit with failure.
+ */
+void
+usage_fail(const char *name)
+{
+
+ const char *header =
+ "usage: %s [options] <file.vert | file.geom | file.frag>\n"
+ "\n"
+ "Possible options are:\n";
+ printf(header, name, name);
+ for (const struct option *o = compiler_opts; o->name != 0; ++o) {
+ printf(" --%s\n", o->name);
+ }
+ exit(EXIT_FAILURE);
+}
+
+#define DRAW_TO_SCREEN 1
+#include "image_file.h"
+
+#if defined __arm__ && defined DRAW_TO_SCREEN
+extern "C" int SetupDrawingSurface(unsigned * width, unsigned * height, unsigned * bpp);
+extern "C" void * PresentDrawingSurface();
+extern "C" void DisposeDrawingSurface();
+#endif
+
+void execute(const gl_shader_program * program)
+{
+ puts("execute");
+
+ //const gl_shader * shader = ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_FRAGMENT];
+ const gl_shader * shader = NULL;
+#if defined __arm__ && DRAW_TO_SCREEN
+ unsigned width = 0, height = 0, bpp = 0;
+ int err = SetupDrawingSurface(&width, &height, &bpp);
+ assert(!err);
+ assert(32 == bpp);
+ unsigned * frameSurface = (unsigned *)PresentDrawingSurface();
+#else
+ const unsigned width = 1280, height = 800;
+ unsigned * frameSurface = new unsigned [width * height];
+#endif
+ //const unsigned scale = 16, portWidth = 80, portHeight = 50;
+ unsigned scale = 1, portWidth = width / scale, portHeight = height / scale;
+ //unsigned scale = 1, portWidth = width / 4, portHeight = height / 4;
+
+ GGLSurface colorSurface = {width, height, GGL_PIXEL_FORMAT_RGBA_8888, frameSurface, width, sizeof(GGLSurface)};
+ ggl->SetBuffer(ggl, GL_COLOR_BUFFER_BIT, &colorSurface);
+ ggl->EnableDisable(ggl, GL_DEPTH_TEST, false);
+
+// float * uniform = (float *)ctx->glCtx->CurrentProgram->ValuesUniform;
+// float * attribute = (float *)ctx->glCtx->CurrentProgram->ValuesVertexInput;
+// float * varying = (float *)ctx->glCtx->CurrentProgram->ValuesVertexOutput;
+// float * output = ((VertexOutput*)ctx->glCtx->CurrentProgram->ValuesVertexOutput)->fragColor[0].f;
+// int glFragColorLocation = 0;
+ int vTexCoordLocation = ggl->ShaderVaryingLocation(ggl, program, "vTexCoord", NULL);
+// if (shader->symbols->get_variable("vTexCoord"))
+// vTexCoordLocation = shader->symbols->get_variable("vTexCoord")->location;
+// int vNormalLocation = -1;
+// if (shader->symbols->get_variable("vNormal"))
+// vNormalLocation = shader->symbols->get_variable("vNormal")->location;
+// if (shader->symbols->get_variable("uRotM") && 0) {
+// ir_variable * var = shader->symbols->get_variable("uRotM");
+// float * matrix = uniform + 4 * 1 + 4 * shader->symbols->get_variable("uRotM")->location;
+// memset(matrix, 0, 16 * sizeof(*matrix));
+// matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1;
+// matrix[28] = 0;
+// matrix[29] = 0;
+// matrix[30] = 0;
+// matrix[31] = 0;
+// }
+// printf("executing... \n function=%p \n", shader->function);
+
+ /*
+ #ifdef __arm__
+ {
+ volatile unsigned wait = 1;
+ printf("waiting for attach, set wait(%p) to 0 \n", &wait);
+ puts("");
+ while (wait);
+ }
+ #endif
+ //*/
+
+
+
+ unsigned frames = 1;
+ clock_t c0 = clock();
+
+ //while(true)
+ for (frames = 1; frames <= 20; frames++) {
+ for (unsigned y = 0; y < portHeight; y++) {
+ VertexOutput v0, v1;
+ v0.position = Vector4(0, y, 0, 0);
+ v1.position = Vector4(portWidth - 1, y ,0 ,0);
+ if (vTexCoordLocation > -1) {
+ v0.varyings[vTexCoordLocation - 2] = Vector4(0, (float)y / (portHeight - 1), 0, 1);
+ v1.varyings[vTexCoordLocation - 2] = Vector4(1, (float)y / (portHeight - 1), 0, 1);
+ }
+ ggl->ScanLine(ggl, &v0, &v1);
+
+// for (unsigned x = 0; x < portWidth; x++) {
+// if (vTexCoordLocation > -1)
+// {
+// varying[vTexCoordLocation * 4 + 0] = ((float)x) / (portWidth - 1);
+// varying[vTexCoordLocation * 4 + 1] = ((float)y) / (portHeight - 1);
+// varying[vTexCoordLocation * 4 + 2] = 0;
+// varying[vTexCoordLocation * 4 + 3] = 1;
+// }
+//// if (vNormalLocation > -1)
+//// {
+//// varying[vNormalLocation * 4 + 0] = 0;
+//// varying[vNormalLocation * 4 + 1] = 1;
+//// varying[vNormalLocation * 4 + 2] = 0;
+//// varying[vNormalLocation * 4 + 3] = 1;
+//// }
+// shader->function();
+// unsigned r = output[0] * 255;
+// unsigned g = output[1] * 255;
+// unsigned b = output[2] * 255;
+// unsigned a = output[3] * 255;
+// frameSurface[y * width + x] = (a << 24) | (b << 16) | (g << 8) | r;
+// }
+ }
+ //*
+ if (scale > 1)
+ for (int y = portHeight - 1; y >= 0; y--)
+ for (int x = portWidth - 1; x >= 0; x--) {
+ unsigned pixel = ((unsigned *)frameSurface)[y * width + x];
+ for (unsigned xx = 0; xx < scale; xx++)
+ for (unsigned yy = 0; yy < scale; yy++)
+ ((unsigned *)frameSurface)[(y * scale + yy) * width + x * scale + xx] = pixel;
+ }
+ //*/
+#if defined __arm__ && DRAW_TO_SCREEN
+ frameSurface = (unsigned *)PresentDrawingSurface();
+ colorSurface.data = frameSurface;
+ ggl->SetBuffer(ggl, GL_COLOR_BUFFER_BIT, &colorSurface);
+#endif
+ }
+
+ float elapsed = (float)(clock() - c0) / CLOCKS_PER_SEC;
+ printf ("\n *** test_scan elapsed CPU time: %fs \n *** fps=%.2f, tpf=%.2fms \n",
+ elapsed, frames / elapsed, elapsed / frames * 1000);
+ //printf("gl_FragColor=%.2f, %.2f, %.2f %.2f \n", output[0], output[1], output[2], output[3]);
+#if defined __arm__
+ SaveBMP("/sdcard/mesa.bmp", frameSurface, width, height);
+#else
+ SaveBMP("mesa.bmp", frameSurface, width, height);
+#endif
+ //assert(0.1f < output[3]);
+#if DRAW_TO_SCREEN
+ void DisposeDrawingSurface();
+#else
+ delete frameSurface;
+#endif
+
+}
+
+int
+main(int argc, char **argv)
+{
+ static char basePath [256] = {0};
+ static char texturePath [256] = {0};
+ static char fragPath [256] = {0};
+ static char vertPath [256] = {0};
+ static char cubeTexturePath [256] = {0};
+ static const char fragFile[] = "fs.frag";
+ static const char vertFile[] = "vs.vert";
+ static const char textureFile[] = "android.tga";
+ static const char cubeTextureFile[] = "cube.tga";
+
+ strncpy(basePath, argv[0], strrchr(argv[0], '/') - argv[0] + 1);
+ strcpy(fragPath, basePath);
+ strcat(fragPath, fragFile);
+ strcpy(vertPath, basePath);
+ strcat(vertPath, vertFile);
+ strcpy(texturePath, basePath);
+ strcat(texturePath, textureFile);
+ strcpy(cubeTexturePath, basePath);
+ strcat(cubeTexturePath, cubeTextureFile);
+ //*
+ if (1 == argc) {
+ const char * args [] = {argv[0], "--dump-hir", "--do-jit", "--link", "--glsl-es", fragPath, vertPath};
+ argc = sizeof(args) / sizeof(*args);
+ argv = (char **)args;
+ }
+ //*/
+ int status = EXIT_SUCCESS;
+ int c;
+ int idx = 0;
+ while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1)
+ /* empty */ ;
+
+
+ if (argc <= optind)
+ usage_fail(argv[0]);
+
+ //initialize_context(ctx, (glsl_es) ? API_OPENGLES2 : API_OPENGL);
+ ggl = CreateGGLInterface();
+
+ struct gl_shader_program * program = ggl->ShaderProgramCreate(ggl);
+ for (/* empty */; argc > optind; optind++) {
+ const unsigned len = strlen(argv[optind]);
+ if (len < 6)
+ usage_fail(argv[0]);
+
+ const char *const ext = & argv[optind][len - 5];
+ GLenum Type;
+ if (strncmp(".vert", ext, 5) == 0)
+ Type = GL_VERTEX_SHADER;
+ else if (strncmp(".geom", ext, 5) == 0)
+ //Type = GL_GEOMETRY_SHADER;
+ assert(0);
+ else if (strncmp(".frag", ext, 5) == 0)
+ Type = GL_FRAGMENT_SHADER;
+ else
+ usage_fail(argv[0]);
+
+ struct gl_shader * shader = ggl->ShaderCreate(ggl, Type);
+
+
+ char * source = load_text_file(program, argv[optind]);
+ if (source == NULL) {
+ printf("File \"%s\" does not exist.\n", argv[optind]);
+ exit(EXIT_FAILURE);
+ }
+
+ char * infoLog = NULL;
+ if (!ggl->ShaderCompile(ggl, shader, source, &infoLog)) {
+ printf("Info log for %s:\n%s\n", argv[optind], infoLog);
+ status = EXIT_FAILURE;
+ break;
+ }
+ hieralloc_free(source);
+ ggl->ShaderAttach(ggl, program, shader);
+ }
+
+ puts("link");
+
+ if ((status == EXIT_SUCCESS) && do_link) {
+ const char * infoLog = NULL;
+ bool linkStatus = ggl->ShaderProgramLink(ggl, program, &infoLog);
+ status = linkStatus ? EXIT_SUCCESS : EXIT_FAILURE;
+ assert(linkStatus);
+ if (strlen(infoLog) > 0)
+ printf("Info log for linking:\n%s\n", infoLog);
+ }
+
+ puts("jit");
+
+ GGLTexture texture = {0};
+ LoadTGA(texturePath, &texture.width, &texture.height, &texture.levels);
+ texture.format = GGL_PIXEL_FORMAT_RGBA_8888;
+ texture.type = GL_TEXTURE_2D;
+ texture.levelCount = 1;
+ texture.wrapS = texture.wrapT = 0; // repeat = 0 fastest, clamp = 1, mirrored = 2
+ texture.minFilter = texture.magFilter = 0; // nearest = 0, linear = 1
+ ggl->SetSampler(ggl, 0, &texture);
+
+ ggl->ShaderUse(ggl, program);
+
+ texture.minFilter = texture.magFilter = 1; // nearest = 0, linear = 1
+ ggl->SetSampler(ggl, 0, &texture);
+
+ ggl->ShaderUse(ggl, program);
+
+ static unsigned cubeTextureSurface [6] = {0xff0000ff, 0xff00ff00, 0xffff0000,
+ 0xff00ffff, 0xffffff00, 0xffff00ff
+ };
+ GGLTexture cubeTexture = {GL_TEXTURE_CUBE_MAP, GGL_PIXEL_FORMAT_RGBA_8888, 1, 1, 1, cubeTextureSurface, 1, 2, 1, 1};
+
+
+ int samplerLocation = -1;
+ if (0 <= (samplerLocation = ggl->ShaderUniformLocation(ggl, program, "samp2D")))
+ ggl->SetSampler(ggl, samplerLocation, &texture);
+ if (0 <= (samplerLocation = ggl->ShaderUniformLocation(ggl, program, "samp2DA")))
+ ggl->SetSampler(ggl, samplerLocation, &texture);
+ if (0 <= (samplerLocation = ggl->ShaderUniformLocation(ggl, program, "sampCube")))
+ ggl->SetSampler(ggl, samplerLocation, &texture);
+
+ execute(program);
+// puts("\n *** IR for JIT *** \n");
+// //_mesa_print_ir(ir, NULL);
+//
+// shader->executable = hieralloc_zero(shader, Executable);
+// llvm::Module * module = glsl_ir_to_llvm_module(shader->ir, (GGLContext *)ggl);
+// assert(module);
+// shader->executable->module = module;
+// puts("\n *** Module for JIT *** \n");
+// //module->dump();
+// jit(shader, program, (GGLContext *)ggl);
+// puts("jitted");
+
+ free(texture.levels);
+
+ ggl->ShaderProgramDelete(ggl, program);
+
+ DestroyGGLInterface((GGLInterface *)ggl);
+
+ printf("mesa exit(%d) \n", status);
+ hieralloc_report_brief(NULL, stdout);
+ return status;
+}
diff --git a/test/mesa.project b/test/mesa.project
new file mode 100644
index 0000000..384df00
--- /dev/null
+++ b/test/mesa.project
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="utf-8"?>
+<CodeLite_Project Name="mesa" InternalType="Console">
+ <Plugins>
+ <Plugin Name="qmake">
+ <![CDATA[00010001N0005Debug000000000000]]>
+ </Plugin>
+ </Plugins>
+ <Description/>
+ <Dependencies/>
+ <VirtualDirectory Name="test">
+ <File Name="image_file.h"/>
+ <File Name="main.cpp"/>
+ <File Name="egl.cpp"/>
+ <File Name="cmain.c"/>
+ </VirtualDirectory>
+ <Settings Type="Executable">
+ <Configuration Name="Debug" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
+ <Compiler Options="-g;-D__STDC_LIMIT_MACROS;-D__STDC_CONSTANT_MACROS;-m32 -march=i686;-DDEBUG;-UNDEBUG;-O0" Required="yes" PreCompiledHeader="">
+ <IncludePath Value="."/>
+ <IncludePath Value="../include/"/>
+ <IncludePath Value="../../../base/opengl/include"/>
+ </Compiler>
+ <Linker Options="-m32 -lstdc++ -ldl -lpthread -lbcc" Required="yes">
+ <LibraryPath Value="../Debug"/>
+ <Library Value="libMesa"/>
+ </Linker>
+ <ResourceCompiler Options="" Required="no"/>
+ <General OutputFile="./Debug/$(ProjectName)" IntermediateDirectory="./Debug/obj" Command="./$(ProjectName)" CommandArguments="" WorkingDirectory="./Debug" PauseExecWhenProcTerminates="yes"/>
+ <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="">
+ <PostConnectCommands/>
+ <StartupCommands/>
+ </Debugger>
+ <PreBuild/>
+ <PostBuild/>
+ <CustomBuild Enabled="no">
+ <RebuildCommand/>
+ <CleanCommand/>
+ <BuildCommand/>
+ <PreprocessFileCommand/>
+ <SingleFileCommand/>
+ <MakefileGenerationCommand/>
+ <ThirdPartyToolName>None</ThirdPartyToolName>
+ <WorkingDirectory/>
+ </CustomBuild>
+ <AdditionalRules>
+ <CustomPostBuild/>
+ <CustomPreBuild/>
+ </AdditionalRules>
+ </Configuration>
+ <Configuration Name="Release" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
+ <Compiler Options="" Required="yes" PreCompiledHeader="">
+ <IncludePath Value="."/>
+ </Compiler>
+ <Linker Options="-O2" Required="yes"/>
+ <ResourceCompiler Options="" Required="no"/>
+ <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/>
+ <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="">
+ <PostConnectCommands/>
+ <StartupCommands/>
+ </Debugger>
+ <PreBuild/>
+ <PostBuild/>
+ <CustomBuild Enabled="no">
+ <RebuildCommand/>
+ <CleanCommand/>
+ <BuildCommand/>
+ <PreprocessFileCommand/>
+ <SingleFileCommand/>
+ <MakefileGenerationCommand/>
+ <ThirdPartyToolName>None</ThirdPartyToolName>
+ <WorkingDirectory/>
+ </CustomBuild>
+ <AdditionalRules>
+ <CustomPostBuild/>
+ <CustomPreBuild/>
+ </AdditionalRules>
+ </Configuration>
+ <GlobalSettings>
+ <Compiler Options="">
+ <IncludePath Value="."/>
+ </Compiler>
+ <Linker Options="">
+ <LibraryPath Value="."/>
+ </Linker>
+ <ResourceCompiler Options=""/>
+ </GlobalSettings>
+ </Settings>
+ <Dependencies Name="Debug">
+ <Project Name="libMesa"/>
+ </Dependencies>
+</CodeLite_Project>