示例#1
0
    def paintGL(self):
        """Draw scene"""

        ## record render time statistics
        if self._statistics:

            ## begin GPU time query
            GL.glBeginQuery(GL.GL_TIME_ELAPSED, self._query)

            ## render scene
            self.renderScene()

            ## finish GPU time query
            GL.glEndQuery(GL.GL_TIME_ELAPSED)

            ## record render time statistics, need to stall the CPU a bit
            ready = False 
            while not ready:
                ready = GL.glGetQueryObjectiv(self._query, GL.GL_QUERY_RESULT_AVAILABLE)
            self._gpuElapsed = GL.glGetQueryObjectuiv(self._query, GL.GL_QUERY_RESULT ) / 1000000.0

            ## delete query object
            #GL.glDeleteQueries( self._query )

        else:

            ## render scene
            self.renderScene()

        self._frameElapsed = self._elapsed_timer.restart()
def benchmark(num_test, query, preset=lambda: (), test_name=None):
    qid = gl.glGenQueries(1)[0]

    preset()
    render_times = []
    operation_times = []
    for i in range(num_test):
        s = time.time()
        gl.glBeginQuery(gl.GL_TIME_ELAPSED, qid)
        query()
        gl.glEndQuery(gl.GL_TIME_ELAPSED)
        e = time.time()
        operation_times.append(e - s)
        while not gl.glGetQueryObjectiv(qid, gl.GL_QUERY_RESULT_AVAILABLE):
            pass
        render_times.append(gl.glGetQueryObjectiv(qid, gl.GL_QUERY_RESULT))
    glfw.swap_buffers(window)
    gl.glDeleteQueries(1, [qid])

    truncated_ratio = 0.95
    render_times.sort()
    render_times = render_times[int(len(render_times) * (
        1 - truncated_ratio)):int(len(render_times) * truncated_ratio)]
    render_ave = sum(t / num_test for t in render_times) / 1_000_000_000
    operation_times.sort()
    operation_times = operation_times[
        int(len(operation_times) *
            (1 - truncated_ratio)):int(len(operation_times) * truncated_ratio)]
    op_ave = sum(t / num_test for t in operation_times)
    if test_name is None:
        test_name = query.__name__
    print(f"TEST {test_name} RENDERING ELAPSE TIME: {render_ave}")
    print(f"TEST {test_name} FULL ELAPSE TIME: {op_ave}")
    print()
def test(setting, query, num_test, test_name):
    setting()
    elapse_times = []
    for i in range(num_test):
        gl.glBeginQuery(gl.GL_TIME_ELAPSED, qid)
        query()
        gl.glEndQuery(gl.GL_TIME_ELAPSED)
        elapse_times.append(gl.glGetQueryObjectiv(qid, gl.GL_QUERY_RESULT))
    glfw.swap_buffers(window)
    ave = sum(t / num_test for t in elapse_times) / 1_000_000_000
    print(f"TEST {test_name} RESULT: {ave}")
示例#4
0
num_test = 10
is_test = True
times = {}
for _ in range(num_test):
    removed = []
    # pick
    s = time.time()
    for i in cherry_picked:
        block = test1_blocks[i]
        removed.append(block['idx'][:])
        block.release_refill(0xff_ff_ff_ff)
    e = time.time()
    times.setdefault('refill', []).append(e - s)

    # push data
    gl.glBeginQuery(gl.GL_TIME_ELAPSED, qid)
    gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, test3_ibo)
    gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, test1_idx.active_bytesize,
                    test1_idx.array, gl.GL_DYNAMIC_DRAW)
    gl.glEndQuery(gl.GL_TIME_ELAPSED)
    times.setdefault('push_packed', []).append(
        gl.glGetQueryObjectiv(qid, gl.GL_QUERY_RESULT) / 1_000_000_000)

    # render
    gl.glBeginQuery(gl.GL_TIME_ELAPSED, qid)
    gl.glDrawElements(gl.GL_POINTS, test1_idx.active_size + 1,
                      gl.GL_UNSIGNED_INT, ctypes.c_void_p(0))
    gl.glEndQuery(gl.GL_TIME_ELAPSED)
    times.setdefault('render_packed', []).append(
        gl.glGetQueryObjectiv(qid, gl.GL_QUERY_RESULT) / 1_000_000_000)