--- .../spec/arb_get_program_binary/gpb-common.c | 126 ++++++++++++++++++ .../spec/arb_get_program_binary/gpb-common.h | 37 +++++ 2 files changed, 163 insertions(+) create mode 100644 tests/spec/arb_get_program_binary/gpb-common.c create mode 100644 tests/spec/arb_get_program_binary/gpb-common.h
diff --git a/tests/spec/arb_get_program_binary/gpb-common.c b/tests/spec/arb_get_program_binary/gpb-common.c new file mode 100644 index 000000000..06194696e --- /dev/null +++ b/tests/spec/arb_get_program_binary/gpb-common.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2018 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 "piglit-util-gl.h" +#include "gpb-common.h" +#include <stdlib.h> + +bool +gpb_save_program(GLuint prog, void **binary, GLsizei *length, GLenum *format) +{ + GLsizei binary_length; + void *binary_buffer; + GLenum binary_format; + GLint ok; + + glGetProgramiv(prog, GL_LINK_STATUS, &ok); + if (!ok) { + fprintf(stderr, "Can't save/restore program that is " + "not linked!\n"); + piglit_report_result(PIGLIT_FAIL); + } + + glGetProgramiv(prog, GL_PROGRAM_BINARY_LENGTH, &binary_length); + if (!piglit_check_gl_error(GL_NO_ERROR)) { + fprintf(stderr, "glGetProgramiv GL_PROGRAM_BINARY_LENGTH " + "error\n"); + piglit_report_result(PIGLIT_FAIL); + } + + binary_buffer = malloc(binary_length); + if (!binary_buffer) + return false; + + glGetProgramBinary(prog, binary_length, &binary_length, &binary_format, + binary_buffer); + if (!piglit_check_gl_error(GL_NO_ERROR)) { + fprintf(stderr, "glGetProgramBinary error\n"); + free(binary_buffer); + piglit_report_result(PIGLIT_FAIL); + } + + *length = binary_length; + *binary = binary_buffer; + *format = binary_format; + return true; +} + +bool +gpb_restore_program(GLuint prog, void *binary, GLsizei length, GLenum format) +{ + GLint ok; + + glProgramBinary(prog, format, binary, length); + if (!piglit_check_gl_error(GL_NO_ERROR)) { + fprintf(stderr, "glProgramBinary error " + "(should not happend according to spec.)\n"); + piglit_report_result(PIGLIT_FAIL); + } + + glGetProgramiv(prog, GL_LINK_STATUS, &ok); + if (!ok) { + fprintf(stderr, "link failure after glProgramBinary\n"); + piglit_report_result(PIGLIT_FAIL); + } + + return true; +} + +bool +gpb_save_restore(GLuint *prog) +{ + GLsizei bin_length; + void *binary; + GLenum bin_format; + GLuint new_prog; + + if (!gpb_save_program(*prog, &binary, &bin_length, &bin_format)) { + fprintf(stderr, + "failed to save program with GetProgramBinary\n"); + piglit_report_result(PIGLIT_FAIL); + } + + new_prog = glCreateProgram(); + if (!piglit_check_gl_error(GL_NO_ERROR)) { + free(binary); + piglit_report_result(PIGLIT_FAIL); + } + + if (!gpb_restore_program(new_prog, binary, bin_length, bin_format)) { + free(binary); + fprintf(stderr, "failed to restore binary program\n"); + piglit_report_result(PIGLIT_FAIL); + } + free(binary); + + glUseProgram(new_prog); + if (!piglit_check_gl_error(GL_NO_ERROR)) + piglit_report_result(PIGLIT_FAIL); + + glDeleteProgram(*prog); + if (!piglit_check_gl_error(GL_NO_ERROR)) + piglit_report_result(PIGLIT_FAIL); + *prog = new_prog; + + return true; +} diff --git a/tests/spec/arb_get_program_binary/gpb-common.h b/tests/spec/arb_get_program_binary/gpb-common.h new file mode 100644 index 000000000..f471241aa --- /dev/null +++ b/tests/spec/arb_get_program_binary/gpb-common.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018 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. + */ + +#pragma once +#ifndef PIGLIT_GPB_COMMON_H +#define PIGLIT_GPB_COMMON_H + +bool +gpb_save_program(GLuint prog, void **binary, GLsizei *length, GLenum *format); + +bool +gpb_restore_program(GLuint prog, void *binary, GLsizei length, GLenum format); + +bool +gpb_save_restore(GLuint *prog); + +#endif -- 2.17.1 _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/piglit