This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-24
Channels
- # announcements (2)
- # aws (2)
- # babashka (1)
- # beginners (87)
- # boot (1)
- # calva (42)
- # clj-kondo (18)
- # cljdoc (5)
- # cljsjs (1)
- # cljsrn (1)
- # clojars (16)
- # clojure (222)
- # clojure-dev (30)
- # clojure-europe (17)
- # clojure-gamedev (2)
- # clojure-hungary (10)
- # clojure-italy (6)
- # clojure-nl (21)
- # clojure-spec (9)
- # clojure-uk (111)
- # clojuredesign-podcast (1)
- # clojurescript (99)
- # code-reviews (1)
- # conjure (18)
- # cursive (11)
- # datomic (22)
- # emacs (1)
- # events (3)
- # figwheel-main (3)
- # fulcro (14)
- # graalvm (41)
- # graphql (16)
- # helix (12)
- # juxt (1)
- # kaocha (56)
- # keechma (1)
- # meander (77)
- # observability (1)
- # off-topic (29)
- # pathom (3)
- # re-frame (4)
- # reagent (3)
- # reitit (1)
- # remote-jobs (3)
- # reveal (9)
- # shadow-cljs (45)
- # spacemacs (43)
- # sql (28)
- # tools-deps (14)
- # vim (1)
- # xtdb (26)
- # yada (1)
I'm trying to measure the frame time, for the purposes of getting a sense of how close I'm getting to using up my time budget, in a clojure LWJGL project (based upon https://github.com/rogerallen/hello_lwjgl, but updated to LWJGL version 3.2.3). This is my main loop:
(defn main-loop [^Histogram histogram]
(loop [frame-t0 nil]
(update-globals)
(draw)
(when frame-t0
(.recordValue histogram (- (get-time) frame-t0)))
(GLFW/glfwSwapBuffers (:window @globals))
;;(GL11/glClear (bit-or GL11/GL_COLOR_BUFFER_BIT GL11/GL_DEPTH_BUFFER_BIT GL11/GL_STENCIL_BUFFER_BIT))
(GLFW/glfwPollEvents)
(when-not (GLFW/glfwWindowShouldClose (:window @globals))
(recur (get-time))))
(.outputPercentileDistribution histogram System/out 1000000.0))
where Histogram is this class: https://github.com/HdrHistogram/HdrHistogram, tl;dr: something that keeps track of the recorded times and can summarize them for me at the end, and for (get-time) I tried (System/nanoTime) and (GLFW/glfwGetTime) with the same results as far as this question is concerned. Also, the fact that I'm excluding the GLFW/glfwPollEvents
call from my measurements is a temporary experiment that doesn't matter for this purpose either.
My problem was that the time spent waiting for vsync was included in these measurements despite my attempts to exclude it. The only thing that worked for me is the line that is commented above (i.e., do some drawing op before getting the start time. i.e., it would seem like GLFW/glfwSwapBuffers returns before the vsync wait, but any further OpenGL drawing call will block until vsync is done.
Is this expected behavior? Am I missing anything? In any event, I thought I'd leave this hint here should anyone stumble into the same problem.