From f9fbe0efbedc1a261a4606b569a1c9d03413bfc2 Mon Sep 17 00:00:00 2001 From: Try Date: Sun, 21 Apr 2024 12:37:51 +0200 Subject: [PATCH] + image atomic test #59 --- Tests/shader/image_atomic_test.comp | 11 +++++++++ Tests/tests/CMakeLists.txt | 1 + Tests/tests/gapi/directx_test.cpp | 6 +++++ Tests/tests/gapi/gapi_test_common.h | 37 +++++++++++++++++++++++++++++ Tests/tests/gapi/vulkan_test.cpp | 6 +++++ 5 files changed, 61 insertions(+) create mode 100644 Tests/shader/image_atomic_test.comp diff --git a/Tests/shader/image_atomic_test.comp b/Tests/shader/image_atomic_test.comp new file mode 100644 index 00000000..44220452 --- /dev/null +++ b/Tests/shader/image_atomic_test.comp @@ -0,0 +1,11 @@ +#version 450 + +layout (binding=0, r32ui) uniform uimage2D image; + +void main() { + ivec2 index = ivec2(gl_GlobalInvocationID.xy); + vec3 color = vec3(index, 0.0) / vec3(128,128,0); + + uint bits = packUnorm4x8(vec4(color,1.0)); + imageAtomicMax(image, index, bits); + } diff --git a/Tests/tests/CMakeLists.txt b/Tests/tests/CMakeLists.txt index 6e2753d5..e6cf1ea2 100644 --- a/Tests/tests/CMakeLists.txt +++ b/Tests/tests/CMakeLists.txt @@ -73,6 +73,7 @@ compile_shader(simple_test.vert) compile_shader(simple_test.frag) compile_shader(simple_test.comp) compile_shader(image_store_test.comp) +compile_shader(image_atomic_test.comp) compile_shader(ssbo_read.comp) compile_shader(ssbo_zero_length.comp) compile_shader(overlap_test.comp) diff --git a/Tests/tests/gapi/directx_test.cpp b/Tests/tests/gapi/directx_test.cpp index 08b319f4..e07414d6 100644 --- a/Tests/tests/gapi/directx_test.cpp +++ b/Tests/tests/gapi/directx_test.cpp @@ -153,6 +153,12 @@ TEST(DirectX12Api,ComputeImage) { #endif } +TEST(DirectX12Api,AtomicImage) { +#if defined(_MSC_VER) + GapiTestCommon::AtomicImage("DirectX12Api_AtomicImage.png"); +#endif + } + TEST(DirectX12Api,DispathToDraw) { #if defined(_MSC_VER) GapiTestSync::DispathToDraw("DirectX12Api_DispathToDraw.png"); diff --git a/Tests/tests/gapi/gapi_test_common.h b/Tests/tests/gapi/gapi_test_common.h index 4015cf9e..d404ac95 100644 --- a/Tests/tests/gapi/gapi_test_common.h +++ b/Tests/tests/gapi/gapi_test_common.h @@ -953,6 +953,43 @@ void ComputeImage(const char* outImage) { } } +template +void AtomicImage(const char* outImage) { + using namespace Tempest; + + try { + GraphicsApi api{ApiFlags::Validation}; + Device device(api); + + auto img = device.image2d(TextureFormat::R32U,128,128,false); + auto pso = device.pipeline(device.shader("shader/image_atomic_test.comp.sprv")); + + auto ubo = device.descriptors(pso.layout()); + ubo.set(0,img); + + auto cmd = device.commandBuffer(); + { + auto enc = cmd.startEncoding(device); + enc.setUniforms(pso,ubo); + enc.dispatch(img.w(),img.h(),1); + } + + auto sync = device.fence(); + device.submit(cmd,sync); + sync.wait(); + + auto pm = device.readPixels(img); + auto rgb = Pixmap(pm.w(), pm.h(), TextureFormat::RGBA8); + std::memcpy(rgb.data(), pm.data(), pm.w()*pm.h()*sizeof(uint32_t)); + rgb.save(outImage); + } + catch(std::system_error& e) { + if(e.code()==Tempest::GraphicsErrc::NoDevice) + Log::d("Skipping graphics testcase: ", e.what()); else + throw; + } + } + template void MipMaps(const char* outImage) { using namespace Tempest; diff --git a/Tests/tests/gapi/vulkan_test.cpp b/Tests/tests/gapi/vulkan_test.cpp index d7c88644..a2663f1c 100644 --- a/Tests/tests/gapi/vulkan_test.cpp +++ b/Tests/tests/gapi/vulkan_test.cpp @@ -153,6 +153,12 @@ TEST(VulkanApi,ComputeImage) { #endif } +TEST(VulkanApi,AtomicImage) { +#if !defined(__OSX__) + GapiTestCommon::AtomicImage("VulkanApi_AtomicImage.png"); +#endif + } + TEST(VulkanApi,DispathToDraw) { #if !defined(__OSX__) GapiTestSync::DispathToDraw("VulkanApi_DispathToDraw.png");