diff --git a/util/test/data/GL_Buffer_Updates/backbuffer.png b/util/test/data/GL_Buffer_Updates/backbuffer.png new file mode 100644 index 000000000..eb21d64ff Binary files /dev/null and b/util/test/data/GL_Buffer_Updates/backbuffer.png differ diff --git a/util/test/demos/gl/gl_buffer_updates.cpp b/util/test/demos/gl/gl_buffer_updates.cpp index 249b7b709..f3a5e1e09 100644 --- a/util/test/demos/gl/gl_buffer_updates.cpp +++ b/util/test/demos/gl/gl_buffer_updates.cpp @@ -297,15 +297,19 @@ void main() ptr = (Vec4f *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(Vec4f), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); - memcpy(ptr, &green, sizeof(Vec4f)); + if(ptr) + memcpy(ptr, &green, sizeof(Vec4f)); glUnmapBuffer(GL_UNIFORM_BUFFER); glBindBuffer(GL_UNIFORM_BUFFER, buffers[CleanBufferMapWriteNonInvalidate]); glBufferData(GL_UNIFORM_BUFFER, sizeof(Vec4f), &red, GL_DYNAMIC_DRAW); ptr = (Vec4f *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(Vec4f), GL_MAP_WRITE_BIT); - ptr->x = 0.0f; - ptr->y = 1.0f; + if(ptr) + { + ptr->x = 0.0f; + ptr->y = 1.0f; + } glUnmapBuffer(GL_UNIFORM_BUFFER); glBindBuffer(GL_UNIFORM_BUFFER, buffers[DirtyBufferMapWriteInvalidate]); @@ -313,15 +317,19 @@ void main() ptr = (Vec4f *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(Vec4f), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); - memcpy(ptr, &green, sizeof(Vec4f)); + if(ptr) + memcpy(ptr, &green, sizeof(Vec4f)); glUnmapBuffer(GL_UNIFORM_BUFFER); glBindBuffer(GL_UNIFORM_BUFFER, buffers[DirtyBufferMapWriteNonInvalidate]); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(Vec4f), &red); ptr = (Vec4f *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(Vec4f), GL_MAP_WRITE_BIT); - ptr->x = 0.0f; - ptr->y = 1.0f; + if(ptr) + { + ptr->x = 0.0f; + ptr->y = 1.0f; + } glUnmapBuffer(GL_UNIFORM_BUFFER); glBindBuffer(GL_UNIFORM_BUFFER, buffers[CleanBufferMapFlushExplicit]); @@ -329,25 +337,35 @@ void main() ptr = (Vec4f *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(Vec4f), GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); - ptr->x = 0.0f; - ptr->y = 1.0f; + if(ptr) + { + ptr->x = 0.0f; + ptr->y = 1.0f; + } glFlushMappedBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(float) * 2); glUnmapBuffer(GL_UNIFORM_BUFFER); glBindBuffer(GL_UNIFORM_BUFFER, buffers[DirtyBufferMapFlushExplicit]); ptr = (Vec4f *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(Vec4f), GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); - ptr->x = 0.0f; - ptr->y = 1.0f; + if(ptr) + { + ptr->x = 0.0f; + ptr->y = 1.0f; + } glFlushMappedBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(float) * 2); glUnmapBuffer(GL_UNIFORM_BUFFER); - memcpy(ptrs[CoherentMapWrite], &red, sizeof(Vec4f)); - memcpy(ptrs[CoherentMapWriteInvalidateRange], &red, sizeof(Vec4f)); - memcpy(ptrs[CoherentMapWriteInvalidateBuffer], &red, sizeof(Vec4f)); + if(ptrs[CoherentMapWrite]) + memcpy(ptrs[CoherentMapWrite], &red, sizeof(Vec4f)); + if(ptrs[CoherentMapWriteInvalidateRange]) + memcpy(ptrs[CoherentMapWriteInvalidateRange], &red, sizeof(Vec4f)); + if(ptrs[CoherentMapWriteInvalidateBuffer]) + memcpy(ptrs[CoherentMapWriteInvalidateBuffer], &red, sizeof(Vec4f)); glBindBuffer(GL_UNIFORM_BUFFER, buffers[NonCoherentMapFlush]); - memcpy(ptrs[NonCoherentMapFlush], &red, sizeof(Vec4f)); + if(ptrs[NonCoherentMapFlush]) + memcpy(ptrs[NonCoherentMapFlush], &red, sizeof(Vec4f)); glFlushMappedBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(float) * 4); glBindBuffer(GL_UNIFORM_BUFFER, buffers[OffsetMapWrite]); @@ -355,7 +373,8 @@ void main() ptr = (Vec4f *)glMapBufferRange(GL_UNIFORM_BUFFER, sizeof(float) * 2, sizeof(float), GL_MAP_WRITE_BIT); - ptr->x = 0.0f; + if(ptr) + ptr->x = 0.0f; glUnmapBuffer(GL_UNIFORM_BUFFER); glBindBuffer(GL_UNIFORM_BUFFER, buffers[OffsetMapFlush]); @@ -363,7 +382,8 @@ void main() ptr = (Vec4f *)glMapBufferRange(GL_UNIFORM_BUFFER, sizeof(float) * 2, sizeof(float), GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); - ptr->x = 0.0f; + if(ptr) + ptr->x = 0.0f; glFlushMappedBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(float)); glUnmapBuffer(GL_UNIFORM_BUFFER); @@ -382,12 +402,16 @@ void main() if(buf == CoherentMapWrite || buf == CoherentMapWriteInvalidateRange || buf == CoherentMapWriteInvalidateBuffer) - memcpy(ptrs[buf], &green, sizeof(Vec4f)); + { + if(ptrs[buf]) + memcpy(ptrs[buf], &green, sizeof(Vec4f)); + } if(buf == NonCoherentMapFlush) { glBindBuffer(GL_UNIFORM_BUFFER, buffers[NonCoherentMapFlush]); - memcpy(ptrs[NonCoherentMapFlush], &green, sizeof(Vec4f)); + if(ptrs[NonCoherentMapFlush]) + memcpy(ptrs[NonCoherentMapFlush], &green, sizeof(Vec4f)); glFlushMappedBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(float) * 4); } diff --git a/util/test/tests/GL/GL_Buffer_Updates.py b/util/test/tests/GL/GL_Buffer_Updates.py new file mode 100644 index 000000000..3a3f6fe2f --- /dev/null +++ b/util/test/tests/GL/GL_Buffer_Updates.py @@ -0,0 +1,38 @@ +import rdtest +import renderdoc as rd + + +class GL_Buffer_Updates(rdtest.TestCase): + def get_capture(self): + return rdtest.run_and_capture("demos_x64", "GL_Buffer_Updates", 5) + + def check_capture(self): + self.check_final_backbuffer() + + # Open the capture and grab the thumbnail, check that it is all green too (dirty way of verifying we didn't + # break in-app updates but somehow end up with the right data) + cap = rd.OpenCaptureFile() + + # Open a particular file + status = cap.OpenFile(self.capture_filename, '', None) + + # Make sure the file opened successfully + if status != rd.ReplayStatus.Succeeded: + cap.Shutdown() + raise rdtest.TestFailureException("Couldn't open '{}': {}".format(self.capture_filename, str(status))) + + thumb: rd.Thumbnail = cap.GetThumbnail(rd.FileType.PNG, 0) + + tmp_path = rdtest.get_tmp_path('thumbnail.png') + + with open(tmp_path, 'wb') as f: + f.write(thumb.data) + + # The original thumbnail should also be identical, since we have the uncompressed extended thumbnail. + ref_path = self.get_ref_path('backbuffer.png') + + if not rdtest.png_compare(tmp_path, ref_path): + raise rdtest.TestFailureException("Reference backbuffer and thumbnail image differ", tmp_path, ref_path) + + rdtest.log.success("Thumbnail is identical to reference") +