upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/test/shaders/cs_f64_add.asm10
-rw-r--r--runtime/test/vk_compute_test.cpp10
-rw-r--r--runtime/test/vk_shader_fma.h8
-rw-r--r--scripts/run_gpu_tests.py8
4 files changed, 30 insertions, 6 deletions
diff --git a/runtime/test/shaders/cs_f64_add.asm b/runtime/test/shaders/cs_f64_add.asm
new file mode 100644
index 000000000..4dbba4123
--- /dev/null
+++ b/runtime/test/shaders/cs_f64_add.asm
@@ -0,0 +1,10 @@
1; group: 1,1,1
2; Store binary64 (0.75 + 0.5) * 2 = 2.5 as low/high words: 0x00000000, 0x40040000.
3v_mov_b32 v0, 0
4v_mov_b32 v1, 0x3fe80000
5v_mov_b32 v2, 0
6v_mov_b32 v3, 0x3fe00000
7v_add_f64 v[4:5], v[0:1], v[2:3] mul:2
8v_mov_b32 v6, 0
9buffer_store_dwordx2 v[4:5], v6, s[0:3], 0 offen
10s_endpgm
diff --git a/runtime/test/vk_compute_test.cpp b/runtime/test/vk_compute_test.cpp
index 0c02f1a62..f0f7c4605 100644
--- a/runtime/test/vk_compute_test.cpp
+++ b/runtime/test/vk_compute_test.cpp
@@ -153,6 +153,13 @@ int main(int argc, char** argv) {
153 std::fprintf(stderr, "full 64-wide compute subgroups unavailable\n"); 153 std::fprintf(stderr, "full 64-wide compute subgroups unavailable\n");
154 return 77; 154 return 77;
155 } 155 }
156 std::ifstream f(argv[1], std::ios::binary);
157 std::vector<char> code((std::istreambuf_iterator<char>(f)), {});
158 const bool needs_float64 = leonida::vk_test::spirv_declares_capability(code.data(), code.size(), 10); // Float64
159 if (needs_float64 && !f2q.features.shaderFloat64) {
160 std::fprintf(stderr, "unsupported: %s uses Float64 and the device has no shaderFloat64\n", argv[1]);
161 return 77;
162 }
156 VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; 163 VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES};
157 VkPhysicalDeviceVulkan12Features f12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; 164 VkPhysicalDeviceVulkan12Features f12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES};
158 f12.bufferDeviceAddress = VK_TRUE; 165 f12.bufferDeviceAddress = VK_TRUE;
@@ -163,6 +170,7 @@ int main(int argc, char** argv) {
163 } 170 }
164 VkPhysicalDeviceFeatures2 f2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; 171 VkPhysicalDeviceFeatures2 f2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
165 f2.features.shaderInt64 = VK_TRUE; 172 f2.features.shaderInt64 = VK_TRUE;
173 f2.features.shaderFloat64 = needs_float64;
166 f2.pNext = &f12; 174 f2.pNext = &f12;
167 // OpFmaKHR (rdna2spirv.py --fma khr): VK_KHR_shader_fma, when the device has it. 175 // OpFmaKHR (rdna2spirv.py --fma khr): VK_KHR_shader_fma, when the device has it.
168 leonida::vk_test::ShaderFma fma; 176 leonida::vk_test::ShaderFma fma;
@@ -229,8 +237,6 @@ int main(int argc, char** argv) {
229 bai.buffer = buf; 237 bai.buffer = buf;
230 const uint64_t heap = vkGetBufferDeviceAddress(dev, &bai); 238 const uint64_t heap = vkGetBufferDeviceAddress(dev, &bai);
231 239
232 std::ifstream f(argv[1], std::ios::binary);
233 std::vector<char> code((std::istreambuf_iterator<char>(f)), {});
234 if (!fma.accepts(code.data(), code.size(), argv[1])) return 77; 240 if (!fma.accepts(code.data(), code.size(), argv[1])) return 77;
235 VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; 241 VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO};
236 smi.codeSize = code.size(); smi.pCode = reinterpret_cast<const uint32_t*>(code.data()); 242 smi.codeSize = code.size(); smi.pCode = reinterpret_cast<const uint32_t*>(code.data());
diff --git a/runtime/test/vk_shader_fma.h b/runtime/test/vk_shader_fma.h
index e66884f97..a740859dc 100644
--- a/runtime/test/vk_shader_fma.h
+++ b/runtime/test/vk_shader_fma.h
@@ -21,14 +21,14 @@ inline constexpr bool shader_fma_in_headers = true;
21inline constexpr bool shader_fma_in_headers = false; 21inline constexpr bool shader_fma_in_headers = false;
22#endif 22#endif
23 23
24// OpCapability (17) FMAKHR (6030; spirv/unified1/spirv.h). 24// Find OpCapability (17) in a binary module.
25inline bool spirv_needs_fma(const void* data, std::size_t bytes) { 25inline bool spirv_declares_capability(const void* data, std::size_t bytes, std::uint32_t capability) {
26 if (bytes < 20 || bytes % 4) return false; 26 if (bytes < 20 || bytes % 4) return false;
27 std::vector<std::uint32_t> words(bytes / 4); 27 std::vector<std::uint32_t> words(bytes / 4);
28 std::memcpy(words.data(), data, bytes); 28 std::memcpy(words.data(), data, bytes);
29 for (std::size_t i = 5; i < words.size() && (words[i] >> 16);) { 29 for (std::size_t i = 5; i < words.size() && (words[i] >> 16);) {
30 const std::uint32_t op = words[i] & 0xffff, count = words[i] >> 16; 30 const std::uint32_t op = words[i] & 0xffff, count = words[i] >> 16;
31 if (op == 17 && count == 2 && i + 1 < words.size() && words[i + 1] == 6030) return true; 31 if (op == 17 && count == 2 && i + 1 < words.size() && words[i + 1] == capability) return true;
32 i += count; 32 i += count;
33 } 33 }
34 return false; 34 return false;
@@ -93,7 +93,7 @@ struct ShaderFma {
93 // True when the module can be used: it does not need FMAKHR, or the device enables shaderFmaFloat32. 93 // True when the module can be used: it does not need FMAKHR, or the device enables shaderFmaFloat32.
94 // Otherwise says so and the caller returns 77. 94 // Otherwise says so and the caller returns 77.
95 bool accepts(const void* code, std::size_t bytes, const char* name) const { 95 bool accepts(const void* code, std::size_t bytes, const char* name) const {
96 if (float32 || !spirv_needs_fma(code, bytes)) return true; 96 if (float32 || !spirv_declares_capability(code, bytes, 6030)) return true; // FMAKHR
97 std::fprintf(stderr, "unsupported: %s needs OpFmaKHR (VK_KHR_shader_fma, shaderFmaFloat32) and the device " 97 std::fprintf(stderr, "unsupported: %s needs OpFmaKHR (VK_KHR_shader_fma, shaderFmaFloat32) and the device "
98 "lacks it; translate with --fma glsl\n", name); 98 "lacks it; translate with --fma glsl\n", name);
99 return false; 99 return false;
diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py
index 8fdce77d8..a21cfbffd 100644
--- a/scripts/run_gpu_tests.py
+++ b/scripts/run_gpu_tests.py
@@ -875,6 +875,14 @@ def run_suite(a, work: str) -> int:
875 vals = words[:len(USER_SGPRS_WORDS)] if words else [] 875 vals = words[:len(USER_SGPRS_WORDS)] if words else []
876 results.append((name, rc == 0 and vals == USER_SGPRS_WORDS, 876 results.append((name, rc == 0 and vals == USER_SGPRS_WORDS,
877 " ".join(hex(x) for x in vals) if vals else msg)) 877 " ".join(hex(x) for x in vals) if vals else msg))
878 elif name == "cs_f64_add":
879 rc, msg = run_cmd([vk_compute, spv, "1", "dump"], env=cs_env)
880 if rc == 77:
881 results.append((name, None, "SKIP (no shaderFloat64 on this device)"))
882 else:
883 ok, detail = judge_cs_dump(rc, msg, [0, 0x40040000], wave64=False, partial=False, emulated=False,
884 hexwords=True)
885 results.append((name, ok, detail))
878 elif name == "cs_cvt_f32_sat": 886 elif name == "cs_cvt_f32_sat":
879 # #300's saturating float -> int conversions: one dispatch per input word in s4 (VKC_SGPRS). 887 # #300's saturating float -> int conversions: one dispatch per input word in s4 (VKC_SGPRS).
880 wrong = [] 888 wrong = []