void piglit_init(int argc, char **argv) { bool pass = true; GLuint pipe; GLuint vs_prog; GLuint active_prog; GLuint unlinked_prog; GLuint shader; unsigned glsl_version; char *source; piglit_require_extension("GL_ARB_separate_shader_objects"); glsl_version = pick_a_glsl_version(); glGenProgramPipelines(1, &pipe); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glBindProgramPipeline(pipe); (void)!asprintf(&source, vs_code_template, glsl_version); vs_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, (const GLchar *const *) &source); pass = piglit_link_check_status(vs_prog) && pass; /* First, make a valid program active. */ glActiveShaderProgram(pipe, vs_prog); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; /* Next, try to make an invalid program active and verify that the * correct error is generated. Also make sure the old program is * still active. * * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of * the OpenGL 4.4 spec says: * * "An INVALID_VALUE error is generated if program is not zero and * is not the name of either a program or shader object." */ glActiveShaderProgram(pipe, ~vs_prog); pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass; glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog); if (active_prog != vs_prog) { printf("glActiveShaderProgram with an invalid program name " "changed the active program state.\n"); pass = false; } else { glActiveShaderProgram(pipe, vs_prog); } /* Try the same thing with a valid shader object (that is not part of * a linked program). Verify that the correct error is generated, and * make sure the old program is still active. * * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of * the OpenGL 4.4 spec says: * * "An INVALID_OPERATION error is generated if program is the name * of a shader object." */ shader = piglit_compile_shader_text(GL_VERTEX_SHADER, source); glActiveShaderProgram(pipe, shader); pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog); if (active_prog != vs_prog) { printf("glActiveShaderProgram with a shader object " "changed the active program state.\n"); pass = false; } else { glActiveShaderProgram(pipe, vs_prog); } /* Finally, try the same thing with a valid program that is not * linked. Verify that the correct error is generated, and make sure * the old program is still active. * * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of * the OpenGL 4.4 spec says: * * "An INVALID_OPERATION error is generated if program is not zero * and has not been linked, or was last linked unsuccessfully." */ unlinked_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, (const GLchar *const *) &invalid_code); glActiveShaderProgram(pipe, unlinked_prog); pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog); if (active_prog != vs_prog) { printf("glActiveShaderProgram with an unlinked program " "changed the active program state.\n"); pass = false; } else { glActiveShaderProgram(pipe, vs_prog); } free(source); piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
bool validate(GLuint const & ProgramName) { bool Error = false; // Pipeline object validation { GLint Status(0); GLint LengthMax(0); glValidateProgramPipeline(PipelineName); glGetProgramPipelineiv(PipelineName, GL_VALIDATE_STATUS, &Status); glGetProgramPipelineiv(PipelineName, GL_INFO_LOG_LENGTH, &LengthMax); GLsizei LengthQuery(0); std::vector<GLchar> InfoLog(LengthMax + 1, '\0'); glGetProgramPipelineInfoLog(PipelineName, GLsizei(InfoLog.size()), &LengthQuery, &InfoLog[0]); glDebugMessageInsertARB( GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, 76, GL_DEBUG_SEVERITY_LOW_ARB, LengthQuery, &InfoLog[0]); } GLint ActiveAttributeMaxLength(0); GLint ActiveAttribute(0); glGetProgramiv(ProgramName, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &ActiveAttributeMaxLength); glGetProgramiv(ProgramName, GL_ACTIVE_ATTRIBUTES, &ActiveAttribute); GLsizei AttribLength(0); GLint AttribSize(0); GLenum AttribType(0); std::vector<GLchar> AttribName(ActiveAttributeMaxLength, '\0'); for(GLint i = 0; i < ActiveAttribute; ++i) { glGetActiveAttrib(ProgramName, GLuint(i), GLsizei(ActiveAttributeMaxLength), &AttribLength, &AttribSize, &AttribType, &AttribName[0]); std::string NameString; NameString.insert(NameString.begin(), AttribName.begin(), AttribName.end()); std::vector<GLchar> NameSwap(ActiveAttributeMaxLength, '\0'); std::swap(AttribName, NameSwap); GLint AttribLocation = glGetAttribLocation(ProgramName, NameString.c_str()); vertexattrib VertexAttrib; glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &VertexAttrib.Enabled); //glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &VertexAttrib.Binding); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_SIZE, &VertexAttrib.Size); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &VertexAttrib.Stride); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_TYPE, &VertexAttrib.Type); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &VertexAttrib.Normalized); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_INTEGER, &VertexAttrib.Integer); glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_DIVISOR, &VertexAttrib.Divisor); glGetVertexAttribPointerv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_POINTER, &VertexAttrib.Pointer); if(GL_VERTEX_ATTRIB_ARRAY_INTEGER == GL_TRUE) { if(!( VertexAttrib.Type == GL_INT || VertexAttrib.Type == GL_INT_VEC2 || VertexAttrib.Type == GL_INT_VEC3 || VertexAttrib.Type == GL_INT_VEC4 || VertexAttrib.Type == GL_UNSIGNED_INT || VertexAttrib.Type == GL_UNSIGNED_INT_VEC2 || VertexAttrib.Type == GL_UNSIGNED_INT_VEC3 || VertexAttrib.Type == GL_UNSIGNED_INT_VEC4)) return true; if(!( VertexAttrib.Type == GL_BYTE || VertexAttrib.Type == GL_UNSIGNED_BYTE || VertexAttrib.Type == GL_SHORT || VertexAttrib.Type == GL_UNSIGNED_SHORT || VertexAttrib.Type == GL_INT || VertexAttrib.Type == GL_UNSIGNED_INT)) return true; //if(AttribSize > 1) //GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FLOAT, and GL_DOUBLE } else if(VertexAttrib.Long == GL_TRUE) // OpenGL Spec bug { if( VertexAttrib.Type == GL_DOUBLE || VertexAttrib.Type == GL_DOUBLE_VEC2 || VertexAttrib.Type == GL_DOUBLE_VEC3 || VertexAttrib.Type == GL_DOUBLE_VEC4 || VertexAttrib.Type == GL_DOUBLE_MAT2 || VertexAttrib.Type == GL_DOUBLE_MAT3 || VertexAttrib.Type == GL_DOUBLE_MAT4 || VertexAttrib.Type == GL_DOUBLE_MAT2x3 || VertexAttrib.Type == GL_DOUBLE_MAT2x4 || VertexAttrib.Type == GL_DOUBLE_MAT3x2 || VertexAttrib.Type == GL_DOUBLE_MAT3x4 || VertexAttrib.Type == GL_DOUBLE_MAT4x2 || VertexAttrib.Type == GL_DOUBLE_MAT4x3) { if(VertexAttrib.Type != GL_DOUBLE) return true; } else// if((VertexAttrib.Normalized == GL_TRUE) || (GL_VERTEX_ATTRIB_ARRAY_FLOAT == GL_TRUE)) { if(!( VertexAttrib.Type == GL_FLOAT || VertexAttrib.Type == GL_FLOAT_VEC2 || VertexAttrib.Type == GL_FLOAT_VEC3 || VertexAttrib.Type == GL_FLOAT_VEC4 || VertexAttrib.Type == GL_FLOAT_MAT2 || VertexAttrib.Type == GL_FLOAT_MAT3 || VertexAttrib.Type == GL_FLOAT_MAT4 || VertexAttrib.Type == GL_FLOAT_MAT2x3 || VertexAttrib.Type == GL_FLOAT_MAT2x4 || VertexAttrib.Type == GL_FLOAT_MAT3x2 || VertexAttrib.Type == GL_FLOAT_MAT3x4 || VertexAttrib.Type == GL_FLOAT_MAT4x2 || VertexAttrib.Type == GL_FLOAT_MAT4x3)) return true; // It could be any vertex array attribute type } } printf("glGetActiveAttrib(\n\t%d, \n\t%d, \n\t%d, \n\t%d, \n\t%d, \n\t%s)\n", i, AttribLocation, AttribLength, AttribSize, AttribType, NameString.c_str()); } return Error; }
String logObjectInfo(const String& msg, const GLuint obj) { String logMessage = msg; // Invalid object. if (obj <= 0) { return logMessage; } GLint infologLength = 0; GLboolean isShader = glIsShader(obj); GLboolean isProgramPipeline = glIsProgramPipeline(obj); GLboolean isProgram = glIsProgram(obj); if (isShader) { OGRE_CHECK_GL_ERROR(glGetShaderiv(obj, GL_INFO_LOG_LENGTH, &infologLength)); } else if (isProgramPipeline && Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS)) { //FIXME Crashes on NVIDIA? See GL3+ GSoC forum // posts around 2013-11-25. OGRE_CHECK_GL_ERROR(glGetProgramPipelineiv(obj, GL_INFO_LOG_LENGTH, &infologLength)); } else if (isProgram) { OGRE_CHECK_GL_ERROR(glGetProgramiv(obj, GL_INFO_LOG_LENGTH, &infologLength)); } // No info log available. // if (infologLength <= 1) if (infologLength < 1) { return logMessage; } GLint charsWritten = 0; char * infoLog = new char [infologLength]; infoLog[0] = 0; if (isShader) { OGRE_CHECK_GL_ERROR(glGetShaderInfoLog(obj, infologLength, &charsWritten, infoLog)); } else if (isProgramPipeline && Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS)) { OGRE_CHECK_GL_ERROR(glGetProgramPipelineInfoLog(obj, infologLength, &charsWritten, infoLog)); } else if (isProgram) { OGRE_CHECK_GL_ERROR(glGetProgramInfoLog(obj, infologLength, &charsWritten, infoLog)); } if (strlen(infoLog) > 0) { logMessage += "\n" + String(infoLog); } delete [] infoLog; if (logMessage.size() > 0) { // Remove empty lines from the end of the log. while (logMessage[logMessage.size() - 1] == '\n') { logMessage.erase(logMessage.size() - 1, 1); } LogManager::getSingleton().logMessage(logMessage); } return logMessage; }
void dumpShadersUniforms(JSONWriter &json, Context &context) { GLint pipeline = 0; GLint vertex_program = 0; GLint fragment_program = 0; GLint geometry_program = 0; GLint tess_control_program = 0; GLint tess_evaluation_program = 0; GLint compute_program = 0; if (!context.ES) { glGetIntegerv(GL_PROGRAM_PIPELINE_BINDING, &pipeline); if (pipeline) { glGetProgramPipelineiv(pipeline, GL_VERTEX_SHADER, &vertex_program); glGetProgramPipelineiv(pipeline, GL_FRAGMENT_SHADER, &fragment_program); glGetProgramPipelineiv(pipeline, GL_GEOMETRY_SHADER, &geometry_program); glGetProgramPipelineiv(pipeline, GL_TESS_CONTROL_SHADER, &tess_control_program); glGetProgramPipelineiv(pipeline, GL_TESS_EVALUATION_SHADER, &tess_evaluation_program); glGetProgramPipelineiv(pipeline, GL_COMPUTE_SHADER, &compute_program); } } GLint program = 0; if (!pipeline) { glGetIntegerv(GL_CURRENT_PROGRAM, &program); } json.beginMember("shaders"); json.beginObject(); if (pipeline) { dumpProgram(json, vertex_program); dumpProgram(json, fragment_program); dumpProgram(json, geometry_program); dumpProgram(json, tess_control_program); dumpProgram(json, tess_evaluation_program); dumpProgram(json, compute_program); } else if (program) { dumpProgram(json, program); } else { dumpArbProgram(json, GL_FRAGMENT_PROGRAM_ARB); dumpArbProgram(json, GL_VERTEX_PROGRAM_ARB); } json.endObject(); json.endMember(); // shaders json.beginMember("uniforms"); json.beginObject(); if (pipeline) { dumpProgramUniformsStage(json, vertex_program, "GL_VERTEX_SHADER"); dumpProgramUniformsStage(json, fragment_program, "GL_FRAGMENT_SHADER"); dumpProgramUniformsStage(json, geometry_program, "GL_GEOMETRY_SHADER"); dumpProgramUniformsStage(json, tess_control_program, "GL_TESS_CONTROL_SHADER"); dumpProgramUniformsStage(json, tess_evaluation_program, "GL_TESS_EVALUATION_SHADER"); dumpProgramUniformsStage(json, compute_program, "GL_COMPUTE_SHADER"); } else if (program) { dumpProgramUniforms(json, program); } else { dumpArbProgramUniforms(json, GL_FRAGMENT_PROGRAM_ARB, "fp."); dumpArbProgramUniforms(json, GL_VERTEX_PROGRAM_ARB, "vp."); } json.endObject(); json.endMember(); // uniforms json.beginMember("buffers"); json.beginObject(); if (program) { dumpTransformFeedback(json, program); } json.endObject(); json.endMember(); // buffers }
void piglit_init(int argc, char **argv) { GLint vs, fs, gs, tcs, tes; GLint ver; GLuint pipe = 0; GLint param = 0; char *version = NULL; const char *shader_source[2]; static const char vs_source[] = "#if __VERSION__ > 140\n" "/* At least some versions of AMD's closed-source driver\n" " * contain a bug that requires redeclaration of gl_PerVertex\n" " * interface block in core profile shaders.\n" " */\n" "out gl_PerVertex {\n" " vec4 gl_Position;\n" "};\n" "\n" "in vec4 position;\n" "#else\n" "varying vec4 position;\n" "#endif\n" "\n" "void main()\n" "{\n" " gl_Position = position;\n" "}\n"; static const char fs_source[] = "void main()\n" "{\n" " gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0);\n" "}\n"; static const char gs_source[] = "/* At least some versions of AMD's closed-source driver\n" " * contain a bug that requires redeclaration of gl_PerVertex\n" " * interface block in core profile shaders.\n" " */\n" "in gl_PerVertex {\n" " vec4 gl_Position;\n" " float gl_PointSize;\n" " float gl_ClipDistance[];\n" "} gl_in[];\n" "\n" "out gl_PerVertex {\n" " vec4 gl_Position;\n" " float gl_PointSize;\n" " float gl_ClipDistance[];\n" "};\n" "\n" "layout(triangles) in;\n" "layout(triangle_strip, max_vertices = 3) out;\n" "void main() {\n" " for(int i = 0; i < gl_in.length(); i++) {\n" " gl_Position = gl_in[i].gl_Position;\n" " EmitVertex();\n" " }\n" " EndPrimitive();\n" "}\n"; static const char tc_source[] = "/* At least some versions of AMD's closed-source driver\n" " * contain a bug that requires redeclaration of gl_PerVertex\n" " * interface block in core profile shaders.\n" " */\n" "in gl_PerVertex {\n" " vec4 gl_Position;\n" " float gl_PointSize;\n" " float gl_ClipDistance[];\n" "} gl_in[];\n" "\n" "out gl_PerVertex {\n" " vec4 gl_Position;\n" " float gl_PointSize;\n" " float gl_ClipDistance[];\n" "} gl_out[];\n" "\n" "layout(vertices = 3) out;\n" "void main()\n" "{\n" " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n" " gl_TessLevelOuter[0] = 1.0;\n" " gl_TessLevelOuter[1] = 1.0;\n" " gl_TessLevelOuter[2] = 1.0;\n" " gl_TessLevelInner[0] = 1.0;\n" " gl_TessLevelInner[1] = 1.0;\n" "}\n"; static const char te_source[] = "/* At least some versions of AMD's closed-source driver\n" " * contain a bug that requires redeclaration of gl_PerVertex\n" " * interface block in core profile shaders.\n" " */\n" "in gl_PerVertex {\n" " vec4 gl_Position;\n" " float gl_PointSize;\n" " float gl_ClipDistance[];\n" "} gl_in[];\n" "\n" "out gl_PerVertex {\n" " vec4 gl_Position;\n" " float gl_PointSize;\n" " float gl_ClipDistance[];\n" "};\n" "\n" "layout(triangles, equal_spacing) in;\n" "\n" "void main()\n" "{\n" " vec4 p0 = gl_in[0].gl_Position;\n" " vec4 p1 = gl_in[1].gl_Position;\n" " vec4 p2 = gl_in[2].gl_Position;\n" "\n" " vec3 p = gl_TessCoord.xyz;\n" "\n" " gl_Position = p0*p.x + p1*p.y + p2*p.z;\n" "}\n"; const bool has_gs = piglit_get_gl_version() >= 32; const bool has_tess = piglit_get_gl_version() >= 40 || piglit_is_extension_supported("GL_ARB_tessellation_shader"); piglit_require_extension("GL_ARB_separate_shader_objects"); pass = true; if (piglit_get_gl_version() >= 43) { ver = 430; } else if (piglit_get_gl_version() >= 32) { ver = 150; } else { ver = 110; } asprintf(&version, "#version %d\n" "#extension GL_ARB_separate_shader_objects: enable\n\n", ver); shader_source[0] = version; if (has_tess) { shader_source[1] = tc_source; tcs = glCreateShaderProgramv(GL_TESS_CONTROL_SHADER, 2, shader_source); pass = piglit_link_check_status(tcs) && pass; shader_source[1] = te_source; tes = glCreateShaderProgramv(GL_TESS_EVALUATION_SHADER, 2, shader_source); pass = piglit_link_check_status(tes) && pass; } else { tcs = 0; tes = 0; } if (has_gs) { shader_source[1] = gs_source; gs = glCreateShaderProgramv(GL_GEOMETRY_SHADER, 2, shader_source); pass = piglit_link_check_status(gs) && pass; } else { gs = 0; } shader_source[1] = fs_source; fs = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 2, shader_source); pass = piglit_link_check_status(fs) && pass; shader_source[1] = vs_source; vs = glCreateShaderProgramv(GL_VERTEX_SHADER, 2, shader_source); pass = piglit_link_check_status(vs) && pass; glGenProgramPipelines(1, &pipe); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glActiveShaderProgram(pipe, fs); glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, ¶m); if (param != fs) { fprintf(stderr, "Failed to get Active Program.\n"); pass = false; } pass = piglit_check_gl_error(GL_NO_ERROR) && pass; use_stage_and_check(pipe, vs, GL_VERTEX_SHADER, true); use_stage_and_check(pipe, fs, GL_FRAGMENT_SHADER, true); use_stage_and_check(pipe, gs, GL_GEOMETRY_SHADER, has_gs); use_stage_and_check(pipe, tes, GL_TESS_EVALUATION_SHADER, has_tess); use_stage_and_check(pipe, tcs, GL_TESS_CONTROL_SHADER, has_tess); glActiveShaderProgram(pipe, vs); glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, ¶m); if (param != vs) { fprintf(stderr, "Failed to get Active Program.\n"); pass = false; } pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glUseProgramStages(pipe, GL_ALL_SHADER_BITS, 0); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; check_stage(pipe, 0, GL_VERTEX_SHADER, true); check_stage(pipe, 0, GL_FRAGMENT_SHADER, true); check_stage(pipe, 0, GL_GEOMETRY_SHADER, has_gs); check_stage(pipe, 0, GL_TESS_EVALUATION_SHADER, has_tess); check_stage(pipe, 0, GL_TESS_CONTROL_SHADER, has_tess); free(version); piglit_present_results(); piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }