Harbor

Changelog f68de9cedde9

pin handle index helper

@sky · 1 month ago · parent 61c62485f56f
0 added 2 modified 0 deleted
gpu/backend/backend.odin +8 -0 modified
71 unchanged lines hidden
72 72 return size == 0 || size <= caps.max_push_constant_size
73 73 }
74 74
75 + handle_index :: proc(handle: $T, max_count: int) -> (int, bool) {
76 + idx := int(u64(handle))
77 + if idx <= 0 || idx >= max_count {
78 + return 0, false
79 + }
80 + return idx, true
81 + }
82 +
75 83 // --- Surface descriptors ---
76 84
77 85 Surface_Kind :: enum {
462 unchanged lines hidden
gpu/tests/capabilities_test.odin +16 -0 modified
45 unchanged lines hidden
46 46 }
47 47
48 48 @(test)
49 + test_backend_handle_index_rejects_null_and_out_of_range :: proc(t: ^testing.T) {
50 + _, null_ok := bk.handle_index(bk.NULL_BUFFER, 8)
51 + testing.expect(t, !null_ok)
52 +
53 + idx, valid_ok := bk.handle_index(bk.Buffer_Handle(1), 8)
54 + testing.expect(t, valid_ok)
55 + testing.expect_value(t, idx, 1)
56 +
57 + _, max_ok := bk.handle_index(bk.Buffer_Handle(8), 8)
58 + testing.expect(t, !max_ok)
59 +
60 + _, overflow_ok := bk.handle_index(bk.Texture_Handle(99), 8)
61 + testing.expect(t, !overflow_ok)
62 + }
63 +
64 + @(test)
49 65 test_backend_vtable_rejects_missing_required_slots :: proc(t: ^testing.T) {
50 66 testing.expect(t, !bk.backend_vtable_is_complete(nil))
51 67 backend: bk.Backend
2 unchanged lines hidden