| 8 | #include "shaders/Utils.hpp" |
| 9 | |
| 10 | TEST(TestPushConstants, TestConstantsAlgoDispatchOverride) |
| 11 | { |
| 12 | { |
| 13 | std::string shader(R"( |
| 14 | #version 450 |
| 15 | layout(push_constant) uniform PushConstants { |
| 16 | float x; |
| 17 | float y; |
| 18 | float z; |
| 19 | } pcs; |
| 20 | layout (local_size_x = 1) in; |
| 21 | layout(set = 0, binding = 0) buffer a { float pa[]; }; |
| 22 | void main() { |
| 23 | pa[0] += pcs.x; |
| 24 | pa[1] += pcs.y; |
| 25 | pa[2] += pcs.z; |
| 26 | })"); |
| 27 | |
| 28 | std::vector<uint32_t> spirv = compileSource(shader); |
| 29 | |
| 30 | std::shared_ptr<kp::Sequence> sq = nullptr; |
| 31 | |
| 32 | { |
| 33 | kp::Manager mgr; |
| 34 | |
| 35 | std::shared_ptr<kp::TensorT<float>> tensor = |
| 36 | mgr.tensor({ 0, 0, 0 }); |
| 37 | |
| 38 | std::shared_ptr<kp::Algorithm> algo = mgr.algorithm( |
| 39 | { tensor }, spirv, kp::Workgroup({ 1 }), {}, { 0.0, 0.0, 0.0 }); |
| 40 | |
| 41 | sq = mgr.sequence()->eval<kp::OpTensorSyncDevice>({ tensor }); |
| 42 | |
| 43 | // We need to run this in sequence to avoid race condition |
| 44 | // We can't use atomicAdd as swiftshader doesn't support it for |
| 45 | // float |
| 46 | sq->eval<kp::OpAlgoDispatch>(algo, |
| 47 | std::vector<float>{ 0.1, 0.2, 0.3 }); |
| 48 | sq->eval<kp::OpAlgoDispatch>(algo, |
| 49 | std::vector<float>{ 0.3, 0.2, 0.1 }); |
| 50 | sq->eval<kp::OpTensorSyncLocal>({ tensor }); |
| 51 | |
| 52 | EXPECT_EQ(tensor->vector(), std::vector<float>({ 0.4, 0.4, 0.4 })); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride) |
| 58 | { |
nothing calls this directly
no test coverage detected