/** * Copy from a source image into a destination image of the specified * format and check the result. * * If \a strict_layout_qualifiers is false, uniform layout qualifiers * will be omitted where allowed by the spec. If \a * strict_access_qualifiers is false, the "readonly" and "writeonly" * qualifiers will be omitted. If \a strict_binding is false, the * image will be bound as READ_WRITE, otherwise only the required * access type will be used. */ static bool run_test(const struct image_format_info *format, bool strict_layout_qualifiers, bool strict_access_qualifiers, bool strict_binding) { const struct grid_info grid = grid_info(GL_FRAGMENT_SHADER, image_base_internal_format(format), W, H); const struct image_info img = image_info(GL_TEXTURE_2D, format->format, W, H); GLuint prog = generate_program( grid, GL_FRAGMENT_SHADER, concat(image_hunk(img, ""), test_hunk(strict_layout_qualifiers, strict_access_qualifiers), hunk("SRC_IMAGE_Q uniform IMAGE_BARE_T src_img;\n" "DST_IMAGE_Q uniform IMAGE_BARE_T dst_img;\n" "\n" "GRID_T op(ivec2 idx, GRID_T x) {\n" " imageStore(dst_img, IMAGE_ADDR(idx)," " imageLoad(src_img, IMAGE_ADDR(idx)));\n" " return x;\n" "}\n"), NULL)); bool ret = prog && init_fb(grid) && init_image(img, 0, strict_binding) && init_image(img, 1, strict_binding) && set_uniform_int(prog, "src_img", 0) && set_uniform_int(prog, "dst_img", 1) && draw_grid(grid, prog) && check(grid, img); glDeleteProgram(prog); return ret; }
static bool run_test(const struct image_op_info *op, unsigned w, unsigned h, bool (*check)(const struct grid_info grid, const struct image_info img, unsigned w, unsigned h), const char *body) { const struct grid_info grid = grid_info(GL_FRAGMENT_SHADER, GL_R32UI, W, H); const struct image_info img = image_info_for_grid(grid); GLuint prog = generate_program( grid, GL_FRAGMENT_SHADER, concat(image_hunk(img, ""), hunk("uniform IMAGE_T img;\n"), hunk(op->hunk), hunk(body), NULL)); bool ret = prog && init_fb(grid) && init_image(img) && set_uniform_int(prog, "img", 0) && draw_grid(set_grid_size(grid, w, h), prog) && check(grid, img, w, h); glDeleteProgram(prog); return ret; }
static bool run_test(const struct image_qualifier_info *qual) { const struct grid_info grid = grid_info(GL_FRAGMENT_SHADER, GL_R32UI, W, H); const struct image_info img = image_info(GL_TEXTURE_1D, GL_R32UI, W, H); GLuint prog = generate_program( grid, /** * Write to consecutive locations of an image using a * the value read from a fixed location of a different * image uniform which aliases the first image. If * the implementation incorrectly coalesces repeated * loads from the fixed location the results of the * test will be altered. */ GL_FRAGMENT_SHADER, concat(qualifier_hunk(qual), image_hunk(img, ""), hunk("IMAGE_Q IMAGE_UNIFORM_T src_img;\n" "IMAGE_Q IMAGE_UNIFORM_T dst_img;\n" "\n" "GRID_T op(ivec2 idx, GRID_T x) {\n" " int i;\n" "\n" " for (i = 0; i < N / 2; ++i) {\n" " imageStore(dst_img, 2 * i," " imageLoad(src_img, W) + 1u);\n" " imageStore(dst_img, 2 * i + 1," " imageLoad(src_img, W) - 1u);\n" " }\n" "\n" " return x;\n" "}\n"), NULL)); bool ret = prog && init_fb(grid) && init_image(img) && set_uniform_int(prog, "src_img", 0) && set_uniform_int(prog, "dst_img", 0) && draw_grid(set_grid_size(grid, 1, 1), prog) && (check(img) || qual->control_test); glDeleteProgram(prog); return ret; }
/** * Test skeleton: Init image to \a init_value, run the provided shader * \a op and check that the resulting image pixels equal \a * check_value. */ static bool run_test(uint32_t init_value, uint32_t check_value, const char *op) { const struct grid_info grid = grid_info(GL_FRAGMENT_SHADER, GL_R32UI, W, H); const struct image_info img = image_info_for_grid(grid); GLuint prog = generate_program( grid, GL_FRAGMENT_SHADER, concat(image_hunk(img, ""), hunk("uniform IMAGE_T img;\n"), hunk(op), NULL)); bool ret = prog && init_fb(grid) && init_image(img, init_value) && set_uniform_int(prog, "img", 0) && draw_grid(grid, prog) && check(img, check_value); glDeleteProgram(prog); return ret; }
/** * If \a layered is false, bind an individual layer of a texture to an * image unit, read its contents and write back a different value to * the same location. If \a layered is true or the texture has a * single layer, the whole texture will be read and written back. * * For textures with a single layer, the arguments \a layered and \a * layer which are passed to the same arguments of * glBindImageTexture() should have no effect as required by the spec. */ static bool run_test(const struct image_target_info *target, bool layered, unsigned layer) { const struct image_info real_img = image_info( target->target, GL_RGBA32F, W, H); const unsigned slices = (layered ? 1 : image_num_layers(real_img)); /* * "Slice" of the image that will be bound to the pipeline. */ const struct image_info slice_img = image_info( (layered ? target->target : image_layer_target(target)), GL_RGBA32F, W, H / slices); /* * Grid with as many elements as the slice. */ const struct grid_info grid = grid_info( GL_FRAGMENT_SHADER, GL_RGBA32F, W, H / slices); GLuint prog = generate_program( grid, GL_FRAGMENT_SHADER, concat(image_hunk(slice_img, ""), hunk("IMAGE_UNIFORM_T img;\n" "\n" "GRID_T op(ivec2 idx, GRID_T x) {\n" " GRID_T v = imageLoad(img, IMAGE_ADDR(idx));\n" " imageStore(img, IMAGE_ADDR(idx), DATA_T(33));\n" " return v;\n" "}\n"), NULL)); bool ret = prog && init_fb(grid) && init_image(real_img, layered, layer) && set_uniform_int(prog, "img", 0) && draw_grid(grid, prog) && check(grid, real_img, (slices == 1 ? 0 : layer)); glDeleteProgram(prog); return ret; }
/** * Test binding image uniforms to image units for a simple shader * program. */ static bool run_test_uniform(void) { const struct grid_info grid = grid_info(GL_FRAGMENT_SHADER, GL_RGBA32F, W, H); GLuint prog = generate_program( grid, GL_FRAGMENT_SHADER, concat(image_hunk(image_info_for_grid(grid), ""), hunk("uniform IMAGE_T imgs[2];\n" "\n" "GRID_T op(ivec2 idx, GRID_T x) {\n" " imageStore(imgs[0], IMAGE_ADDR(idx), x);\n" " imageStore(imgs[1], IMAGE_ADDR(idx), x);\n" " return x;\n" "}\n"), NULL)); const int loc = glGetUniformLocation(prog, "imgs"); bool ret = prog && check_uniform_int(prog, loc, 0) && check_uniform_int(prog, loc + 1, 0); int v[2]; glUseProgram(prog); /* * Image uniforms are bound to image units using * glUniform1i{v}. */ glUniform1i(loc, 3); ret &= check_uniform_int(prog, loc, 3) && check_uniform_int(prog, loc + 1, 0); glUniform1i(loc + 1, 3); ret &= check_uniform_int(prog, loc, 3) && check_uniform_int(prog, loc + 1, 3); v[0] = 4; v[1] = 5; glUniform1iv(loc, 2, v); ret &= check_uniform_int(prog, loc, 4) && check_uniform_int(prog, loc + 1, 5); /* * GL_INVALID_VALUE is generated if the value specified is * greater than or equal to the value of GL_MAX_IMAGE_UNITS. */ glUniform1i(loc, max_image_units()); ret &= piglit_check_gl_error(GL_INVALID_VALUE); v[0] = 3; v[1] = max_image_units() + 1; glUniform1iv(loc, 2, v); ret &= piglit_check_gl_error(GL_INVALID_VALUE); /* * GL_INVALID_VALUE is generated if the value specified is * less than zero. */ glUniform1i(loc, -1); ret &= piglit_check_gl_error(GL_INVALID_VALUE); v[0] = 3; v[1] = -4; glUniform1iv(loc, 2, v); ret &= piglit_check_gl_error(GL_INVALID_VALUE); /* * GL_INVALID_OPERATION is generated by Uniform* functions * other than Uniform1i{v}. */ CHECK_INVAL_2(glUniform, 1f, 1ui, (loc, 0), ret); CHECK_INVAL_3(glUniform, 2i, 2f, 2ui, (loc, 0, 0), ret); CHECK_INVAL_3(glUniform, 3i, 3f, 3ui, (loc, 0, 0, 0), ret); CHECK_INVAL_3(glUniform, 4i, 4f, 4ui, (loc, 0, 0, 0, 0), ret); CHECK_INVAL_2(glUniform, 1fv, 1uiv, (loc, 1, (void *)v), ret); CHECK_INVAL_3(glUniform, 2iv, 2fv, 2uiv, (loc, 1, (void *)v), ret); CHECK_INVAL_3(glUniform, 3iv, 3fv, 3uiv, (loc, 1, (void *)v), ret); CHECK_INVAL_3(glUniform, 4iv, 4fv, 4uiv, (loc, 1, (void *)v), ret); CHECK_INVAL_3(glUniformMatrix, 2fv, 3fv, 4fv, (loc, 1, GL_FALSE, (float *)v), ret); CHECK_INVAL_3(glUniformMatrix, 2x3fv, 3x2fv, 2x4fv, (loc, 1, GL_FALSE, (float *)v), ret); CHECK_INVAL_3(glUniformMatrix, 4x2fv, 3x4fv, 4x3fv, (loc, 1, GL_FALSE, (float *)v), ret); if (piglit_is_extension_supported("GL_ARB_gpu_shader_fp64")) { CHECK_INVAL_1(glUniform, 1d, (loc, 0), ret); CHECK_INVAL_1(glUniform, 2d, (loc, 0, 0), ret); CHECK_INVAL_1(glUniform, 3d, (loc, 0, 0, 0), ret); CHECK_INVAL_1(glUniform, 4d, (loc, 0, 0, 0, 0), ret); CHECK_INVAL_2(glUniform, 1dv, 2dv, (loc, 1, (double *)v), ret); CHECK_INVAL_2(glUniform, 3dv, 4dv, (loc, 1, (double *)v), ret); CHECK_INVAL_3(glUniformMatrix, 2dv, 3dv, 4dv, (loc, 1, GL_FALSE, (double *)v), ret); CHECK_INVAL_3(glUniformMatrix, 2x3dv, 3x2dv, 2x4dv, (loc, 1, GL_FALSE, (double *)v), ret); CHECK_INVAL_3(glUniformMatrix, 4x2dv, 3x4dv, 4x3dv, (loc, 1, GL_FALSE, (double *)v), ret); } glDeleteProgram(prog); return ret; }