From b594210c40c91c94e9c9912444cd376db359b232 Mon Sep 17 00:00:00 2001 From: Gorazd Sumkovski Date: Fri, 1 Nov 2024 12:24:19 +0000 Subject: [PATCH] Add test `multi_flag_creation` This tests that the `CL_COMMAND_BUFFER_FLAGS_KHR` bitfield is parsed correctly when multiple flags are set. Signed-off-by: Gorazd Sumkovski --- .../basic_command_buffer.cpp | 72 +++++++++++++++++++ .../extensions/cl_khr_command_buffer/main.cpp | 1 + .../extensions/cl_khr_command_buffer/procs.h | 2 + 3 files changed, 75 insertions(+) diff --git a/test_conformance/extensions/cl_khr_command_buffer/basic_command_buffer.cpp b/test_conformance/extensions/cl_khr_command_buffer/basic_command_buffer.cpp index 38baefcdec..90555cc33b 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/basic_command_buffer.cpp +++ b/test_conformance/extensions/cl_khr_command_buffer/basic_command_buffer.cpp @@ -180,6 +180,71 @@ cl_int BasicCommandBufferTest::SetUp(int elements) namespace { +// Test that the CL_COMMAND_BUFFER_FLAGS_KHR bitfield is parsed correctly when +// multiple flags are set. +struct MultiFlagCreationTest : public BasicCommandBufferTest +{ + using BasicCommandBufferTest::BasicCommandBufferTest; + + cl_int Run() override + { + cl_command_buffer_properties_khr flags = 0; + size_t num_flags_set = 0; + bool mutli_flags_supported = true; + cl_int error = CL_SUCCESS; + + // First try to find mutliple flags that are supported by the driver and + // device. + if (simultaneous_use_support) + { + flags |= CL_COMMAND_BUFFER_SIMULTANEOUS_USE_KHR; + num_flags_set++; + } + + if (device_side_enqueue_support) + { + flags |= CL_COMMAND_BUFFER_DEVICE_SIDE_SYNC_KHR; + num_flags_set++; + } + + if (is_extension_available( + device, CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_NAME)) + { + flags |= CL_COMMAND_BUFFER_MUTABLE_KHR; + num_flags_set++; + } + + // If we can't find mutliple supported flags, still set a bitfield but + // expect CL_INVALID_PROPERTY to be returned on creation. + if (num_flags_set < 2) + { + flags = CL_COMMAND_BUFFER_SIMULTANEOUS_USE_KHR + | CL_COMMAND_BUFFER_DEVICE_SIDE_SYNC_KHR; + + mutli_flags_supported = false; + } + + cl_command_buffer_properties_khr props[] = { + CL_COMMAND_BUFFER_FLAGS_KHR, flags, 0 + }; + + command_buffer = clCreateCommandBufferKHR(1, &queue, props, &error); + if (mutli_flags_supported) + { + test_error(error, "clCreateCommandBufferKHR failed"); + } + else + { + test_failure_error_ret( + error, CL_INVALID_PROPERTY, + "clCreateCommandBufferKHR should return CL_INVALID_PROPERTY", + TEST_FAIL); + } + + return CL_SUCCESS; + } +}; + // Test enqueuing a command-buffer containing a single NDRange command once struct BasicEnqueueTest : public BasicCommandBufferTest { @@ -424,6 +489,13 @@ struct InterleavedEnqueueTest : public BasicCommandBufferTest } // anonymous namespace +int test_multi_flag_creation(cl_device_id device, cl_context context, + cl_command_queue queue, int num_elements) +{ + return MakeAndRunTest(device, context, queue, + num_elements); +} + int test_single_ndrange(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements) { diff --git a/test_conformance/extensions/cl_khr_command_buffer/main.cpp b/test_conformance/extensions/cl_khr_command_buffer/main.cpp index ea8fddbe8b..93e1448ea5 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/main.cpp +++ b/test_conformance/extensions/cl_khr_command_buffer/main.cpp @@ -16,6 +16,7 @@ #include "harness/testHarness.h" test_definition test_list[] = { + ADD_TEST(multi_flag_creation), ADD_TEST(single_ndrange), ADD_TEST(interleaved_enqueue), ADD_TEST(mixed_commands), diff --git a/test_conformance/extensions/cl_khr_command_buffer/procs.h b/test_conformance/extensions/cl_khr_command_buffer/procs.h index b2bd7c6c62..2a1e199b44 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/procs.h +++ b/test_conformance/extensions/cl_khr_command_buffer/procs.h @@ -19,6 +19,8 @@ #include // Basic command-buffer tests +extern int test_multi_flag_creation(cl_device_id device, cl_context context, + cl_command_queue queue, int num_elements); extern int test_single_ndrange(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements); extern int test_interleaved_enqueue(cl_device_id device, cl_context context,