| 8 | #include "shaders/Utils.hpp" |
| 9 | |
| 10 | TEST(TestSpecializationConstants, TestTwoConstants) |
| 11 | { |
| 12 | { |
| 13 | std::string shader(R"( |
| 14 | #version 450 |
| 15 | layout (constant_id = 0) const float cOne = 1; |
| 16 | layout (constant_id = 1) const float cTwo = 1; |
| 17 | layout (local_size_x = 1) in; |
| 18 | layout(set = 0, binding = 0) buffer a { float pa[]; }; |
| 19 | layout(set = 0, binding = 1) buffer b { float pb[]; }; |
| 20 | void main() { |
| 21 | uint index = gl_GlobalInvocationID.x; |
| 22 | pa[index] = cOne; |
| 23 | pb[index] = cTwo; |
| 24 | })"); |
| 25 | |
| 26 | std::vector<uint32_t> spirv = compileSource(shader); |
| 27 | |
| 28 | std::shared_ptr<kp::Sequence> sq = nullptr; |
| 29 | |
| 30 | { |
| 31 | kp::Manager mgr; |
| 32 | |
| 33 | std::shared_ptr<kp::TensorT<float>> tensorA = |
| 34 | mgr.tensor({ 0, 0, 0 }); |
| 35 | std::shared_ptr<kp::TensorT<float>> tensorB = |
| 36 | mgr.tensor({ 0, 0, 0 }); |
| 37 | |
| 38 | std::vector<std::shared_ptr<kp::Tensor>> params = { tensorA, |
| 39 | tensorB }; |
| 40 | |
| 41 | std::vector<float> spec = std::vector<float>({ 5.0, 0.3 }); |
| 42 | |
| 43 | std::shared_ptr<kp::Algorithm> algo = |
| 44 | mgr.algorithm(params, spirv, {}, spec); |
| 45 | |
| 46 | sq = mgr.sequence() |
| 47 | ->record<kp::OpTensorSyncDevice>(params) |
| 48 | ->record<kp::OpAlgoDispatch>(algo) |
| 49 | ->record<kp::OpTensorSyncLocal>(params) |
| 50 | ->eval(); |
| 51 | |
| 52 | EXPECT_EQ(tensorA->vector(), std::vector<float>({ 5, 5, 5 })); |
| 53 | EXPECT_EQ(tensorB->vector(), std::vector<float>({ 0.3, 0.3, 0.3 })); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | TEST(TestSpecializationConstants, TestConstantsInt) |
| 59 | { |