ARB_sync and proper testing

zeboidlund

I came across the concept of Sync Objects, and decided to test them out. They seem to work as expected, but my current test cases are limited.

What would be a proper test to ensure that these sync objects are performing as intended as a means to synchronize the CPU rendering thread with the GPU?

An example use-case for this would be for video capture programs which "hook" into the OpenGL context of a video game, or some other application using OpenGL.

Andon M. Coleman

Your example use-case seems fishy to me.

FRAPS is an example of a program that "hooks" into an OpenGL application to capture video, and it does it very differently. Rather than force a CPU-GPU synchronization, FRAPS inserts an asynchronous pixelbuffer read immediately before SwapBuffers (...) is called. It will then try and read the results back the next time SwapBuffers (...) is called instead of stalling while the result becomes available the first time around. Latency does not matter for FRAPS.

However, even without the async PBO read, there would be no reason for FRAPS to use a sync object. glReadPixels (...) and commands like it will implicitly wait for all pending commands to finish before reading the results and returning control to the CPU. It would really hurt performance, but GL would automatically do the synchronization.


The simplest use-case for sync objects is two or more render contexts running simultaneously.

In OpenGL you can share certain resources (including sync objects) across contexts, but the command stream for each context is completely separate and no synchronization of any sort is enforced. Thus, if you were to upload data to a vertex buffer in one context and use it in another, you would insert a fence sync in the producer (upload context) and wait for it to be signaled in the consumer (draw context). This will ensure that the draw command does not occur until the upload is finished - if the commands were all issued from the same context, GL would actually guarantee this without the use of a sync object.

The example I just gave does not require CPU-GPU synchronization (only GPU-GPU), but you can use glClientWaitSync (...) to block your calling thread until the upload is finished if you had a situation where CPU-GPU made sense.


Here is some pseudo-code to evaluate the effectiveness of a sync object:

Thread 1:

glBindBuffer    (GL_ARRAY_BUFFER, vbo);
glBufferSubData (GL_ARRAY_BUFFER, 0, 4096*4096, foo); // Upload a 16 MiB buffer

GLsync ready =
   glFenceSync  (GL_SYNC_GPU_COMMANDS_COMPLETE​, 0);

Thread 0:

glBindBuffer (GL_ARRAY_BUFFER, vbo);

// Try with and without synchronization
if (sync) {
  // Wait up to 1 second for the upload to finish
  glClientWaitSync (ready, GL_SYNC_FLUSH_COMMANDS_BIT, 1000000000UL);
}

// Ordinarily mapping a buffer would wait for everything else to finish,
//   we need to eliminate that behavior (GL_MAP_UNSYNCHRONIZED_BIT) for this test.
void* bar = 
  glMapBufferRange (GL_ARRAY_BUFFER, 0, 4096*4096, GL_MAP_UNSYNCHRONIZED_BIT​);

// When `sync` is true and the sync object is working, bar should be identical to foo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Proper package naming for testing with the Go language

From Dev

How should unit testing work with external resources? What is proper approach?

From Dev

Symfony2 + Functional Testing "DataFixtures load how set the proper order"

From Dev

proper handling of LibGDX AssetManager

From Dev

Testing write speed: ArangoDB...Sync and MSync times

From Dev

What's the proper approach to testing controllers in Laravel?

From Dev

Proper unit testing with PostSharp

From Dev

Android Testing - Cannot set the proper config

From Dev

JavaScript proper prototypical inheritance

From Dev

Testing EF async methods with sync methods with MOQ

From Dev

Proper indentation of Bash script

From Dev

Proper way to maintain database known state by rolling back transactions in NUnit, Sql Server and UI Testing

From Dev

Proper way to sync a wpf progress bar with function from a library

From Dev

Proper POST file upload (load testing with Locust)

From Dev

Proper solution

From Dev

What is a proper way of end-to-end (e2e) testing in Vue.js

From Dev

How to manually trigger a background sync (for testing)?

From Dev

proper vueJS way to sync props with data

From Dev

What is the proper way of testing throttling in DRF?

From Dev

Proper way of using and testing generated mapper

From Dev

How should unit testing work with external resources? What is proper approach?

From Dev

What's the proper approach to testing controllers in Laravel?

From Dev

Integration Testing or Unit Testing?

From Dev

Proper solution

From Dev

testing NTP for time sync between nodes in a local network

From Dev

Proper Unit testing with large projects

From Dev

Proper unit testing in Visual Studio

From Dev

Testing multicast - not getting proper results

From Dev

Unit testing and Integration testing

Related Related

  1. 1

    Proper package naming for testing with the Go language

  2. 2

    How should unit testing work with external resources? What is proper approach?

  3. 3

    Symfony2 + Functional Testing "DataFixtures load how set the proper order"

  4. 4

    proper handling of LibGDX AssetManager

  5. 5

    Testing write speed: ArangoDB...Sync and MSync times

  6. 6

    What's the proper approach to testing controllers in Laravel?

  7. 7

    Proper unit testing with PostSharp

  8. 8

    Android Testing - Cannot set the proper config

  9. 9

    JavaScript proper prototypical inheritance

  10. 10

    Testing EF async methods with sync methods with MOQ

  11. 11

    Proper indentation of Bash script

  12. 12

    Proper way to maintain database known state by rolling back transactions in NUnit, Sql Server and UI Testing

  13. 13

    Proper way to sync a wpf progress bar with function from a library

  14. 14

    Proper POST file upload (load testing with Locust)

  15. 15

    Proper solution

  16. 16

    What is a proper way of end-to-end (e2e) testing in Vue.js

  17. 17

    How to manually trigger a background sync (for testing)?

  18. 18

    proper vueJS way to sync props with data

  19. 19

    What is the proper way of testing throttling in DRF?

  20. 20

    Proper way of using and testing generated mapper

  21. 21

    How should unit testing work with external resources? What is proper approach?

  22. 22

    What's the proper approach to testing controllers in Laravel?

  23. 23

    Integration Testing or Unit Testing?

  24. 24

    Proper solution

  25. 25

    testing NTP for time sync between nodes in a local network

  26. 26

    Proper Unit testing with large projects

  27. 27

    Proper unit testing in Visual Studio

  28. 28

    Testing multicast - not getting proper results

  29. 29

    Unit testing and Integration testing

HotTag

Archive