diff options
author | David Li <davidxli@google.com> | 2011-02-08 14:25:22 -0800 |
---|---|---|
committer | David Li <davidxli@google.com> | 2011-02-08 14:25:22 -0800 |
commit | b341bc8271147be311b77937347f0f3f54aab749 (patch) | |
tree | 22d2e62cea837f5309e934bcff3d866b0099cfff /test | |
parent | 2ac1cf8a62bcf080b70eaa7c0e4f57d4e8001685 (diff) |
Changed some states to enum; static gl_context for shader compiling/linking.
Changed language version from 100 to 120.
Diffstat (limited to 'test')
-rw-r--r-- | test/Android.mk | 3 | ||||
-rw-r--r-- | test/cmain.c | 22 | ||||
-rw-r--r-- | test/egl.cpp | 19 | ||||
-rw-r--r-- | test/main.cpp | 162 | ||||
-rw-r--r-- | test/mesa.project | 10 |
5 files changed, 176 insertions, 40 deletions
diff --git a/test/Android.mk b/test/Android.mk index 593d163..4776c3d 100644 --- a/test/Android.mk +++ b/test/Android.mk @@ -3,6 +3,7 @@ DEBUG_BUILD := true ifneq ($(TARGET_SIMULATOR),true) LOCAL_PATH := $(call my-dir) +LLVM_ROOT_PATH := external/llvm mesa_SRC_FILES := \ egl.cpp \ @@ -29,6 +30,7 @@ LOCAL_C_INCLUDES := \ $(LOCAL_PATH) \ frameworks/compile/mesa/include +include $(LLVM_ROOT_PATH)/llvm-host-build.mk include $(BUILD_HOST_EXECUTABLE) # Executable for target @@ -51,6 +53,7 @@ LOCAL_C_INCLUDES := \ $(LOCAL_PATH) \ frameworks/compile/mesa/include +include $(LLVM_ROOT_PATH)/llvm-device-build.mk include $(BUILD_EXECUTABLE) endif # TARGET_SIMULATOR != true diff --git a/test/cmain.c b/test/cmain.c index 6271f2e..3ffeaa0 100644 --- a/test/cmain.c +++ b/test/cmain.c @@ -37,7 +37,7 @@ int cmain(int argc, char **argv) " gl_Position = aPosition; \n" " vTexCoord = aTexCoord + uVec4; \n" " vTexColor = texture2D(sampler2d, aTexCoord.zw); \n" - " gl_PointSize = 432.0; \n" + " gl_PointSize = 432; \n" "}"; puts(glsl0); GLboolean compileStatus = ggl->ShaderCompile(ggl, shader0, glsl0, &infoLog); @@ -69,7 +69,7 @@ int cmain(int argc, char **argv) ggl->ShaderAttributeBind(program0, 2, "aTexCoord"); ggl->ShaderAttributeBind(program0, 3, "aPosition"); - GLboolean linkStatus = ggl->ShaderProgramLink(ggl, program0, &infoLog); + GLboolean linkStatus = ggl->ShaderProgramLink(program0, &infoLog); if (!linkStatus) fprintf(stderr, "failed to link program 0, infoLog: \n %s \n", infoLog); assert(linkStatus); @@ -79,7 +79,7 @@ int cmain(int argc, char **argv) unsigned texels0 [] = {0xffffffff, 0x22222222, 0x66666666, 0xffffffff}; GGLTexture_t texture0 = {GL_TEXTURE_2D, GGL_PIXEL_FORMAT_RGBA_8888, 2, 2, 1, // width, height, levelCount - texels0, 1, 2, 1, 1 + texels0, GGL_CLAMP_TO_EDGE, GGL_MIRRORED_REPEAT, GGL_LINEAR, GGL_LINEAR }; // levels, wrapS, wrapT, minFilter, magFilter int sampler2dLoc = ggl->ShaderUniformLocation(program0, "sampler2d"); @@ -122,8 +122,18 @@ int cmain(int argc, char **argv) assert(0); } -// TODO DXL linear filtering needs to be fixed for texcoord outside of [0,1] - v0.attributes[2] = VECTOR4_CTR(0,0, 0.5f, 0.5f); + v0.attributes[2] = VECTOR4_CTR(0,0, 1.5f, 1.5f); + texture0.wrapS = GGL_REPEAT; + texture0.wrapT = GGL_REPEAT; + + sampler2dLoc = ggl->ShaderUniformLocation(program0, "sampler2d"); + if (0 <= sampler2dLoc) { + int samplerUnit = -1; + //ggl->ShaderUniformGetiv(ggl, program0, sampler2dLoc, &samplerUnit); + samplerUnit = sampler2dLoc; + ggl->SetSampler(ggl, samplerUnit, &texture0); + } + ggl->ShaderUse(ggl, program0); ggl->ProcessVertex(ggl, &v0, &vout0); const float filtered = (float)(0xff + 0x22 + 0x66 + 0xff) / (4 * 0xff); if (!ApproximatelyEqual(vout0.varyings[vTexColorIndex], @@ -149,7 +159,7 @@ int cmain(int argc, char **argv) ggl->ClearColor(ggl, 0.1f, 0.1f, 0.1f, 1.0f); ggl->ClearDepthf(ggl, 0.5f); -// TODO DXL scanline and fs test +// TODO DXL test scanline and fs free(colorSurface.data); colorSurface.data = NULL; diff --git a/test/egl.cpp b/test/egl.cpp index 5b55400..f31e30d 100644 --- a/test/egl.cpp +++ b/test/egl.cpp @@ -693,12 +693,6 @@ EGLBoolean egl_window_surface_v2_t::bindDrawSurface(ogles_context_t* gl) //puts("egl_window_surface_v2_t::bindDrawSurface"); //printf("\t width=%d height=%d stride=%d format=%d \n", buffer.width, buffer.height, buffer.stride, buffer.format); - /*for (unsigned int y = 0; y < buffer.height; y++) - { - unsigned int * line = (unsigned int *)bits + y * buffer.stride; - for (unsigned int x = 0; x < buffer.width; x++) - line[x] = 0xff00ff00; - }*/ gl->width = this->buffer->width; gl->height = this->buffer->height; gl->stride = this->buffer->stride; @@ -1926,15 +1920,7 @@ static struct S sp<Surface> surface; ~S() { - //surface->dispose(); - surface.~sp(); - puts("surface.~sp()"); - //surfaceControl->dispose(); - surfaceControl.~sp(); - puts("surfaceControl.~sp()"); client->dispose(); - client.~sp(); - puts("client.~sp()"); } } * s = NULL; static ANativeWindow * window; @@ -2014,15 +2000,10 @@ extern "C" void * PresentDrawingSurface() extern "C" void DisposeDrawingSurface() { - puts("DisposeDrawingSurface"); eglDestroySurface(display, drawSurface); - puts("eglDestroySurface"); eglDestroyContext(display, eglCtx); - puts("eglDestroyContext"); delete s; - puts("delete s"); s = NULL; - puts("DisposeDrawingSurface"); } diff --git a/test/main.cpp b/test/main.cpp index d51c6d9..5bcb1ca 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -78,7 +78,7 @@ gl_shader_program * init_shader() ggl->ShaderAttach(ggl, program, vertShader); ggl->ShaderAttach(ggl, program, fragShader); const char * infoLog = NULL; - GLboolean linkStatus = ggl->ShaderProgramLink(ggl, program, &infoLog); + GLboolean linkStatus = ggl->ShaderProgramLink(program, &infoLog); printf("finished linking, LinkStatus=%d \n %s \n", linkStatus, infoLog); @@ -108,7 +108,7 @@ void test_scan() frameSurface.format = GGL_PIXEL_FORMAT_RGBA_8888; frameSurface.width = width; frameSurface.height = height; - + GGLSurface depthSurface = {0}; depthSurface.width = width; depthSurface.height = height; @@ -145,8 +145,8 @@ void test_scan() #endif 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 + texture.wrapS = texture.wrapT = GGLTexture::GGL_REPEAT; // repeat = 0 fastest, clamp = 1, mirrored = 2 + texture.minFilter = texture.magFilter = GGLTexture::GGL_NEAREST; // nearest = 0, linear = 1 //texture.levelCount = GenerateMipmaps(texture.levels, texture.width, texture.height); // static unsigned texels [6] = {0xff0000ff, 0xff00ff00, 0xffff0000, @@ -171,7 +171,7 @@ void test_scan() ggl->SetBuffer(ggl, GL_COLOR_BUFFER_BIT, &frameSurface); - + ggl->EnableDisable(ggl, GL_DEPTH_TEST, true); ggl->DepthFunc(ggl, GL_LESS); @@ -195,7 +195,7 @@ void test_scan() int uRotMLoc = ggl->ShaderUniformLocation(program, "uRotM"); int uTLoc = ggl->ShaderUniformLocation(program, "t"); - GGLTexture cubeTexture = {GL_TEXTURE_CUBE_MAP, GGL_PIXEL_FORMAT_RGBA_8888, 1, 1, 1, NULL, 1, 2, 1, 1}; + GGLTexture cubeTexture = {GL_TEXTURE_CUBE_MAP, GGL_PIXEL_FORMAT_RGBA_8888, 1, 1, 1, NULL, GGLTexture::GGL_CLAMP_TO_EDGE, GGLTexture::GGL_MIRRORED_REPEAT, GGLTexture::GGL_LINEAR, GGLTexture::GGL_LINEAR}; unsigned cubeTextureSurface [6] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff00ffff, 0xffffff00, 0xffff00ff }; @@ -264,8 +264,8 @@ void test_scan() ggl->EnableDisable(ggl, GL_BLEND, false); ggl->EnableDisable(ggl, GL_DEPTH_TEST, true); ggl->EnableDisable(ggl, GL_STENCIL_TEST, false); - - + + ggl->DrawTriangle(ggl, &v0, &v0, &v0); // cause re-JIT to not mess up timing puts("\n -- begin rendering -- \n"); @@ -278,7 +278,7 @@ void test_scan() #endif for ( #ifdef __arm__ - unsigned i = 0; i <= 360; i++ + unsigned i = 0; i <= 90; i++ #else unsigned i = 0; i <= 10; i+= 1 #endif @@ -326,7 +326,7 @@ void test_scan() //ggl->BlendColor(ggl,(float)i / 10, (float) i / 15, (float)i < 20, 1); for (unsigned j = 0; j < sizeof(indices) / sizeof(*indices); j += 3) - ggl->DrawTriangle(ggl, vertices + indices[j], vertices + indices[j+1], vertices + indices[j+2]); + ggl->DrawTriangle(ggl, vertices + indices[j], vertices + indices[j+1], vertices + indices[j+2]); // including clear, depth, and other ops, direct ScanLine calls are 4% faster than DrawTriangle // X86 memcpy is 0.60ms vs 4.90ms for 480*800 fs texturing @@ -429,7 +429,7 @@ void test_scan() ggl->SetBuffer(ggl, GL_COLOR_BUFFER_BIT, NULL); #if defined __arm__ && DRAW_TO_SCREEN - //DisposeDrawingSurface(); + DisposeDrawingSurface(); #else free(frameSurface.data); #endif @@ -451,10 +451,150 @@ void test_scan() extern "C" int cmain(int,char**); +#include "llvm/LLVMContext.h" + +void GLContextDctr(); + +void contextless_test() +{ + static const char vsGLSL [] = + "uniform vec4 uVec4; \n" + "uniform sampler2D sampler2d; \n" + "attribute vec4 aPosition; \n" + "attribute vec4 aTexCoord; \n" + "varying vec4 vTexCoord; \n" + "varying vec4 vTexColor; \n" + "void main() { \n" + " gl_Position = aPosition; \n" + " vTexCoord = aTexCoord; \n" + " vTexColor = texture2D(sampler2d, aTexCoord.zw); \n" + " gl_PointSize = 432.0; \n" + "}"; + gl_shader * vs = GGLShaderCreate(GL_VERTEX_SHADER); + const char * infoLog = NULL; + if (!GGLShaderCompile(vs, vsGLSL, &infoLog)) { + printf("GGLShaderCompile vs failed:\n%s\n", infoLog); + assert(0); + } + static const char fsGLSL [] = + "uniform vec4 uVec4; \n" + "uniform sampler2D sampler2d; \n" + "varying vec4 vTexCoord; \n" + "varying vec4 vTexColor; \n" + "void main() { \n" + " gl_FragColor = texture2D(sampler2d, vTexCoord.zw); \n" + "}"; + gl_shader * fs = GGLShaderCreate(GL_FRAGMENT_SHADER); + if (!GGLShaderCompile(fs, fsGLSL, &infoLog)) { + printf("GGLShaderCompile fs failed:\n%s\n", infoLog); + assert(0); + } + gl_shader_program * prog = GGLShaderProgramCreate(); + unsigned glError = GL_NO_ERROR; + glError = GGLShaderAttach(prog, vs); + assert(GL_NO_ERROR == glError); + glError = GGLShaderAttach(prog, fs); + assert(GL_NO_ERROR == glError); + GGLShaderAttributeBind(prog, 4, "aPosition"); + GGLShaderAttributeBind(prog, 5, "aTexCoord"); + if (!GGLShaderProgramLink(prog, &infoLog)) { + printf("GGLShaderProgramLink failed:\n%s\n", infoLog); + assert(0); + } + llvm::LLVMContext * llvmCtx = new llvm::LLVMContext(); + GGLState gglState = {0}; + unsigned texels0 [] = {0xff10ffff, 0x22222222, 0x66666666, 0xffffffff}; + GGLTexture_t texture0 = {GL_TEXTURE_2D, GGL_PIXEL_FORMAT_RGBA_8888, + 2, 2, 1, // width, height, levelCount + texels0, GGLTexture::GGL_CLAMP_TO_EDGE, GGLTexture::GGL_CLAMP_TO_EDGE, + GGLTexture::GGL_NEAREST, GGLTexture::GGL_NEAREST + }; + gglState.textureState.textures[0] = texture0; + gglState.textureState.textureData[0] = gglState.textureState.textures[0].levels; + gglState.textureState.textureDimensions[0 * 2 + 0] = gglState.textureState.textures[0].width; + gglState.textureState.textureDimensions[0 * 2 + 1] = gglState.textureState.textures[0].height; + GGLShaderUse(llvmCtx, &gglState, prog); + + VertexInput input = {0, 0, 0, 0, Vector4(0,0,0,1), Vector4(0,0,0,0)}; + VertexOutput output = {0}; + GGLProcessVertex(prog, &input, &output, NULL); + int vTexColor = -1; + GGLShaderVaryingLocation(prog, "vTexColor", &vTexColor); + if (vTexColor >= 0) { + if (((Vector4 *)&output)[vTexColor] != Vector4(1,1,16/255.0f,1)) { + puts("((Vector4 *)&output)[vTexColor] != Vector4(1,1,0,1)"); + assert(0); + } + } else { + puts("vTexColor < 0"); + assert(0); + } + + static const char fsGLSL1 [] = + "uniform vec4 uVec4; \n" + "uniform sampler2D sampler2d; \n" + "varying vec4 vTexCoord; \n" + "varying vec4 vTexColor; \n" + "void main() { \n" + " gl_FragColor = vTexColor; \n" + "}"; + gl_shader * fs1 = GGLShaderCreate(GL_FRAGMENT_SHADER); + if (!GGLShaderCompile(fs1, fsGLSL1, &infoLog)) { + printf("GGLShaderCompile fs failed:\n%s\n", infoLog); + assert(0); + } + gl_shader_program * prog1 = GGLShaderProgramCreate(); + glError = GGLShaderAttach(prog1, vs); + assert(GL_NO_ERROR == glError); + glError = GGLShaderAttach(prog1, fs1); + assert(GL_NO_ERROR == glError); + GGLShaderAttributeBind(prog1, 1, "aPosition"); + GGLShaderAttributeBind(prog1, 2, "aTexCoord"); + if (!GGLShaderProgramLink(prog1, &infoLog)) { + printf("GGLShaderProgramLink failed:\n%s\n", infoLog); + assert(0); + } + + GGLShaderUse(llvmCtx, &gglState, prog1); + VertexInput input1 = {0, Vector4(1,1,0,1), Vector4(1,1,0,0)}; + VertexOutput output1 = {0}; + GGLProcessVertex(prog1, &input1, &output1, NULL); + int vTexCoord = -1; + assert(2 == GGLShaderAttributeLocation(prog1, "aTexCoord")); + GGLShaderVaryingLocation(prog1, "vTexCoord", &vTexCoord); + if (vTexCoord >= 0) { + if (((Vector4 *)&output1)[vTexCoord] != input1.attributes[2]) { + puts("((Vector4 *)&output1)[vTexCoord] != input1.attributes[1]"); + assert(0); + } + } else { + puts("vTexCoord < 0"); + assert(0); + } + + puts("***\n finished contextless_test \n***"); + + GGLShaderProgramDelete(prog); + GGLShaderProgramDelete(prog1); + + GLContextDctr(); +} + +extern "C" void hieralloc_report(const void *, FILE *); +extern "C" void hieralloc_report_brief(const void *, FILE *); + int main (int argc, char * const argv[]) { cmain(0,NULL); + + contextless_test(); + +// contextless_test(); + test_scan(); + +// hieralloc_report(NULL, stdout); + hieralloc_report_brief(NULL, stdout); puts("mesa done"); return 0; } diff --git a/test/mesa.project b/test/mesa.project index f88f153..d0ecf6b 100644 --- a/test/mesa.project +++ b/test/mesa.project @@ -15,12 +15,17 @@ <File Name="m_matrix.c"/> <File Name="m_matrix.h"/> </VirtualDirectory> + <Dependencies Name="Release"/> + <Dependencies Name="Debug"> + <Project Name="libMesa"/> + </Dependencies> <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=""> + <Compiler Options="-D__STDC_LIMIT_MACROS;-D__STDC_CONSTANT_MACROS;-m32 -march=i686;-DDEBUG;-UNDEBUG;-O0;-g" Required="yes" PreCompiledHeader=""> <IncludePath Value="."/> <IncludePath Value="../include/"/> <IncludePath Value="../../../base/opengl/include"/> + <IncludePath Value="../../../../external/llvm/include"/> </Compiler> <Linker Options="-m32 -lstdc++ -ldl -lpthread -lbcc" Required="yes"> <LibraryPath Value="../Debug"/> @@ -87,7 +92,4 @@ <ResourceCompiler Options=""/> </GlobalSettings> </Settings> - <Dependencies Name="Debug"> - <Project Name="libMesa"/> - </Dependencies> </CodeLite_Project> |