PIGLIT_GL_TEST_CONFIG_END enum piglit_result piglit_display(void) { GLuint oq[3]; GLint result[3] = {2, 2, 2}; bool pass = true; int i; glEnable(GL_DEPTH_TEST); glClearDepth(1.0); glClearColor(0.5, 0.5, 0.5, 0.5); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glGenQueries(3, oq); glDeleteQueries(3, oq); glColor4f(0.0, 1.0, 0.0, 0.0); glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[0]); piglit_draw_rect_z(0.5, -1, -1, 2, 2); glEndQuery(GL_ANY_SAMPLES_PASSED); glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[1]); glEndQuery(GL_ANY_SAMPLES_PASSED); glColor4f(1.0, 0.0, 0.0, 0.0); glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[2]); piglit_draw_rect_z(0.75, -0.5, -0.5, 1.0, 1.0); glEndQuery(GL_ANY_SAMPLES_PASSED); piglit_present_results(); for (i = 0; i < 3; i++) { glGetQueryObjectiv(oq[i], GL_QUERY_RESULT, &result[i]); } if (result[0] != GL_TRUE) { fprintf(stderr, "GL_ANY_SAMPLES_PASSED with passed fragments returned %d\n", result[0]); pass = false; } if (result[1] != GL_FALSE) { fprintf(stderr, "GL_ANY_SAMPLES_PASSED with no rendering returned %d\n", result[1]); pass = false; } if (result[2] != GL_FALSE) { fprintf(stderr, "GL_ANY_SAMPLES_PASSED with occluded rendering returned %d\n", result[2]); pass = false; } return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
PIGLIT_GL_TEST_CONFIG_END enum piglit_result piglit_display(void) { GLuint active, inactive; GLint elapsed; /* Generate and start a query. */ glGenQueries(1, &active); glBeginQuery(GL_SAMPLES_PASSED, active); printf ("Testing Gen/Delete of query while another query is active.\n"); { /* While first query is active, gen a new one. */ glGenQueries(1, &inactive); if (!piglit_check_gl_error(GL_NO_ERROR)) return PIGLIT_FAIL; /* Delete the inactive query. */ glDeleteQueries(1, &inactive); if (!piglit_check_gl_error(GL_NO_ERROR)) return PIGLIT_FAIL; /* Finish and get result from active query. */ glEndQuery(GL_SAMPLES_PASSED); glGetQueryObjectiv(active, GL_QUERY_RESULT, &elapsed); } printf ("Testing Delete of currently-active query.\n"); { /* Finally, ensure that an active query can be deleted. */ glGenQueries(1, &active); glBeginQuery(GL_SAMPLES_PASSED, active); glDeleteQueries(1, &active); if (!piglit_check_gl_error(GL_NO_ERROR)) return PIGLIT_FAIL; } printf ("Testing that glEndQuery on deleted query (expecting error).\n"); { /* And ensure that we get an error if we try to end a deleted * query. */ glEndQuery(GL_SAMPLES_PASSED); if (!piglit_check_gl_error(GL_INVALID_OPERATION)) return PIGLIT_FAIL; } return PIGLIT_PASS; }
void OGLConditionalRender::Begin() { if (glloader_GL_VERSION_3_3() || glloader_GL_ARB_occlusion_query2()) { glBeginQuery(GL_ANY_SAMPLES_PASSED, query_); } else { glBeginQuery(GL_SAMPLES_PASSED, query_); } }
enum piglit_result piglit_display(void) { #define NUM_QUERIES 5 GLuint queries[NUM_QUERIES], available; bool test_pass = true; GLint result; int i; piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); glClearColor(1.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glGenQueries(NUM_QUERIES, queries); glColor4f(0.0f, 1.0f, 0.0f, 1.0f); /* Queue up a bunch of drawing with several queries. */ for (i = 0; i < NUM_QUERIES - 1; i++) { glBeginQuery(GL_SAMPLES_PASSED, queries[i]); draw_some_things((double)i / (NUM_QUERIES - 1)); glEndQuery(GL_SAMPLES_PASSED); } /* Now fire off a query with no drawing. */ glBeginQuery(GL_SAMPLES_PASSED, queries[NUM_QUERIES - 1]); glEndQuery(GL_SAMPLES_PASSED); /* Get the result for the final query. */ glGetQueryObjectiv(queries[NUM_QUERIES - 1], GL_QUERY_RESULT, &result); /* At this point, the results of all the previous queries * should be available. */ for (i = 0; i < NUM_QUERIES - 1; i++) { glGetQueryObjectuiv(queries[i], GL_QUERY_RESULT_AVAILABLE, &available); if (available != 1) { printf("Query #%d result not available (expected in-order processing)\n", i); test_pass = false; } } glDeleteQueries(NUM_QUERIES, queries); piglit_present_results(); return test_pass ? PIGLIT_PASS : PIGLIT_FAIL; }
void MetricBackend_opengl::beginQuery(QueryBoundary boundary) { // GPU related if (glQueriesNeeded[boundary]) { std::array<GLuint, QUERY_LIST_END> query; glGenQueries(QUERY_LIST_END, query.data()); if (metrics[METRIC_GPU_START].profiled[boundary] || (metrics[METRIC_GPU_DURATION].profiled[boundary] && supportsTimestamp)) { glQueryCounter(query[QUERY_GPU_START], GL_TIMESTAMP); } if (metrics[METRIC_GPU_DURATION].profiled[boundary] && !supportsTimestamp) { glBeginQuery(GL_TIME_ELAPSED, query[QUERY_GPU_DURATION]); } if (metrics[METRIC_GPU_PIXELS].profiled[boundary]) { glBeginQuery(GL_SAMPLES_PASSED, query[QUERY_OCCLUSION]); } queries[boundary].push(std::move(query)); } // CPU related if (metrics[METRIC_CPU_START].profiled[boundary] || metrics[METRIC_CPU_DURATION].profiled[boundary]) { cpuStart[boundary] = getCurrentTime(); if (metrics[METRIC_CPU_START].profiled[boundary]) { int64_t time = cpuStart[boundary] * cpuTimeScale - baseTime; data[METRIC_CPU_START][boundary]->addData(boundary, time); } } if (metrics[METRIC_CPU_VSIZE_START].profiled[boundary] || metrics[METRIC_CPU_VSIZE_DURATION].profiled[boundary]) { vsizeStart[boundary] = os::getVsize(); if (metrics[METRIC_CPU_VSIZE_START].profiled[boundary]) { int64_t time = vsizeStart[boundary]; data[METRIC_CPU_VSIZE_START][boundary]->addData(boundary, time); } } if (metrics[METRIC_CPU_RSS_START].profiled[boundary] || metrics[METRIC_CPU_RSS_DURATION].profiled[boundary]) { rssStart[boundary] = os::getRss(); if (metrics[METRIC_CPU_RSS_START].profiled[boundary]) { int64_t time = rssStart[boundary]; data[METRIC_CPU_RSS_START][boundary]->addData(boundary, time); } } queryInProgress[boundary] = true; // DRAWCALL is a CALL if (boundary == QUERY_BOUNDARY_DRAWCALL) beginQuery(QUERY_BOUNDARY_CALL); }
void recursion( float startX, float startY, float startZ, float startW) { glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER,0,streamoutBufffer[0]); glBeginTransformFeedback(GL_POINTS); glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, outputQuery); glPointSize(1); glBegin(GL_POINTS); glVertex4f(startX, startY, startZ, startW); glEnd(); glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); glEndTransformFeedback(); GLint outPointCount = 0; GLint succ = 0; while(!succ) glGetQueryObjectiv(outputQuery, GL_QUERY_RESULT_AVAILABLE, &succ); glGetQueryObjectiv(outputQuery, GL_QUERY_RESULT, &outPointCount); //std::cout << "points written: " << outPointCount << std::endl; succ = 0; glEnableClientState(GL_VERTEX_ARRAY); int bb = 0; while(outPointCount > 0) { glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER,0,streamoutBufffer[(bb+1)%2]); glBeginTransformFeedback(GL_POINTS); glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, outputQuery); glBindBufferARB(GL_ARRAY_BUFFER_ARB, streamoutBufffer[bb]); glVertexPointer(4,GL_FLOAT,0,NULL); glDrawArrays(GL_POINTS, 0, outPointCount); glEndTransformFeedback(); glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); while(!succ) glGetQueryObjectiv(outputQuery, GL_QUERY_RESULT_AVAILABLE, &succ); glGetQueryObjectiv(outputQuery, GL_QUERY_RESULT, &outPointCount); succ = 0; bb = (bb + 1) % 2; } glDisableClientState(GL_VERTEX_ARRAY); }
PIGLIT_GL_TEST_CONFIG_END enum piglit_result piglit_display(void) { bool pass = true; float green[4] = {0.0, 1.0, 0.0, 0.0}; GLuint q; GLuint list; list = glGenLists(1); glNewList(list, GL_COMPILE); glClearColor(0.5, 0.5, 0.5, 0.5); glClear(GL_COLOR_BUFFER_BIT); glGenQueries(1, &q); /* Generate query pass: draw bottom half of screen. */ glColor4f(0.0, 1.0, 0.0, 0.0); glBeginQuery(GL_SAMPLES_PASSED, q); piglit_draw_rect(-1, -1, 2, 1); glEndQuery(GL_SAMPLES_PASSED); /* Conditional render that should draw top half of screen. */ glBeginConditionalRenderNV(q, GL_QUERY_WAIT_NV); piglit_draw_rect(-1, 0, 2, 1); glEndConditionalRenderNV(); /* Generate query fail */ glBeginQuery(GL_SAMPLES_PASSED, q); glEndQuery(GL_SAMPLES_PASSED); /* Conditional render that should not draw full screen. */ glBeginConditionalRenderNV(q, GL_QUERY_WAIT_NV); glColor4f(1.0, 0.0, 0.0, 0.0); piglit_draw_rect(-1, -1, 2, 2); glEndConditionalRenderNV(); glEndList(); glCallList(list); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green); piglit_present_results(); glDeleteQueries(1, &q); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
static float draw(GLuint *q, int iters) { float start_time, end_time; glUseProgram(prog); glUniform1i(iters_loc, iters); start_time = get_time(); if (test == TIMESTAMP) { glQueryCounter(q[0], GL_TIMESTAMP); } else { glBeginQuery(GL_TIME_ELAPSED, q[0]); } piglit_draw_rect(-1, -1, 2, 2); if (test == TIMESTAMP) { glQueryCounter(q[1], GL_TIMESTAMP); } else { glEndQuery(GL_TIME_ELAPSED); } /* This glFinish() is important, since this is used in a * timing loop. */ glFinish(); end_time = get_time(); return end_time - start_time; }
void TransitionParticles::update(const ofBufferObject & blobs, const ofxTexture3d & noiseField, float now){ auto numParticles = totalVertices / every; computeShader.begin(); computeShader.setUniform1f("every", every); computeShader.setUniform1f("now", now); computeShader.setUniform1f("dt",ofGetLastFrameTime()*speed); computeShader.setUniform1f("repulsionForce", repulsion); computeShader.setUniform1f("attractionForce", attraction); computeShader.setUniform1f("elapsedTime",now); computeShader.setUniform1f("bufferSize", totalVertices); computeShader.setUniform1f("noiseSize", noiseField.texData.width); computeShader.setUniform1f("frameNum", ofGetFrameNum()); computeShader.setUniformTexture("noiseField", GL_TEXTURE_3D, noiseField.texData.textureID, 0); computeShader.dispatchCompute(numParticles / 1024 + 1, 1, 1); computeShader.end(); glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, numVerticesQuery); shader.beginTransformFeedback(GL_TRIANGLES, feedbackBuffer); blobs.bindBase(GL_SHADER_STORAGE_BUFFER, 0); shader.setUniform1f("every", every); shader.setUniform1f("scale", scale); shader.setUniform4f("particleColor", color); model.drawInstanced(GL_TRIANGLES, 0, model.getNumVertices(), numParticles); shader.endTransformFeedback(feedbackBuffer); glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); glGetQueryObjectuiv(numVerticesQuery, GL_QUERY_RESULT, &numPrimitives); }
void LODmodel::getLODvalue() { // ================================== // occlusion query alg glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf( transformMatrix.m ); // draw bbox and query it... glBeginQuery(GL_SAMPLES_PASSED, queryID); lods[0]->drawForLOD(); glEndQuery(GL_SAMPLES_PASSED); glPopMatrix(); // decide which LOD depending on query result... GLuint result = 0; glGetQueryObjectuiv(queryID, GL_QUERY_RESULT, &result); *LODvalue = result; /* // =================================== // distance alg // get distance to camera // decide which LOD depending distance... */ }
void GLGSRender::check_zcull_status(bool framebuffer_swap, bool force_read) { if (g_cfg.video.disable_zcull_queries) return; bool testing_enabled = zcull_pixel_cnt_enabled || zcull_stats_enabled; if (framebuffer_swap) { zcull_surface_active = false; const u32 zeta_address = depth_surface_info.address; if (zeta_address) { //Find zeta address in bound zculls for (int i = 0; i < rsx::limits::zculls_count; i++) { if (zculls[i].binded) { const u32 rsx_address = rsx::get_address(zculls[i].offset, CELL_GCM_LOCATION_LOCAL); if (rsx_address == zeta_address) { zcull_surface_active = true; break; } } } } } occlusion_query_info* query = nullptr; if (zcull_task_queue.task_stack.size() > 0) query = zcull_task_queue.active_query; if (query && query->active) { if (force_read || (!zcull_rendering_enabled || !testing_enabled || !zcull_surface_active)) { glEndQuery(GL_ANY_SAMPLES_PASSED); query->active = false; query->pending = true; } } else { if (zcull_rendering_enabled && testing_enabled && zcull_surface_active) { //Find query u32 free_index = synchronize_zcull_stats(); query = &occlusion_query_data[free_index]; zcull_task_queue.add(query); glBeginQuery(GL_ANY_SAMPLES_PASSED, query->handle); query->active = true; query->result = 0; query->num_draws = 0; } } }
/* ======================== PC_BeginNamedEvent FIXME: this is not thread safe on the PC ======================== */ void PC_BeginNamedEvent( const char *szName, ... ) { #if 0 if ( !r_pix.GetBool() ) { return; } if ( !pixEvents ) { // lazy allocation to not waste memory pixEvents = (pixEvent_t *)Mem_ClearedAlloc( sizeof( *pixEvents ) * MAX_PIX_EVENTS, TAG_CRAP ); } if ( numPixEvents >= MAX_PIX_EVENTS ) { idLib::FatalError( "PC_BeginNamedEvent: event overflow" ); } if ( ++numPixLevels > 1 ) { return; // only get top level timing information } if ( !glGetQueryObjectui64vEXT ) { return; } GL_CheckErrors(); if ( timeQueryIds[0] == 0 ) { glGenQueries( MAX_PIX_EVENTS, timeQueryIds ); } glFinish(); glBeginQuery( GL_TIME_ELAPSED_EXT, timeQueryIds[numPixEvents] ); GL_CheckErrors(); pixEvent_t *ev = &pixEvents[numPixEvents++]; strncpy( ev->name, szName, sizeof( ev->name ) - 1 ); ev->cpuTime = Sys_Microseconds(); #endif }
void PerfQuery::EnableQuery(PerfQueryGroup type) { if (!ShouldEmulate()) return; // Is this sane? if (m_query_count > ArraySize(m_query_buffer) / 2) WeakFlush(); if (ArraySize(m_query_buffer) == m_query_count) { FlushOne(); //ERROR_LOG(VIDEO, "Flushed query buffer early!"); } // start query if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP) { auto& entry = m_query_buffer[(m_query_read_pos + m_query_count) % ArraySize(m_query_buffer)]; glBeginQuery(GL_SAMPLES_PASSED, entry.query_id); entry.query_type = type; ++m_query_count; } }
//------------------------------------------------------------------------- void GPUSectionTimer::StartSection() { if(!waiting) { glBeginQuery(GL_TIME_ELAPSED, id); } }
void Query::begin() { glBeginQuery(target, id); if (target == GL_TIME_ELAPSED) { glQueryCounter(id, GL_TIMESTAMP); } }
void IrrDriver::computeSunVisibility() { // Is the lens flare enabled & visible? Check last frame's query. bool hasgodrays = false; if (World::getWorld() != NULL) { hasgodrays = World::getWorld()->getTrack()->hasGodRays(); } if (UserConfigParams::m_light_shaft && hasgodrays) { GLuint res = 0; if (m_query_issued) glGetQueryObjectuiv(m_lensflare_query, GL_QUERY_RESULT, &res); m_post_processing->setSunPixels(res); // Prepare the query for the next frame. glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glBeginQuery(GL_SAMPLES_PASSED_ARB, m_lensflare_query); m_scene_manager->setCurrentRendertime(scene::ESNRP_SOLID); m_scene_manager->drawAll(scene::ESNRP_CAMERA); irr_driver->setPhase(GLOW_PASS); m_sun_interposer->render(); glEndQuery(GL_SAMPLES_PASSED_ARB); m_query_issued = true; m_lensflare->setStrength(res / 4000.0f); // Make sure the color mask is reset glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); } }
void FeedbackTransformPass::DoRun() { glDisable(GL_DEPTH_TEST); glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf->vbo); { Use shader(program); glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, query); glBeginTransformFeedback(objtype); glEnable(GL_RASTERIZER_DISCARD); out->Draw(program); glDisable(GL_RASTERIZER_DISCARD); glEndTransformFeedback(); glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); // performance loss of 15ms order TODO_W("Move this query to the *start* of the transform, use the old objects in the drawing phase."); glGetQueryObjectuiv(query, GL_QUERY_RESULT, &buf->count); } glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0); swap(*buf, *out); }
void startGPUTimer(GPUtimer* timer) { if (!timer->supported) return; glBeginQuery(GL_TIME_ELAPSED, timer->queries[timer->cur % GPU_QUERY_COUNT] ); timer->cur++; }
void whitgl_profile_gpu_section(const char* name) { if(next_gpu_event > 0) glEndQuery(GL_TIME_ELAPSED); gpu_events[next_gpu_event].name = name; glBeginQuery(GL_TIME_ELAPSED, _front ? _front_queries[next_gpu_event] : _back_queries[next_gpu_event]); next_gpu_event++; }
void TimeGL::Start(void) { if (first_call) { glGenQueries(1, query); first_call = false; fResult = 0.0; } glBeginQuery(GL_TIME_ELAPSED, query[0]); }
enum piglit_result piglit_display(void) { bool pass = true; float green[4] = {0.0, 1.0, 0.0, 0.0}; GLuint qpass, qfail; glClearColor(1.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glGenQueries(1, &qpass); glGenQueries(1, &qfail); /* Generate query pass: draw top half of screen. */ glColor4f(0.0, 1.0, 0.0, 0.0); glBeginQuery(GL_SAMPLES_PASSED, qpass); piglit_draw_rect(-1, 0, 2, 1); glEndQuery(GL_SAMPLES_PASSED); /* Generate query fail */ glBeginQuery(GL_SAMPLES_PASSED, qfail); glEndQuery(GL_SAMPLES_PASSED); /* Conditional render that should not copy red over the green. */ glBeginConditionalRenderNV(qfail, GL_QUERY_WAIT_NV); glRasterPos2i(-1, 0); glCopyPixels(0, 0, piglit_width, piglit_height / 2, GL_COLOR); glEndConditionalRenderNV(); /* Conditional render that should copy green over remaining red. */ glBeginConditionalRenderNV(qpass, GL_QUERY_WAIT_NV); glRasterPos2i(-1, -1); glCopyPixels(0, piglit_height / 2, piglit_width, piglit_height / 2, GL_COLOR); glEndConditionalRenderNV(); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green); glutSwapBuffers(); glDeleteQueries(1, &qfail); glDeleteQueries(1, &qpass); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
void TimerQuery::beginQuery() { if( m_query == 0 ) { glGenQueries( 1, &m_query ); } glBeginQuery( GL_TIME_ELAPSED, m_query ); }
void Timer::start() { d_running = true; if(d_id != 0) glBeginQuery(GL_TIME_ELAPSED, d_id); d_startCPUtime = chrono::steady_clock::now(); }
void hge::render::GeometryUnit::occlusionQuery(const math::Matrix4D<> &vp) { mvp = vp * modelMatrix.getConstRotateScaleTranslateMatrix(); glBeginQuery(GL_ANY_SAMPLES_PASSED, queries[HGEGEOMETRYOCCLUSIONQUERYINDEX]); occlusionQueryShader->setModelViewProjectionMatrix(mvp); occlusionQueryMesh->bindTotal(); occlusionQueryMesh->draw(); glEndQuery(GL_ANY_SAMPLES_PASSED); }
static void SCE_ROcclusionQueryCallback (int begin) { if (begin) glBeginQuery (GL_SAMPLES_PASSED, queryid); else { glEndQuery (GL_SAMPLES_PASSED); glGetQueryObjectiv (queryid, GL_QUERY_RESULT, &drawpixels); } }
enum piglit_result piglit_display(void) { bool pass = true; GLfloat *v; int i; GLuint q, num_prims; glClear(GL_COLOR_BUFFER_BIT); glGenQueries(1, &q); glBeginQuery(GL_PRIMITIVES_GENERATED_EXT, q); glBeginTransformFeedback(GL_POINTS); glBindBuffer(GL_ARRAY_BUFFER, vert_buf); glVertexPointer(3, GL_FLOAT, 0, 0); glEnable(GL_VERTEX_ARRAY); glDrawArrays(GL_POINTS, 0, 3); glEndTransformFeedback(); glEndQuery(GL_PRIMITIVES_GENERATED); glGetQueryObjectuiv(q, GL_QUERY_RESULT, &num_prims); glDeleteQueries(1, &q); printf("%u primitives generated:\n", num_prims); if (num_prims != NUM_VERTS) { printf("Incorrect number of prims generated.\n"); printf("Found %u, expected %u\n", num_prims, NUM_VERTS); pass = false; } glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, xfb_buf); v = glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, GL_READ_ONLY); for (i = 0; i < num_prims; i++) { printf("vertex %2d: pos %5.2g, %5.2g, %5.2g, %5.2g " "color %5.2g, %5.2g, %5.2g, %5.2g\n", i, v[i*8+0], v[i*8+1], v[i*8+2], v[i*8+3], v[i*8+4], v[i*8+5], v[i*8+6], v[i*8+7]); /* spot-check results */ if (!equal(v[i*8+1], 0.1)) { printf("Incorrect Y coord for point %d: %f\n", i, v[i*8+1]); pass = false; } if (!equal(v[i*8+4], 0.9)) { printf("Incorrect red value for point %d: %f\n", i, v[i*8+4]); pass = false; } } glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT); piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
bool render() { glm::ivec2 WindowSize(this->getWindowSize()); { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = reinterpret_cast<glm::mat4*>(glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT)); glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, static_cast<float>(WindowSize.x) / static_cast<float>(WindowSize.y), 0.1f, 100.0f); glm::mat4 Model = glm::mat4(1.0f); *Pointer = Projection * this->view() * Model; glUnmapBuffer(GL_UNIFORM_BUFFER); } // Set the display viewport glViewport(0, 0, WindowSize.x, WindowSize.y); glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); // Clear color buffer with black glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]); // Bind program glUseProgram(ProgramName); glBindVertexArray(VertexArrayName); glBindBufferRange(GL_UNIFORM_BUFFER, semantic::uniform::MATERIAL, BufferName[buffer::MATERIAL], 0, sizeof(glm::vec4)); // The first orange quad is not written in the framebuffer. glColorMaski(0, GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Beginning of the samples count query glBeginQuery(GL_SAMPLES_PASSED, QueryName); // To test the condional rendering, comment this line, the next draw call won't happen. glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1); // End of the samples count query glEndQuery(GL_SAMPLES_PASSED); // The second blue quad is written in the framebuffer only if a sample pass the occlusion query. glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glBindBufferRange(GL_UNIFORM_BUFFER, semantic::uniform::MATERIAL, BufferName[buffer::MATERIAL], this->UniformMaterialOffset, sizeof(glm::vec4)); // Draw only if one sample went through the tests, // we don't need to get the query result which prevent the rendering pipeline to stall. glBeginConditionalRender(QueryName, GL_QUERY_WAIT); // Clear color buffer with white glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]); glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1); glEndConditionalRender(); return true; }
static bool do_test_vector(const struct test_set *test, const struct test_vector *vector) { GLuint primitives_generated; int i; const GLint *readback; unsigned expected_output_points; unsigned actual_output_points; bool pass = true; printf("Testing %s(%d vertices)\n", piglit_get_prim_name(tests->prim_type), vector->num_input_vertices); /* Run vertices through the pipeline */ glBeginQuery(GL_PRIMITIVES_GENERATED, generated_query); glBeginTransformFeedback(GL_POINTS); glDrawArrays(test->prim_type, 0, vector->num_input_vertices); glEndTransformFeedback(); glEndQuery(GL_PRIMITIVES_GENERATED); /* Check that the GS got invoked the right number of times */ glGetQueryObjectuiv(generated_query, GL_QUERY_RESULT, &primitives_generated); if (primitives_generated != vector->expected_gs_invocations) { printf(" Expected %d GS invocations, got %d\n", vector->expected_gs_invocations, primitives_generated); pass = false; } expected_output_points = vector->expected_gs_invocations * test->vertices_per_prim; actual_output_points = primitives_generated * test->vertices_per_prim; /* Check the data output by the GS */ readback = glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, GL_READ_ONLY); if (memcmp(readback, vector->expected_results, expected_output_points * sizeof(GLint)) != 0) { pass = false; } /* Output details if the result was wrong */ if (!pass) { printf(" Expected vertex IDs:"); for (i = 0; i < expected_output_points; i++) printf(" %d", vector->expected_results[i]); printf("\n"); printf(" Actual vertex IDs: "); for (i = 0; i < actual_output_points; i++) printf(" %d", readback[i]); printf("\n"); } glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER); return pass; }
enum piglit_result piglit_display(void) { bool pass = true; float red[4] = {1.0, 0.0, 0.0, 0.0}; float green[4] = {0.0, 1.0, 0.0, 0.0}; GLuint q, texture; int tex_size = 64; int i; glClearColor(0.5, 0.5, 0.5, 0.5); glClear(GL_COLOR_BUFFER_BIT); /* Set up a texture object with green at level 0, red elsewhere */ glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); for (i = 0; tex_size / (1 << i) > 0; i++) fill_level(i, tex_size / (1 << i), i == 0 ? green : red); glGenQueries(1, &q); /* Generate query fail. */ glBeginQuery(GL_SAMPLES_PASSED, q); glEndQuery(GL_SAMPLES_PASSED); /* Mipmap generation should not be affected by conditional rendering. */ glBeginConditionalRenderNV(q, GL_QUERY_WAIT_NV); glGenerateMipmapEXT(GL_TEXTURE_2D); glEndConditionalRenderNV(); /* This should draw level 1, since starting window size is 32 * and texture is 64. */ glEnable(GL_TEXTURE_2D); piglit_draw_rect_tex(-1, -1, 2, 2, 0, 0, 1, 1); glDisable(GL_TEXTURE_2D); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green); glutSwapBuffers(); glDeleteQueries(1, &q); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
PIGLIT_GL_TEST_CONFIG_END static bool run_test(bool scissor_clear) { GLuint query; GLint result = -1; piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); glClearColor(0.0, 1.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glGenQueries(1, &query); glBeginQuery(GL_SAMPLES_PASSED, query); /* Render 64 pixels. This should affect the query */ piglit_draw_rect(0, 0, 8, 8); /* Clear the framebuffer. This shouldn't affect the query */ glClearColor(0.0, 0.0, 1.0, 0.0); if (scissor_clear) { glScissor(0, 0, piglit_width / 2, piglit_height / 2); glEnable(GL_SCISSOR_TEST); } glClear(GL_COLOR_BUFFER_BIT); if (scissor_clear) { glDisable(GL_SCISSOR_TEST); } /* Render another 64 pixels. This should continue adding to * the query */ piglit_draw_rect(4, 0, 8, 8); glEndQuery(GL_SAMPLES_PASSED); glGetQueryObjectiv(query, GL_QUERY_RESULT, &result); glDeleteQueries(1, &query); piglit_present_results(); if (result != 128) { printf("Failure: \n"); printf(" Occlusion query resulted in %d samples " "(expected 128)\n", result); printf(" Scissor enabled? %s\n", scissor_clear ? "yes" : "no"); return false; } else { return true; } }