Commit 30b3cd5c authored by Ian Romanick's avatar Ian Romanick

Tests and framework for exercising the assembly shader compiler

parent 54562c7b
...@@ -5,6 +5,7 @@ add_subdirectory (fbo) ...@@ -5,6 +5,7 @@ add_subdirectory (fbo)
add_subdirectory (general) add_subdirectory (general)
add_subdirectory (glean) add_subdirectory (glean)
add_subdirectory (glslparsertest) add_subdirectory (glslparsertest)
add_subdirectory (asmparsertest)
add_subdirectory (mesa) add_subdirectory (mesa)
add_subdirectory (shaders) add_subdirectory (shaders)
add_subdirectory (texturing) add_subdirectory (texturing)
This diff is collapsed.
include_directories(
${OPENGL_INCLUDE_PATH}
${GLUT_INCLUDE_DIR}
${piglit_SOURCE_DIR}/tests/util
${GLEW_INCLUDE_DIR}
)
link_directories (
${piglit_SOURCE_DIR}/tests/util
)
link_libraries (
piglitutil
${OPENGL_gl_LIBRARY}
${GLUT_glut_LIBRARY}
${GLEW_glew_LIBRARY}
)
add_executable (asmparsertest asmparsertest.c)
/*
* Copyright © 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 <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <GL/glew.h>
#include <GL/glut.h>
#include "piglit-util.h"
#ifndef TRUE
#define FALSE 0
#define TRUE (!FALSE)
#endif
int automatic = FALSE;
void
compile(const char *filename, GLenum target, int use_ARB)
{
GLenum err;
GLuint prognum;
char *buf;
char *ptr;
unsigned sz;
int expected_fail;
if (!automatic) {
printf("%s:\n", filename);
}
buf = piglit_load_text_file(filename, &sz);
if (buf == NULL) {
piglit_report_result(PIGLIT_FAILURE);
}
/* Scan the program source looking for two different things. First,
* look for comments of the form '# FAIL'. This signals that the
* program is expected to fail compilation. Second, look for comments
* of the form '# REQUIRE GL_XXX_xxxx_xxxx'. This signals that the
* program will only compile if some OpenGL extension is available.
*/
expected_fail = (strstr(buf, "# FAIL") != NULL);
ptr = buf;
while (ptr != NULL) {
ptr = strstr(ptr, "# REQUIRE ");
if (ptr != NULL) {
char extension[128];
unsigned i;
ptr += strlen("# REQUIRE ");
for (i = 0; !isspace(ptr[i]) && (ptr[i] != '\0'); i++) {
extension[i] = ptr[i];
}
extension[i] = '\0';
if (!glutExtensionSupported(extension)) {
piglit_report_result(PIGLIT_SKIP);
free(buf);
return;
}
}
}
/* The use_ARB flag is used instead of the target because
* GL_VERTEX_PROGRAM_ARB and GL_VERTEX_PROGRAM_NV have the same value.
*/
if (use_ARB) {
glEnable(target);
glGenProgramsARB(1, &prognum);
glBindProgramARB(target, prognum);
glProgramStringARB(target, GL_PROGRAM_FORMAT_ASCII_ARB, sz,
(const GLubyte *) buf);
} else {
glGenProgramsNV(1, &prognum);
glBindProgramNV(target, prognum);
glLoadProgramNV(target, prognum, sz, (const GLubyte *) buf);
}
err = glGetError();
if (err != GL_NO_ERROR) {
GLint errorpos;
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
if (!automatic) {
printf("glGetError = 0x%04x\n", err);
printf("errorpos: %d\n", errorpos);
printf("%s\n",
(char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
}
}
free(buf);
if ((err == GL_NO_ERROR) != (expected_fail == FALSE)) {
piglit_report_result(PIGLIT_FAILURE);
}
}
int
main(int argc, char **argv)
{
GLenum target;
unsigned i;
int use_ARB;
glutInit(&argc, argv);
glutInitWindowPosition(0, 0);
glutInitWindowSize(250, 250);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH);
glutCreateWindow("assembler test");
glewInit();
i = 1;
if (((argc - 1) >= 1) && (strcmp(argv[i], "-auto") == 0)) {
automatic = TRUE;
i++;
}
if ((argc - i) < 2) {
piglit_report_result(PIGLIT_FAILURE);
}
use_ARB = 1;
if (strcmp(argv[1], "ARBvp1.0") == 0) {
target = GL_VERTEX_PROGRAM_ARB;
piglit_require_extension("GL_ARB_vertex_program");
} else if (strcmp(argv[1], "ARBfp1.0") == 0) {
target = GL_FRAGMENT_PROGRAM_ARB;
piglit_require_extension("GL_ARB_fragment_program");
} else if (strcmp(argv[1], "NVvp1.0") == 0) {
target = GL_VERTEX_PROGRAM_NV;
piglit_require_extension("GL_NV_vertex_program");
use_ARB = 0;
} else if (strcmp(argv[1], "NVfp1.0") == 0) {
target = GL_FRAGMENT_PROGRAM_NV;
piglit_require_extension("GL_NV_fragment_program");
use_ARB = 0;
} else {
piglit_report_result(PIGLIT_FAILURE);
}
for (i = 2; i < argc; i++) {
compile(argv[i], target, use_ARB);
}
piglit_report_result(PIGLIT_SUCCESS);
return 0;
}
!!ARBfp1.0
TEMP R0;
ADD R0, {0.5}.r, fragment.color;
ABS result.color, R0;
END
!!ARBfp1.0
OPTION ARB_fog_linear;
END
!!ARBfp1.0
OPTION ARB_fog_exp;
END
!!ARBfp1.0
OPTION ARB_fog_exp2;
END
!!ARBfp1.0
# FAIL
OPTION ARB_fog_exp;
OPTION ARB_fog_exp2;
END
!!ARBfp1.0
OPTION ARB_precision_hint_fastest;
END
!!ARBfp1.0
OPTION ARB_precision_hint_nicest;
END
!!ARBfp1.0
# FAIL
OPTION ARB_precision_hint_nicest;
OPTION ARB_precision_hint_nicest;
END
!!ARBfp1.0
# FAIL
OPTION ARB_precision_hint_fastest;
OPTION ARB_precision_hint_nicest;
END
!!ARBfp1.0
# FAIL
OPTION ARB_precision_hint_fastest;
OPTION ARB_precision_hint_fastest;
END
!!ARBfp1.0
TEMP R0;
MOV result.color, R0;
END
!!ARBfp1.0
# FAIL
TEMP R0;
MOV result.position, R0;
END
!!ARBfp1.0
# FAIL
TEMP R0;
MOV result.fogcoord, R0;
END
!!ARBfp1.0
# FAIL
TEMP R0;
MOV result.pointsize, R0;
END
!!ARBfp1.0
# FAIL
TEMP R0;
MOV result.texcoord, R0;
END
!!ARBfp1.0
# FAIL
TEMP R0;
MOV result.texcoord[0], R0;
END
!!ARBfp1.0
# FAIL
TEMP R0;
MOV result.texcoord[1], R0;
END
!!ARBfp1.0
# FAIL
TEMP R0;
MOV result.color.front, R0;
END
!!ARBfp1.0
# FAIL
TEMP R0;
MOV result.color.back, R0;
END
!!ARBfp1.0
# FAIL
TEMP R0;
MOV result.color.primary, R0;
END
!!ARBfp1.0
# FAIL
TEMP R0;
MOV result.color.secondary, R0;
END
!!ARBfp1.0
TEMP R0, R1;
SIN R0, R1.x;
SIN R0, R1.y;
SIN R0, R1.z;
SIN R0, R1.w;
COS R0, R1.x;
COS R0, R1.y;
COS R0, R1.z;
COS R0, R1.w;
SCS R0, R1.x;
SCS R0, R1.y;
SCS R0, R1.z;
SCS R0, R1.w;
END
!!ARBfp1.0
# FAIL
TEMP R0, R1;
SIN R0, R1;
END
!!ARBfp1.0
# FAIL
TEMP R0, R1;
COS R0, R1;
END
!!ARBfp1.0
# FAIL
TEMP R0, R1;
SCS R0, R1;
END
!!ARBfp1.0
MOV result.color, fragment.color.xxzx;
END
!!ARBfp1.0
SWZ result.color, fragment.color, 1,x,y,z;
END
!!ARBfp1.0
TEMP R0;
SWZ R0, fragment.color, x, y, z, w;
END
!!ARBfp1.0
# FAIL
# invalid extended swizzle selector
TEMP R0;
SWZ R0, fragment.color, xcellent, y, z, w;
END
!!ARBfp1.0
# FAIL
# invalid extended swizzle selector
TEMP R0;
SWZ R0, fragment.color, 0, 1, 2, -x;
END
!!ARBvp1.0
TEMP R0;
ADD R0, {0.5}.x, vertex.color;
ADD R0, vertex.position, vertex.color;
ABS result.color, R0;
MOV result.position, vertex.position;
END
!!ARBvp1.0
TEMP R0;
ADD R0, vertex.color, vertex.color;
ADD result.color, R0, R0;
MOV result.position, vertex.position;
END
!!ARBvp1.0
# Should compile successfully
ADDRESS A0;
TEMP R0;
ARL A0.x, R0.x;
END
!!ARBvp1.0
# FAIL
# due to variable redeclaration
ADDRESS A0;
TEMP A0, R0;
ARL A0.x, R0.x;
END
!!ARBvp1.0
# FAIL
# invalid address writemask
ADDRESS A0;
TEMP R0;
ARL A0.y, R0.x;
END
!!ARBvp1.0
# FAIL
# Invalid array index
ADDRESS A0;
TEMP R0, R1;
PARAM M[] = { program.local[ 0 .. 3 ] };
ARL A0.x, R0.x;
MOV R0, M[ R1.x ];
END
!!ARBvp1.0
# FAIL
# A1 undeclared
ADDRESS A0;
TEMP R0;
PARAM M[] = { program.local[ 0 .. 3 ] };
ARL A0.x, R0.x;
MOV R0, M[ A1.x ];
END
!!ARBvp1.0
# FAIL
# constant array index offset too large
ADDRESS A0;
TEMP R0;
PARAM M[] = { program.local[ 0 .. 3 ] };
ARL A0.x, R0.x;
MOV R0, M[ A0.x - 66 ];
END
!!ARBvp1.0
# FAIL
# invalid address component selector
ADDRESS A0;
TEMP R0;
PARAM M[] = { program.local[ 0 .. 3 ] };
ARL A0.x, R0.x;
MOV R0, M[ A0 ];
END
!!ARBvp1.0
# FAIL
# invalid address component selector
ADDRESS A0;
TEMP R0;
PARAM M[] = { program.local[ 0 .. 3 ] };
ARL A0.x, R0.x;
MOV R0, M[ A0.y ];
END
!!ARBvp1.0
# FAIL
# invalid address component selector
ADDRESS A0;
TEMP R0;
PARAM M[] = { program.local[ 0 .. 3 ] };
ARL A0.x, R0.x;
MOV R0, M[ A0.xxxx ];
END
!!ARBvp1.0
# FAIL
# invalid address write mask
ADDRESS A0;
TEMP R0;
PARAM M[] = { program.local[ 0 .. 3 ] };
ARL A0.y, R0.x;
MOV R0, M[ A0.x ];
END
!!ARBvp1.0
# FAIL
# Out of bounds array access
TEMP R0;
PARAM M[] = { program.local[ 0 .. 3 ] };
# These lines should be okay.
MOV R0, M[4];
END
!!ARBvp1.0
TEMP R0;
ALIAS R0p = R0;
END
!!ARBvp1.0
# FAIL
# R1 undefined
TEMP R0;
ALIAS R1p = R1;
END
!!ARBvp1.0
TEMP r0 ;
ADDRESS a0 ;
MOV r0, state.material.ambient ;
MOV r0, state.material.diffuse ;
MOV r0, state.material.specular ;
MOV r0, state.material.emission ;
MOV r0, state.material.shininess ;
MOV r0, state.material.front.ambient ;
MOV r0, state.material.front.diffuse ;
MOV r0, state.material.front.specular ;
MOV r0, state.material.front.emission ;
MOV r0, state.material.front.shininess ;
MOV r0, state.material.back.ambient ;
MOV r0, state.material.back.diffuse ;
MOV r0, state.material.back.specular ;
MOV r0, state.material.back.emission ;
MOV r0, state.material.back.shininess ;
MOV r0, state.light[0].ambient ;
MOV r0, state.light[0].diffuse ;
MOV r0, state.light[0].specular ;
MOV r0, state.light[0].position ;
MOV r0, state.light[0].attenuation ;
MOV r0, state.light[0].spot.direction ;
MOV r0, state.light[0].half ;
MOV r0, state.lightmodel.ambient ;
MOV r0, state.lightmodel.scenecolor ;
MOV r0, state.lightmodel.front.scenecolor ;
MOV r0, state.lightmodel.back.scenecolor ;
# Do state.lightprod[n] here.
MOV r0, state.lightprod[0].ambient ;
MOV r0, state.lightprod[0].diffuse ;
MOV r0, state.lightprod[0].specular ;
MOV r0, state.lightprod[0].front.ambient ;
MOV r0, state.lightprod[0].front.diffuse ;
MOV r0, state.lightprod[0].front.specular ;
MOV r0, state.lightprod[0].back.ambient ;
MOV r0, state.lightprod[0].back.diffuse ;
MOV r0, state.lightprod[0].back.specular ;
# Do state.texture[n].texgen here.
MOV r0, state.fog.color ;
MOV r0, state.fog.params ;
# Do state.clip[n] here.
MOV r0, state.point.size ;
MOV r0, state.point.attenuation ;
# Do state.matrix here.
END
!!ARBvp1.0
# FAIL
# Invalid state
MOV r0, state;
END