Skip to content

Commit

Permalink
+ image atomic test
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Apr 21, 2024
1 parent 3a5a69e commit f9fbe0e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Tests/shader/image_atomic_test.comp
Original file line number Diff line number Diff line change
@@ -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);
}
1 change: 1 addition & 0 deletions Tests/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions Tests/tests/gapi/directx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ TEST(DirectX12Api,ComputeImage) {
#endif
}

TEST(DirectX12Api,AtomicImage) {
#if defined(_MSC_VER)
GapiTestCommon::AtomicImage<DirectX12Api>("DirectX12Api_AtomicImage.png");
#endif
}

TEST(DirectX12Api,DispathToDraw) {
#if defined(_MSC_VER)
GapiTestSync::DispathToDraw<DirectX12Api>("DirectX12Api_DispathToDraw.png");
Expand Down
37 changes: 37 additions & 0 deletions Tests/tests/gapi/gapi_test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,43 @@ void ComputeImage(const char* outImage) {
}
}

template<class GraphicsApi>
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<class GraphicsApi, Tempest::TextureFormat format>
void MipMaps(const char* outImage) {
using namespace Tempest;
Expand Down
6 changes: 6 additions & 0 deletions Tests/tests/gapi/vulkan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ TEST(VulkanApi,ComputeImage) {
#endif
}

TEST(VulkanApi,AtomicImage) {
#if !defined(__OSX__)
GapiTestCommon::AtomicImage<VulkanApi>("VulkanApi_AtomicImage.png");
#endif
}

TEST(VulkanApi,DispathToDraw) {
#if !defined(__OSX__)
GapiTestSync::DispathToDraw<VulkanApi>("VulkanApi_DispathToDraw.png");
Expand Down

0 comments on commit f9fbe0e

Please sign in to comment.