static bool test_tes_layout(const char *const layout1, const char *const layout2, const char *const layout_name) { unsigned int prog; bool link_status; sprintf(tes_source1, tes_source_template, layout1, 1); sprintf(tes_source2, tes_source_template, layout2, 2); prog = piglit_build_simple_program_unlinked_multiple_shaders( GL_VERTEX_SHADER, vs_source, GL_TESS_CONTROL_SHADER, tcs_source_main, GL_TESS_EVALUATION_SHADER, tes_source_main_no_pm, GL_TESS_EVALUATION_SHADER, tes_source1, GL_TESS_EVALUATION_SHADER, tes_source2, GL_FRAGMENT_SHADER, fs_source, 0); glLinkProgram(prog); link_status = piglit_link_check_status_quiet(prog); glDeleteProgram(prog); if (link_status && (layout1 != layout2)) { fprintf(stderr, "Program with different %s " "specifications linked succesfully\n", layout_name); return false; } if (!link_status && (layout1 == layout2)) { fprintf(stderr, "Program with identical %s " "specifications failed to link\n", layout_name); return false; } return true; }
static GLuint build_shaders(const char *vs_prefix, int vs_blocks, const char *fs_prefix, int fs_blocks) { char *vs_source, *fs_source; GLuint vs, fs, prog; vs_source = get_shader(GL_VERTEX_SHADER, vs_prefix, vs_blocks); fs_source = get_shader(GL_FRAGMENT_SHADER, fs_prefix, fs_blocks); vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source); fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source); prog = glCreateProgram(); glAttachShader(prog, vs); glAttachShader(prog, fs); glLinkProgram(prog); if (!piglit_link_check_status_quiet(prog)) { glDeleteProgram(prog); prog = 0; } glDeleteShader(vs); glDeleteShader(fs); return prog; }
void piglit_init(int argc, char **argv) { GLint ok; GLuint prog; GLuint vs; if (piglit_get_gl_version() < 20) { printf("Requires OpenGL 2.0\n"); piglit_report_result(PIGLIT_SKIP); } vs = piglit_compile_shader_text(GL_VERTEX_SHADER, bad_vs_text); prog = glCreateProgram(); glAttachShader(prog, vs); glLinkProgram(prog); glDeleteShader(vs); ok = piglit_link_check_status_quiet(prog); if (ok) { fprintf(stderr, "Linking with unresolved symbol succeeded when it " "should have failed.\n"); piglit_report_result(PIGLIT_FAIL); } piglit_report_result(PIGLIT_PASS); }
void piglit_init(int argc, char **argv) { const char *glsl_version_string; float glsl_version; GLint ok; GLuint prog; GLuint vs; GLuint fs; piglit_require_GLSL(); glsl_version_string = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION); glsl_version = (glsl_version_string == NULL) ? 0.0 : strtod(glsl_version_string, NULL); if (glsl_version <= 1.299999) { printf("Test requires GLSL version >= 1.3. " "Actual version is %.1f.\n", glsl_version); piglit_report_result(PIGLIT_SKIP); } vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert); fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag); prog = glCreateProgram(); glAttachShader(prog, vs); glAttachShader(prog, fs); glLinkProgram(prog); glDeleteShader(vs); glDeleteShader(fs); ok = piglit_link_check_status_quiet(prog); if (ok) { fprintf(stderr, "Linking with a shader that accesses both " "gl_ClipDistance and gl_ClipVertex succeeded when it " "should have failed.\n"); piglit_report_result(PIGLIT_FAIL); } piglit_report_result(PIGLIT_PASS); }
void piglit_init(int argc, char **argv) { GLint vert; GLint prog; GLboolean ok; piglit_require_gl_version(20); piglit_require_extension("GL_ARB_explicit_attrib_location"); vert = piglit_compile_shader(GL_VERTEX_SHADER, "shaders/glsl-explicit-location-04.vert"); prog = glCreateProgram(); glAttachShader(prog, vert); glLinkProgram(prog); ok = piglit_link_check_status_quiet(prog); if (ok) fprintf(stderr, "Linking with invalid explicit attribute location " "succeeded when it should have failed.\n"); piglit_report_result(!ok ? PIGLIT_PASS : PIGLIT_FAIL); }
void piglit_init(int argc, char **argv) { GLint program; bool expect = false; bool result; unsigned i; const char *invalid_file = NULL; piglit_require_gl_version(20); piglit_require_GLSL(); program = glCreateProgram(); for (i = 1; i < argc; i++) { size_t len; GLint shader; GLenum target; if (strcmp(argv[i], "pass") == 0) { expect = true; break; } if (strcmp(argv[i], "fail") == 0) { expect = false; break; } /* Expect that the name is at least one character plus * ".vert", ".geom", or ".frag" */ len = strlen(argv[i]); if (len < 6) { invalid_file = argv[i]; break; } if (strcmp(argv[i] + len - 5, ".vert") == 0) { target = GL_VERTEX_SHADER; } else if (strcmp(argv[i] + len - 5, ".geom") == 0) { target = GL_GEOMETRY_SHADER; if (piglit_get_gl_version() < 32 && !piglit_is_extension_supported("GL_ARB_geometry_shader4")) { printf("Requires geometry shaders.\n"); piglit_report_result(PIGLIT_SKIP); } } else if (strcmp(argv[i] + len - 5, ".frag") == 0) { target = GL_FRAGMENT_SHADER; } else { invalid_file = argv[i]; break; } shader = piglit_compile_shader(target, argv[i]); glAttachShader(program, shader); glDeleteShader(shader); } /* The loop above will break when an option of either 'pass' or 'fail' * is encountered. If this happens at the last commandline argument, * the loop counter will be (argc-1). Any other value is an error. */ if (i != (argc - 1)) { fprintf(stderr, "Last command line option must be either " "\"pass\" or \"fail\".\n"); piglit_report_result(PIGLIT_FAIL); } if (invalid_file != NULL) { fprintf(stderr, "Invalid shader file name \"%s\".\n", invalid_file); piglit_report_result(PIGLIT_FAIL); } glLinkProgram(program); result = piglit_link_check_status_quiet(program); if (result != expect) fprintf(stderr, "Program should have %s linking, but " "it was (incorrectly) %s.\n", expect ? "succeeded" : "failed", expect ? "unsuccesful" : "succesful"); piglit_report_result((result == expect) ? PIGLIT_PASS : PIGLIT_FAIL); }
enum piglit_result piglit_display(void) { const char *vs_ssbo_template = "#version 130\n" "#extension GL_ARB_shader_storage_buffer_object : enable\n" "#extension GL_ARB_uniform_buffer_object : enable\n" "\n" "varying vec4 vary;" "in vec4 piglit_vertex;\n" "\n" "layout(std140) buffer ssbo {\n" " vec4 v[%d];\n" "};\n" "uniform int i;\n" "\n" "void main() {\n" " gl_Position = piglit_vertex;\n" " vary = v[i];\n" "}\n"; const char *fs_template = "#version 130\n" "#extension GL_ARB_shader_storage_buffer_object : enable\n" "\n" "varying vec4 vary;" "\n" "void main() {\n" " gl_FragColor = vary;\n" "}\n"; const char *vs_template = "#version 130\n" "#extension GL_ARB_shader_storage_buffer_object : enable\n" "in vec4 piglit_vertex;\n" "\n" "void main() {\n" " gl_Position = piglit_vertex;\n" "}\n"; const char *fs_ssbo_template = "#version 130\n" "#extension GL_ARB_shader_storage_buffer_object : enable\n" "#extension GL_ARB_uniform_buffer_object : enable\n" "\n" "layout(std140) buffer ssbo {\n" " vec4 v[%d];\n" "};\n" "uniform int i;\n" "\n" "void main() {\n" " gl_FragColor = v[i];\n" "}\n"; char *vs_source, *fs_source; GLint max_size, vec4s, i_location; GLuint vs, fs, prog, bo; GLenum target; float *data; size_t size; bool pass = true; bool link_should_fail; const float green[4] = { 0, 1, 0, 0 }; int test_index; piglit_require_extension("GL_ARB_shader_storage_buffer_object"); piglit_require_extension("GL_ARB_uniform_buffer_object"); glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_size); printf("Max shader storage block size: %d\n", max_size); vec4s = max_size / 4 / 4; switch (mode) { case VS: target = GL_VERTEX_SHADER; link_should_fail = false; test_index = vec4s - 1; break; case VS_EXCEED: target = GL_VERTEX_SHADER; link_should_fail = true; vec4s++; test_index = vec4s - 2; break; case FS: target = GL_FRAGMENT_SHADER; link_should_fail = false; test_index = vec4s - 1; break; case FS_EXCEED: target = GL_FRAGMENT_SHADER; link_should_fail = true; vec4s++; test_index = vec4s - 2; break; default: assert(false); target = GL_NONE; link_should_fail = false; } switch (target) { case GL_VERTEX_SHADER: (void)!asprintf(&vs_source, vs_ssbo_template, vec4s); (void)!asprintf(&fs_source, "%s", fs_template); printf("Testing VS with shader storage block vec4 v[%d]\n", vec4s); break; case GL_FRAGMENT_SHADER: (void)!asprintf(&vs_source, "%s", vs_template); (void)!asprintf(&fs_source, fs_ssbo_template, vec4s); printf("Testing FS with shader storage block vec4 v[%d]\n", vec4s); break; default: piglit_report_result(PIGLIT_FAIL); } vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source); fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source); prog = glCreateProgram(); glAttachShader(prog, vs); glAttachShader(prog, fs); glLinkProgram(prog); if (link_should_fail) { if (!piglit_link_check_status_quiet(prog)) { printf("Failed to link with shader storage block vec4 " "v[%d]\n", vec4s); piglit_report_result(PIGLIT_PASS); } } else { if (!piglit_link_check_status_quiet(prog)) { fprintf(stderr, "Failed to link with shader storage block vec4 " "v[%d]\n", vec4s); return PIGLIT_FAIL; } } size = vec4s * 4 * sizeof(float); glGenBuffers(1, &bo); glBindBuffer(GL_SHADER_STORAGE_BUFFER, bo); glBufferData(GL_SHADER_STORAGE_BUFFER, size, NULL, GL_DYNAMIC_DRAW); data = glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_WRITE); memset(data, 0, size); /* The whole shader storage buffer will be zeros, except for the * entry at v[test_index] which will be green. */ data[test_index * 4 + 0] = green[0]; data[test_index * 4 + 1] = green[1]; data[test_index * 4 + 2] = green[2]; data[test_index * 4 + 3] = green[3]; glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); glUseProgram(prog); i_location = glGetUniformLocation(prog, "i"); glUniform1i(i_location, test_index); glShaderStorageBlockBinding(prog, 0, 0); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, bo); piglit_draw_rect(-1, -1, 2, 2); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green); glDeleteProgram(prog); piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
static bool draw(int num_varyings) { int data_varying; float vertex[4][4] = { {0.0, 0.0, 0.0, 1.0}, {0.0, 0.0, 0.0, 1.0}, {0.0, 0.0, 0.0, 1.0}, {0.0, 0.0, 0.0, 1.0} }; float green[4][4] = { {0.0, 1.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0} }; float red[4][4] = { {1.0, 0.0, 0.0, 0.0}, {1.0, 0.0, 0.0, 0.0}, {1.0, 0.0, 0.0, 0.0}, {1.0, 0.0, 0.0, 0.0} }; glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), vertex); glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), green); glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), red); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); for (data_varying = 0; data_varying < num_varyings; data_varying++) { GLuint prog, vs, fs; GLint loc; float x, y; vs = get_vs(num_varyings, data_varying); fs = get_fs(num_varyings, data_varying); prog = glCreateProgram(); glAttachShader(prog, vs); glAttachShader(prog, fs); glBindAttribLocation(prog, 0, "vertex"); glBindAttribLocation(prog, 1, "green"); glBindAttribLocation(prog, 2, "red"); glLinkProgram(prog); if (!piglit_link_check_status_quiet(prog)) { if (num_varyings > max_varyings) { printf("Failed to link with %d out of %d " "varyings used\n", num_varyings, max_varyings); return false; } else { piglit_report_result(PIGLIT_FAIL); } } glUseProgram(prog); loc = glGetUniformLocation(prog, "zero"); if (loc != -1) /* not used for num_varyings == 1 */ glUniform1f(loc, 0.0); loc = glGetUniformLocation(prog, "one"); assert(loc != -1); /* should always be used */ glUniform1f(loc, 1.0); x = coord_from_index(data_varying); y = coord_from_index(num_varyings - 1); vertex[0][0] = x; vertex[0][1] = y; vertex[1][0] = x + 2; vertex[1][1] = y; vertex[2][0] = x; vertex[2][1] = y + 2; vertex[3][0] = x + 2; vertex[3][1] = y + 2; glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDeleteShader(vs); glDeleteShader(fs); glDeleteProgram(prog); } return true; }
void piglit_init(int argc, char **argv) { enum piglit_result result = PIGLIT_PASS; GLenum err; GLint ok; GLuint prog; GLuint vs; if (piglit_get_gl_version() < 20) { printf("Requires OpenGL 2.0\n"); piglit_report_result(PIGLIT_SKIP); } piglit_require_extension("GL_EXT_separate_shader_objects"); printf("Trying shader with unresolved external symbol...\n"); vs = piglit_compile_shader_text(GL_VERTEX_SHADER, bad_vs_text); prog = glCreateProgram(); glAttachShader(prog, vs); glLinkProgram(prog); glDeleteShader(vs); ok = piglit_link_check_status_quiet(prog); if (ok) { fprintf(stderr, "Linking with unresolved symbol succeeded when it " "should have failed.\n"); piglit_report_result(PIGLIT_FAIL); } /* There shouldn't be any GL errors, but clear them all just to be * sure. */ while (glGetError() != 0) /* empty */ ; /* The specified program is not linked. This should generate * the error GL_INVALID_OPERATION. */ glActiveProgramEXT(prog); err = glGetError(); if (err != GL_INVALID_OPERATION) { printf("Unexpected OpenGL error state 0x%04x for " "glActiveProgramEXT called with\n" "an unlinked shader program (expected 0x%04x).\n", err, GL_INVALID_OPERATION); result = PIGLIT_FAIL; } glDeleteProgram(prog); glUseProgram(0); /* Try again with a shader program that could be linked but wasn't. */ printf("Trying unlinked, valid shader...\n"); vs = piglit_compile_shader_text(GL_VERTEX_SHADER, good_vs_text); prog = glCreateProgram(); glAttachShader(prog, vs); glDeleteShader(vs); /* There shouldn't be any GL errors, but clear them all just to be * sure. */ while (glGetError() != 0) /* empty */ ; /* The specified program is not linked. This should generate * the error GL_INVALID_OPERATION. */ glActiveProgramEXT(prog); err = glGetError(); if (err != GL_INVALID_OPERATION) { printf("Unexpected OpenGL error state 0x%04x for " "glActiveProgramEXT called with\n" "an unlinked shader program (expected 0x%04x).\n", err, GL_INVALID_OPERATION); result = PIGLIT_FAIL; } glDeleteProgram(prog); glUseProgram(0); piglit_report_result(result); }
void piglit_init(int argc, char **argv) { bool pass = true; GLuint vs = 0, gs = 0; int i; prog = glCreateProgram(); vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext); gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gstext); glAttachShader(prog, vs); glAttachShader(prog, gs); /* check that invalid_varying_names fail to link */ for (i = 0; i < ARRAY_SIZE(invalid_varying_names); i++) { glTransformFeedbackVaryings(prog, 1, &invalid_varying_names[i], GL_INTERLEAVED_ATTRIBS); glLinkProgram(prog); if (piglit_link_check_status_quiet(prog)) { printf("%s is not valid but it was allowed.\n", invalid_varying_names[i]); pass = false; } } /* check that valid_varying_names link properly */ glTransformFeedbackVaryings(prog, ARRAY_SIZE(valid_varying_names), valid_varying_names, GL_INTERLEAVED_ATTRIBS); glLinkProgram(prog); if (!piglit_link_check_status(prog)) { glDeleteProgram(prog); printf("Transform feedback varyings failed to link properly" " with valid names.\n"); piglit_report_result(PIGLIT_FAIL); } glUseProgram(prog); for (i = 0; i < ARRAY_SIZE(valid_varying_names); i++) { char varName[50]; GLsizei nameLength = 0, varSize = 0; GLenum varType = GL_NONE; glGetTransformFeedbackVarying( prog, i, sizeof(varName), &nameLength, &varSize, &varType, varName); printf("Name: %s\t\tType: %s\n", varName, piglit_get_gl_enum_name(varType)); } pass = piglit_check_gl_error(GL_NO_ERROR) && pass; piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }