From d26ee22dd7faab1845a531d410f7ec1db407402a Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 11 Apr 2019 13:49:37 -0400 Subject: [PATCH] Unify buffer sizes. (#465) * Unify buffer sizes. Currently the format buffer and data buffer count their size differently. For data buffers we counted elements (so 1 vec4 was size 1) and format buffers counted values (so 1 vec4 was size 4). This CL unifies the two sizes and adds ElementCount and ValueCount to make it explicit which version the user wants. As part of this, the data types used for ssbo and uniform commands must be consistent. The tests where we switched data formats part way through are updated. * build fix --- docs/vk_script.md | 2 +- src/amber.cc | 2 +- src/amberscript/parser.cc | 11 +- src/amberscript/parser_bind_test.cc | 20 +- src/amberscript/parser_buffer_test.cc | 94 ++++++-- src/amberscript/parser_pipeline_test.cc | 10 +- src/buffer.cc | 226 +++++------------- src/buffer.h | 55 +++-- src/buffer_test.cc | 30 ++- src/command.h | 9 +- src/executor.cc | 2 +- src/format.cc | 23 ++ src/format.h | 40 ++++ src/pipeline.cc | 12 +- src/verifier.cc | 42 ++-- src/verifier.h | 4 +- src/verifier_test.cc | 66 +++-- src/vkscript/command_parser.cc | 69 ++++-- src/vkscript/command_parser_test.cc | 18 +- src/vkscript/parser_test.cc | 20 +- src/vulkan/buffer_descriptor.cc | 11 +- src/vulkan/buffer_descriptor.h | 3 +- src/vulkan/engine_vulkan.cc | 1 - src/vulkan/index_buffer.cc | 2 +- src/vulkan/pipeline.cc | 4 +- src/vulkan/push_constant.cc | 2 +- src/vulkan/vertex_buffer.h | 2 +- src/vulkan/vertex_buffer_test.cc | 105 +------- tests/cases/compute_mat2x2.vkscript | 24 -- tests/cases/compute_mat2x2float.vkscript | 51 ++++ tests/cases/compute_mat2x3.vkscript | 24 -- tests/cases/compute_mat2x3float.vkscript | 52 ++++ tests/cases/compute_mat3x2.vkscript | 35 --- tests/cases/compute_mat3x2float.vkscript | 60 +++++ tests/cases/compute_mat3x3.vkscript | 29 --- tests/cases/compute_mat3x3float.vkscript | 54 +++++ tests/cases/compute_mat3x4.vkscript | 30 --- tests/cases/compute_mat3x4float.vkscript | 56 +++++ tests/cases/compute_mat4x3.vkscript | 34 --- tests/cases/compute_mat4x3float.vkscript | 58 +++++ .../cases/compute_nothing_with_ssbo.vkscript | 11 +- tests/cases/compute_probe_mat3.vkscript | 10 +- .../cases/compute_push_const_mat2x2.vkscript | 25 -- .../compute_push_const_mat2x2float.vkscript | 52 ++++ .../cases/compute_push_const_mat2x3.vkscript | 25 -- .../compute_push_const_mat2x3float.vkscript | 52 ++++ .../cases/compute_push_const_mat3x2.vkscript | 35 --- .../compute_push_const_mat3x2float.vkscript | 60 +++++ .../cases/compute_push_const_mat3x3.vkscript | 29 --- .../compute_push_const_mat3x3float.vkscript | 54 +++++ .../cases/compute_push_const_mat3x4.vkscript | 30 --- .../compute_push_const_mat3x4float.vkscript | 56 +++++ .../cases/compute_push_const_mat4x3.vkscript | 34 --- .../compute_push_const_mat4x3float.vkscript | 58 +++++ .../compute_push_constant_and_ssbo.vkscript | 26 +- ...sbo_update_with_graphics_pipeline.vkscript | 18 +- ...escriptor_set_in_compute_pipeline.vkscript | 8 +- ...ubo_update_with_graphics_pipeline.vkscript | 14 +- ...mpute_with_multiple_ssbo_commands.vkscript | 4 +- .../cases/probe_no_compute_with_ssbo.vkscript | 2 +- 60 files changed, 1127 insertions(+), 868 deletions(-) create mode 100644 tests/cases/compute_mat2x2float.vkscript create mode 100644 tests/cases/compute_mat2x3float.vkscript create mode 100644 tests/cases/compute_mat3x2float.vkscript create mode 100644 tests/cases/compute_mat3x3float.vkscript create mode 100644 tests/cases/compute_mat3x4float.vkscript create mode 100644 tests/cases/compute_mat4x3float.vkscript create mode 100644 tests/cases/compute_push_const_mat2x2float.vkscript create mode 100644 tests/cases/compute_push_const_mat2x3float.vkscript create mode 100644 tests/cases/compute_push_const_mat3x2float.vkscript create mode 100644 tests/cases/compute_push_const_mat3x3float.vkscript create mode 100644 tests/cases/compute_push_const_mat3x4float.vkscript create mode 100644 tests/cases/compute_push_const_mat4x3float.vkscript diff --git a/docs/vk_script.md b/docs/vk_script.md index 509bb705a..da0960efa 100644 --- a/docs/vk_script.md +++ b/docs/vk_script.md @@ -225,7 +225,7 @@ multiple of the requested `type`. ### SSBO size * `ssbo _binding_ _size_` -Sets the size of the SSBO at `binding` to `size`. +Sets the number of elements in the SSBO at `binding` to `size`. ### SSBO subdata diff --git a/src/amber.cc b/src/amber.cc index 3de483ae0..feeabce79 100644 --- a/src/amber.cc +++ b/src/amber.cc @@ -216,7 +216,7 @@ amber::Result Amber::ExecuteWithShaderData(const amber::Recipe* recipe, const uint8_t* ptr = buffer->ValuePtr()->data(); auto& values = buffer_info.values; - for (size_t i = 0; i < buffer->GetSize(); ++i) { + for (size_t i = 0; i < buffer->GetSizeInBytes(); ++i) { values.emplace_back(); values.back().SetIntValue(*ptr); ++ptr; diff --git a/src/amberscript/parser.cc b/src/amberscript/parser.cc index 1784c9db7..b437bd13f 100644 --- a/src/amberscript/parser.cc +++ b/src/amberscript/parser.cc @@ -755,7 +755,7 @@ Result Parser::ParseBufferInitializerSize(DataBuffer* buffer) { return Result("BUFFER size invalid"); uint32_t size_in_items = token->AsUint32(); - buffer->SetSize(size_in_items); + buffer->SetElementCount(size_in_items); token = tokenizer_->NextToken(); if (!token->IsString()) @@ -877,10 +877,7 @@ Result Parser::ParseBufferInitializerData(DataBuffer* buffer) { values.emplace_back(v); } - uint32_t size_in_items = static_cast(values.size()) / - fmt->RowCount() / fmt->ColumnCount(); - buffer->SetSize(size_in_items); - + buffer->SetValueCount(static_cast(values.size())); buffer->SetData(std::move(values)); return ValidateEndOfStatement("BUFFER data command"); } @@ -1095,7 +1092,7 @@ Result Parser::ParseExpect() { if (buffer->GetBufferType() != buffer_2->GetBufferType()) return Result( "EXPECT EQ_BUFFER command cannot compare buffers of different type"); - if (buffer->GetSize() != buffer_2->GetSize()) + if (buffer->ElementCount() != buffer_2->ElementCount()) return Result( "EXPECT EQ_BUFFER command cannot compare buffers of different size"); if (buffer->GetWidth() != buffer_2->GetWidth()) @@ -1272,7 +1269,7 @@ Result Parser::ParseCopy() { buffer_to->SetBufferType(buffer_from->GetBufferType()); buffer_to->SetWidth(buffer_from->GetWidth()); buffer_to->SetHeight(buffer_from->GetHeight()); - buffer_to->SetSize(buffer_from->GetSize()); + buffer_to->SetElementCount(buffer_from->ElementCount()); } if (buffer_from->GetBufferType() != buffer_to->GetBufferType()) diff --git a/src/amberscript/parser_bind_test.cc b/src/amberscript/parser_bind_test.cc index 9bf72e8cd..9952dc66c 100644 --- a/src/amberscript/parser_bind_test.cc +++ b/src/amberscript/parser_bind_test.cc @@ -50,7 +50,8 @@ END)"; const auto& buf_info = color_buffers[0]; ASSERT_TRUE(buf_info.buffer != nullptr); EXPECT_EQ(0, buf_info.location); - EXPECT_EQ(250 * 250, buf_info.buffer->GetSize()); + EXPECT_EQ(250 * 250, buf_info.buffer->ElementCount()); + EXPECT_EQ(250 * 250 * 4, buf_info.buffer->ValueCount()); EXPECT_EQ(250 * 250 * 4 * sizeof(float), buf_info.buffer->GetSizeInBytes()); } @@ -318,7 +319,8 @@ END)"; const auto& buf1 = color_buffers1[0]; ASSERT_TRUE(buf1.buffer != nullptr); EXPECT_EQ(0, buf1.location); - EXPECT_EQ(90 * 180, buf1.buffer->GetSize()); + EXPECT_EQ(90 * 180, buf1.buffer->ElementCount()); + EXPECT_EQ(90 * 180 * 4, buf1.buffer->ValueCount()); EXPECT_EQ(90 * 180 * 4 * sizeof(float), buf1.buffer->GetSizeInBytes()); pipeline = pipelines[1].get(); @@ -326,8 +328,9 @@ END)"; const auto& buf2 = color_buffers2[0]; ASSERT_TRUE(buf2.buffer != nullptr); EXPECT_EQ(9, buf2.location); - EXPECT_EQ(256 * 300, buf2.buffer->GetSize()); - EXPECT_EQ(256 * 300 * sizeof(uint32_t), buf2.buffer->GetSizeInBytes()); + EXPECT_EQ(256 * 300, buf2.buffer->ElementCount()); + EXPECT_EQ(256 * 300 * 4, buf2.buffer->ValueCount()); + EXPECT_EQ(256 * 300 * 4 * sizeof(uint8_t), buf2.buffer->GetSizeInBytes()); } TEST_F(AmberScriptParserTest, BindColorFBSizeSetBeforeBuffer) { @@ -361,7 +364,8 @@ END)"; const auto& buf1 = color_buffers1[0]; ASSERT_TRUE(buf1.buffer != nullptr); EXPECT_EQ(0, buf1.location); - EXPECT_EQ(90 * 180, buf1.buffer->GetSize()); + EXPECT_EQ(90 * 180, buf1.buffer->ElementCount()); + EXPECT_EQ(90 * 180 * 4, buf1.buffer->ValueCount()); EXPECT_EQ(90 * 180 * 4 * sizeof(float), buf1.buffer->GetSizeInBytes()); } @@ -396,7 +400,8 @@ END)"; const auto& buf1 = color_buffers1[0]; ASSERT_TRUE(buf1.buffer != nullptr); EXPECT_EQ(0, buf1.location); - EXPECT_EQ(90 * 180, buf1.buffer->GetSize()); + EXPECT_EQ(90 * 180, buf1.buffer->ElementCount()); + EXPECT_EQ(90 * 180 * 4, buf1.buffer->ValueCount()); EXPECT_EQ(90 * 180 * 4 * sizeof(float), buf1.buffer->GetSizeInBytes()); } @@ -427,7 +432,8 @@ END)"; const auto* pipeline = pipelines[0].get(); const auto& buf = pipeline->GetDepthBuffer(); ASSERT_TRUE(buf.buffer != nullptr); - EXPECT_EQ(90 * 180, buf.buffer->GetSize()); + EXPECT_EQ(90 * 180, buf.buffer->ElementCount()); + EXPECT_EQ(90 * 180 * 4, buf.buffer->ValueCount()); EXPECT_EQ(90 * 180 * 4 * sizeof(float), buf.buffer->GetSizeInBytes()); } diff --git a/src/amberscript/parser_buffer_test.cc b/src/amberscript/parser_buffer_test.cc index 8dfc07afc..17cedcc48 100644 --- a/src/amberscript/parser_buffer_test.cc +++ b/src/amberscript/parser_buffer_test.cc @@ -40,12 +40,13 @@ END)"; auto* buffer = buffers[0].get(); EXPECT_TRUE(buffer->GetFormat()->IsUint32()); - EXPECT_EQ(7U, buffer->GetSize()); + EXPECT_EQ(7U, buffer->ElementCount()); + EXPECT_EQ(7U, buffer->ValueCount()); EXPECT_EQ(7U * sizeof(uint32_t), buffer->GetSizeInBytes()); std::vector results = {1, 2, 3, 4, 55, 99, 1234}; const auto* data = buffer->GetValues(); - ASSERT_EQ(results.size(), buffer->GetSize()); + ASSERT_EQ(results.size(), buffer->ValueCount()); for (size_t i = 0; i < results.size(); ++i) { EXPECT_EQ(results[i], data[i]); } @@ -67,12 +68,13 @@ TEST_F(AmberScriptParserTest, BufferDataOneLine) { auto* buffer = buffers[0].get(); EXPECT_TRUE(buffer->GetFormat()->IsUint32()); - EXPECT_EQ(4U, buffer->GetSize()); + EXPECT_EQ(4U, buffer->ElementCount()); + EXPECT_EQ(4U, buffer->ValueCount()); EXPECT_EQ(4U * sizeof(uint32_t), buffer->GetSizeInBytes()); std::vector results = {1, 2, 3, 4}; const auto* data = buffer->GetValues(); - ASSERT_EQ(results.size(), buffer->GetSize()); + ASSERT_EQ(results.size(), buffer->ValueCount()); for (size_t i = 0; i < results.size(); ++i) { EXPECT_EQ(results[i], data[i]); } @@ -95,12 +97,13 @@ TEST_F(AmberScriptParserTest, BufferDataFloat) { ASSERT_TRUE(buffers[0]->IsDataBuffer()); auto* buffer = buffers[0]->AsDataBuffer(); EXPECT_TRUE(buffer->GetDatumType().IsFloat()); - EXPECT_EQ(4U, buffer->GetSize()); + EXPECT_EQ(4U, buffer->ElementCount()); + EXPECT_EQ(4U, buffer->ValueCount()); EXPECT_EQ(4U * sizeof(float), buffer->GetSizeInBytes()); std::vector results = {1, 2, 3, 4}; const auto* data = buffer->GetValues(); - ASSERT_EQ(results.size(), buffer->GetSize()); + ASSERT_EQ(results.size(), buffer->ValueCount()); for (size_t i = 0; i < results.size(); ++i) { EXPECT_FLOAT_EQ(results[i], data[i]); } @@ -122,12 +125,13 @@ TEST_F(AmberScriptParserTest, BufferFill) { auto* buffer = buffers[0].get(); EXPECT_EQ("my_buffer", buffer->GetName()); EXPECT_TRUE(buffer->GetFormat()->IsUint8()); - EXPECT_EQ(5U, buffer->GetSize()); + EXPECT_EQ(5U, buffer->ElementCount()); + EXPECT_EQ(5U, buffer->ValueCount()); EXPECT_EQ(5U * sizeof(uint8_t), buffer->GetSizeInBytes()); std::vector results = {5, 5, 5, 5, 5}; const auto* data = buffer->GetValues(); - ASSERT_EQ(results.size(), buffer->GetSize()); + ASSERT_EQ(results.size(), buffer->ValueCount()); for (size_t i = 0; i < results.size(); ++i) { EXPECT_EQ(results[i], data[i]); } @@ -149,12 +153,13 @@ TEST_F(AmberScriptParserTest, BufferFillFloat) { auto* buffer = buffers[0].get(); EXPECT_EQ("my_buffer", buffer->GetName()); EXPECT_TRUE(buffer->GetFormat()->IsFloat()); - EXPECT_EQ(5U, buffer->GetSize()); + EXPECT_EQ(5U, buffer->ElementCount()); + EXPECT_EQ(5U, buffer->ValueCount()); EXPECT_EQ(5U * sizeof(float), buffer->GetSizeInBytes()); std::vector results = {5.2f, 5.2f, 5.2f, 5.2f, 5.2f}; const auto* data = buffer->GetValues(); - ASSERT_EQ(results.size(), buffer->GetSize()); + ASSERT_EQ(results.size(), buffer->ValueCount()); for (size_t i = 0; i < results.size(); ++i) { EXPECT_FLOAT_EQ(results[i], data[i]); } @@ -177,12 +182,13 @@ TEST_F(AmberScriptParserTest, BufferSeries) { auto* buffer = buffers[0].get(); EXPECT_EQ("my_buffer", buffer->GetName()); EXPECT_TRUE(buffer->GetFormat()->IsUint8()); - EXPECT_EQ(5U, buffer->GetSize()); + EXPECT_EQ(5U, buffer->ElementCount()); + EXPECT_EQ(5U, buffer->ValueCount()); EXPECT_EQ(5U * sizeof(uint8_t), buffer->GetSizeInBytes()); std::vector results = {2, 3, 4, 5, 6}; const auto* data = buffer->GetValues(); - ASSERT_EQ(results.size(), buffer->GetSize()); + ASSERT_EQ(results.size(), buffer->ValueCount()); for (size_t i = 0; i < results.size(); ++i) { EXPECT_EQ(results[i], data[i]); } @@ -206,12 +212,13 @@ TEST_F(AmberScriptParserTest, BufferSeriesFloat) { auto* buffer = buffers[0].get(); EXPECT_EQ("my_buffer", buffer->GetName()); EXPECT_TRUE(buffer->GetFormat()->IsFloat()); - EXPECT_EQ(5U, buffer->GetSize()); + EXPECT_EQ(5U, buffer->ElementCount()); + EXPECT_EQ(5U, buffer->ValueCount()); EXPECT_EQ(5U * sizeof(float), buffer->GetSizeInBytes()); std::vector results = {2.2f, 3.3f, 4.4f, 5.5f, 6.6f}; const auto* data = buffer->GetValues(); - ASSERT_EQ(results.size(), buffer->GetSize()); + ASSERT_EQ(results.size(), buffer->ValueCount()); for (size_t i = 0; i < results.size(); ++i) { EXPECT_FLOAT_EQ(results[i], data[i]); } @@ -238,12 +245,13 @@ END)"; auto* buffer = buffers[0].get(); EXPECT_EQ("color_buffer", buffer->GetName()); EXPECT_TRUE(buffer->GetFormat()->IsUint8()); - EXPECT_EQ(5U, buffer->GetSize()); + EXPECT_EQ(5U, buffer->ElementCount()); + EXPECT_EQ(5U, buffer->ValueCount()); EXPECT_EQ(5U * sizeof(uint8_t), buffer->GetSizeInBytes()); std::vector results0 = {5, 5, 5, 5, 5}; const auto* data0 = buffer->GetValues(); - ASSERT_EQ(results0.size(), buffer->GetSize()); + ASSERT_EQ(results0.size(), buffer->ValueCount()); for (size_t i = 0; i < results0.size(); ++i) { EXPECT_EQ(results0[i], data0[i]); } @@ -253,12 +261,13 @@ END)"; buffer = buffers[1].get(); EXPECT_EQ("storage_buffer", buffer->GetName()); EXPECT_TRUE(buffer->GetFormat()->IsUint32()); - EXPECT_EQ(7U, buffer->GetSize()); + EXPECT_EQ(7U, buffer->ElementCount()); + EXPECT_EQ(7U, buffer->ValueCount()); EXPECT_EQ(7U * sizeof(uint32_t), buffer->GetSizeInBytes()); std::vector results1 = {1, 2, 3, 4, 55, 99, 1234}; const auto* data1 = buffer->GetValues(); - ASSERT_EQ(results1.size(), buffer->GetSize()); + ASSERT_EQ(results1.size(), buffer->ValueCount()); for (size_t i = 0; i < results1.size(); ++i) { EXPECT_EQ(results1[i], data1[i]); } @@ -281,8 +290,9 @@ BUFFER my_index_buffer DATA_TYPE vec2 SIZE 5 FILL 2)"; auto* buffer = buffers[0].get(); EXPECT_EQ("my_index_buffer", buffer->GetName()); EXPECT_TRUE(buffer->GetFormat()->IsInt32()); - EXPECT_EQ(5U, buffer->GetSize()); - EXPECT_EQ(5U * 2 * sizeof(int32_t), buffer->GetSizeInBytes()); + EXPECT_EQ(5U, buffer->ElementCount()); + EXPECT_EQ(10U, buffer->ValueCount()); + EXPECT_EQ(10U * sizeof(int32_t), buffer->GetSizeInBytes()); std::vector results0 = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; const auto* data0 = buffer->GetValues(); @@ -314,8 +324,9 @@ END auto* buffer = buffers[0].get(); EXPECT_EQ("my_index_buffer", buffer->GetName()); EXPECT_TRUE(buffer->GetFormat()->IsInt32()); - EXPECT_EQ(4U, buffer->GetSize()); - EXPECT_EQ(4U * 2 * sizeof(int32_t), buffer->GetSizeInBytes()); + EXPECT_EQ(4U, buffer->ElementCount()); + EXPECT_EQ(8U, buffer->ValueCount()); + EXPECT_EQ(8U * sizeof(int32_t), buffer->GetSizeInBytes()); std::vector results0 = {2, 3, 4, 5, 6, 7, 8, 9}; const auto* data0 = buffer->GetValues(); @@ -324,6 +335,40 @@ END } } +TEST_F(AmberScriptParserTest, BufferDataStd140Resized) { + std::string in = R"( +BUFFER my_index_buffer DATA_TYPE vec3 DATA +2 3 3 +4 5 5 +6 7 7 +8 9 9 +END +)"; + + Parser parser; + Result r = parser.Parse(in); + ASSERT_TRUE(r.IsSuccess()) << r.Error(); + + auto script = parser.GetScript(); + const auto& buffers = script->GetBuffers(); + ASSERT_EQ(1U, buffers.size()); + + ASSERT_TRUE(buffers[0] != nullptr); + + auto* buffer = buffers[0].get(); + EXPECT_EQ("my_index_buffer", buffer->GetName()); + EXPECT_TRUE(buffer->GetFormat()->IsInt32()); + EXPECT_EQ(4U, buffer->ElementCount()); + EXPECT_EQ(12U, buffer->ValueCount()); + EXPECT_EQ(16U * sizeof(int32_t), buffer->GetSizeInBytes()); + + std::vector results0 = {2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 9}; + const auto* data0 = buffer->GetValues(); + for (size_t i = 0; i < results0.size(); ++i) { + EXPECT_EQ(results0[i], data0[i]); + } +} + TEST_F(AmberScriptParserTest, BufferDataHex) { std::string in = R"( BUFFER my_index_buffer DATA_TYPE uint32 DATA @@ -347,12 +392,13 @@ END auto* buffer = buffers[0].get(); EXPECT_EQ("my_index_buffer", buffer->GetName()); EXPECT_TRUE(buffer->GetFormat()->IsUint32()); - EXPECT_EQ(4U, buffer->GetSize()); + EXPECT_EQ(4U, buffer->ElementCount()); + EXPECT_EQ(4U, buffer->ValueCount()); EXPECT_EQ(4U * sizeof(uint32_t), buffer->GetSizeInBytes()); std::vector results0 = {4278190080, 16711680, 65280, 255}; const auto* data0 = buffer->GetValues(); - ASSERT_EQ(results0.size(), buffer->GetSize()); + ASSERT_EQ(results0.size(), buffer->ValueCount()); for (size_t i = 0; i < results0.size(); ++i) { EXPECT_EQ(results0[i], data0[i]); } diff --git a/src/amberscript/parser_pipeline_test.cc b/src/amberscript/parser_pipeline_test.cc index 69c45e584..6d1d91ab2 100644 --- a/src/amberscript/parser_pipeline_test.cc +++ b/src/amberscript/parser_pipeline_test.cc @@ -200,8 +200,9 @@ END)"; ASSERT_TRUE(buffer1->IsFormatBuffer()); EXPECT_EQ(FormatType::kB8G8R8A8_UNORM, buffer1->GetFormat()->GetFormatType()); EXPECT_EQ(0, buf1.location); - EXPECT_EQ(250 * 250, buffer1->GetSize()); - EXPECT_EQ(250 * 250 * sizeof(uint32_t), buffer1->GetSizeInBytes()); + EXPECT_EQ(250 * 250, buffer1->ElementCount()); + EXPECT_EQ(250 * 250 * 4, buffer1->ValueCount()); + EXPECT_EQ(250 * 250 * 4 * sizeof(uint8_t), buffer1->GetSizeInBytes()); ASSERT_EQ(1U, pipelines[1]->GetColorAttachments().size()); const auto& buf2 = pipelines[1]->GetColorAttachments()[0]; @@ -210,8 +211,9 @@ END)"; EXPECT_EQ(0, buf2.location); EXPECT_EQ(FormatType::kB8G8R8A8_UNORM, buf2.buffer->GetFormat()->GetFormatType()); - EXPECT_EQ(250 * 250, buf2.buffer->GetSize()); - EXPECT_EQ(250 * 250 * sizeof(uint32_t), buf2.buffer->GetSizeInBytes()); + EXPECT_EQ(250 * 250, buf2.buffer->ElementCount()); + EXPECT_EQ(250 * 250 * 4, buf2.buffer->ValueCount()); + EXPECT_EQ(250 * 250 * 4 * sizeof(uint8_t), buf2.buffer->GetSizeInBytes()); } TEST_F(AmberScriptParserTest, PipelineDefaultColorBufferMismatchSize) { diff --git a/src/buffer.cc b/src/buffer.cc index c7e9a0808..f9f931872 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -47,148 +47,6 @@ uint16_t FloatToHexFloat16(const float value) { static_cast(FloatMantissa(*hex) >> 13U)); } -// Convert 32 bits float |value| to 11 bits float based on IEEE-754. -uint16_t FloatToHexFloat11(const float value) { - const uint32_t* hex = reinterpret_cast(&value); - assert(FloatSign(*hex) == 0); - return static_cast( - static_cast(FloatExponent(*hex) << 6U) | - static_cast(FloatMantissa(*hex) >> 17U)); -} - -// Convert 32 bits float |value| to 10 bits float based on IEEE-754. -uint16_t FloatToHexFloat10(const float value) { - const uint32_t* hex = reinterpret_cast(&value); - assert(FloatSign(*hex) == 0); - return static_cast( - static_cast(FloatExponent(*hex) << 5U) | - static_cast(FloatMantissa(*hex) >> 18U)); -} - -// Convert float to small float format. -// See https://www.khronos.org/opengl/wiki/Small_Float_Formats -// and https://en.wikipedia.org/wiki/IEEE_754. -// -// Sign Exponent Mantissa Exponent-Bias -// 16 1 5 10 15 -// 11 0 5 6 15 -// 10 0 5 5 15 -// 32 1 8 23 127 -// 64 1 11 52 1023 -// -// 11 and 10 bits floats are always positive. -// 14 bits float is used only RGB9_E5 format in OpenGL but it does not exist -// in Vulkan. -// -// For example, 1234 in 32 bits float = 1.0011010010 * 2^10 with base 2. -// -// 1.0011010010 * 2^10 --> 0 (sign) / 10 + 127 (exp) / 0011010010 (Mantissa) -// --> 0x449a4000 -uint16_t FloatToHexFloat(float value, uint8_t bits) { - switch (bits) { - case 10: - return FloatToHexFloat10(value); - case 11: - return FloatToHexFloat11(value); - case 16: - return FloatToHexFloat16(value); - } - - assert(false && "Invalid bits"); - return 0; -} - -Result ValueToUint64(const Value& src, uint8_t bits, uint64_t* out) { - uint64_t data = 0; - if (src.IsInteger()) { - switch (bits) { - case 8: { - uint8_t* ptr = reinterpret_cast(&data); - *ptr = src.AsUint8(); - break; - } - case 16: { - uint16_t* ptr = reinterpret_cast(&data); - *ptr = src.AsUint16(); - break; - } - case 32: { - uint32_t* ptr = reinterpret_cast(&data); - *ptr = src.AsUint32(); - break; - } - case 64: { - uint64_t* ptr = reinterpret_cast(&data); - *ptr = src.AsUint64(); - break; - } - default: { - return Result("Vulkan: Invalid int bits for CopyBitsOfValueToBuffer"); - } - } - } else { - if (bits == 64) { - double* ptr = reinterpret_cast(&data); - *ptr = src.AsDouble(); - } else { - switch (bits) { - case 32: { - float* float_ptr = reinterpret_cast(&data); - *float_ptr = src.AsFloat(); - break; - } - case 16: - case 11: - case 10: { - uint16_t* uint16_ptr = reinterpret_cast(&data); - *uint16_ptr = - static_cast(FloatToHexFloat(src.AsFloat(), bits)); - break; - } - default: { - return Result( - "Vulkan: Invalid float bits for CopyBitsOfValueToBuffer"); - } - } - } - } - *out = data; - return {}; -} - -// Copy [0, bits) bits of |src| to -// [dst_bit_offset, dst_bit_offset + bits) of |dst|. If |bits| is -// less than 32 and the type is float, this method uses -// FloatToHexFloat() to convert it into small bits float. -Result CopyBitsOfValueToBuffer(uint8_t* dst, - const Value& src, - uint32_t dst_bit_offset, - uint8_t bits) { - uint64_t data = 0; - Result r = ValueToUint64(src, bits, &data); - if (!r.IsSuccess()) - return r; - - // Shift memory pointer to the start of the byte to write into. - while (dst_bit_offset > 7) { - ++dst; - dst_bit_offset -= 8; - } - - // No overflow will happen. |dst_bit_offset| is based on VkFormat - // and if |bits| is 64, |dst_bit_offset| must be 0. No component - // has |bits| bigger than 64. - data <<= dst_bit_offset; - - uint64_t* dst64 = reinterpret_cast(dst); - uint64_t dst_lower_bits = *dst64 & ((1UL << dst_bit_offset) - 1UL); - uint64_t dst_upper_bits = - *dst64 & ~(((1ULL << (dst_bit_offset + bits)) - 1ULL)); - - *dst64 = dst_lower_bits | data | dst_upper_bits; - return {}; -} - template T* ValuesAs(uint8_t* values) { return reinterpret_cast(values); @@ -215,7 +73,7 @@ Result Buffer::CopyTo(Buffer* buffer) const { return Result("Buffer::CopyBaseFields() buffers have a different width"); if (buffer->height_ != height_) return Result("Buffer::CopyBaseFields() buffers have a different height"); - if (buffer->size_ != size_) + if (buffer->element_count_ != element_count_) return Result("Buffer::CopyBaseFields() buffers have a different size"); buffer->values_ = values_; return {}; @@ -224,7 +82,7 @@ Result Buffer::CopyTo(Buffer* buffer) const { Result Buffer::IsEqual(Buffer* buffer) const { if (buffer->buffer_type_ != buffer_type_) return Result{"Buffers have a different type"}; - if (buffer->size_ != size_) + if (buffer->element_count_ != element_count_) return Result{"Buffers have a different size"}; if (buffer->width_ != width_) return Result{"Buffers have a different width"}; @@ -266,10 +124,8 @@ DataBuffer::DataBuffer(BufferType type) : Buffer(type) {} DataBuffer::~DataBuffer() = default; -Result DataBuffer::SetData(std::vector&& data) { - uint32_t size = static_cast(data.size()) / format_->ColumnCount() / - format_->RowCount(); - SetSize(size); +Result DataBuffer::SetData(const std::vector& data) { + SetValueCount(static_cast(data.size())); values_.resize(GetSizeInBytes()); return CopyData(data); } @@ -319,8 +175,8 @@ FormatBuffer::FormatBuffer(BufferType type) : Buffer(type) {} FormatBuffer::~FormatBuffer() = default; -Result FormatBuffer::SetData(std::vector&& data) { - SetSize(static_cast(data.size())); +Result FormatBuffer::SetData(const std::vector& data) { + SetValueCount(static_cast(data.size())); values_.resize(GetSizeInBytes()); return CopyData(data); } @@ -331,29 +187,63 @@ Result FormatBuffer::CopyData(const std::vector& data) { for (uint32_t i = 0; i < data.size();) { const auto pack_size = format_->GetPackSize(); if (pack_size) { - Result r = CopyBitsOfValueToBuffer(ptr, data[i], 0, pack_size); - if (!r.IsSuccess()) - return r; - - ptr += pack_size / 8; + if (pack_size == 8) { + *(ValuesAs(ptr)) = data[i].AsUint8(); + ptr += sizeof(uint8_t); + } else if (pack_size == 16) { + *(ValuesAs(ptr)) = data[i].AsUint16(); + ptr += sizeof(uint16_t); + } else if (pack_size == 32) { + *(ValuesAs(ptr)) = data[i].AsUint32(); + ptr += sizeof(uint32_t); + } ++i; continue; } - const auto& components = format_->GetComponents(); - uint32_t bit_offset = 0; - - for (uint32_t k = 0; k < components.size(); ++k) { - uint8_t bits = components[k].num_bits; - Result r = CopyBitsOfValueToBuffer(ptr, data[i + k], bit_offset, bits); - if (!r.IsSuccess()) - return r; - - bit_offset += bits; + for (const auto& comp : format_->GetComponents()) { + if (comp.IsInt8()) { + *(ValuesAs(ptr)) = data[i].AsInt8(); + ptr += sizeof(int8_t); + } else if (comp.IsInt16()) { + *(ValuesAs(ptr)) = data[i].AsInt16(); + ptr += sizeof(int16_t); + } else if (comp.IsInt32()) { + *(ValuesAs(ptr)) = data[i].AsInt32(); + ptr += sizeof(int32_t); + } else if (comp.IsInt64()) { + *(ValuesAs(ptr)) = data[i].AsInt64(); + ptr += sizeof(int64_t); + } else if (comp.IsUint8()) { + *(ValuesAs(ptr)) = data[i].AsUint8(); + ptr += sizeof(uint8_t); + } else if (comp.IsUint16()) { + *(ValuesAs(ptr)) = data[i].AsUint16(); + ptr += sizeof(uint16_t); + } else if (comp.IsUint32()) { + *(ValuesAs(ptr)) = data[i].AsUint32(); + ptr += sizeof(uint32_t); + } else if (comp.IsUint64()) { + *(ValuesAs(ptr)) = data[i].AsUint64(); + ptr += sizeof(uint64_t); + } else if (comp.IsFloat()) { + *(ValuesAs(ptr)) = data[i].AsFloat(); + ptr += sizeof(float); + } else if (comp.IsDouble()) { + *(ValuesAs(ptr)) = data[i].AsDouble(); + ptr += sizeof(double); + } else if (comp.IsFloat16()) { + *(ValuesAs(ptr)) = FloatToHexFloat16(data[i].AsFloat()); + ptr += sizeof(uint16_t); + } else { + // The float 10 and float 11 sizes are only used in PACKED formats. + assert(false && "Not reached"); + } + ++i; } - - i += static_cast(components.size()); - ptr += format_->SizeInBytes(); + // Need to add an extra element if this is std140 and there are 3 elements. + if (format_->IsStd140() && format_->RowCount() == 3) + ptr += (format_->GetComponents()[0].num_bits / 8); } return {}; } diff --git a/src/buffer.h b/src/buffer.h index f50dc957f..77e0dc1a9 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -95,25 +95,52 @@ class Buffer { /// Returns the name of the buffer. std::string GetName() const { return name_; } - /// Sets the number of items in the buffer. - void SetSize(uint32_t size) { size_ = size; } - - /// Returns the number of items in the buffer. - uint32_t GetSize() const { return size_; } - uint32_t GetWidth() const { return width_; } void SetWidth(uint32_t width) { width_ = width; } uint32_t GetHeight() const { return height_; } void SetHeight(uint32_t height) { height_ = height; } + // | ---------- Element ---------- | ElementCount == 1 + // | Value | Value | Value | Value | ValueCount == 4 + // | | | | | | | | | | | | | | | | | SizeInBytes == 16 + // Note, the SizeInBytes maybe be greater then the size of the values. If + // the format IsStd140() and there are 3 rows, the SizeInBytes will be + // inflated to 4 values per row, instead of 3. + + /// Sets the number of elements in the buffer. + void SetElementCount(uint32_t count) { element_count_ = count; } + uint32_t ElementCount() const { return element_count_; } + + /// Sets the number of values in the buffer. + void SetValueCount(uint32_t count) { + if (!format_) { + element_count_ = 0; + return; + } + if (format_->GetPackSize() > 0) + element_count_ = count; + else + element_count_ = count / format_->ValuesPerElement(); + } + uint32_t ValueCount() const { + if (!format_) + return 0; + // Packed formats are single values. + if (format_->GetPackSize() > 0) + return element_count_; + return element_count_ * format_->ValuesPerElement(); + } + /// Returns the number of bytes needed for the data in the buffer. - virtual uint32_t GetSizeInBytes() const { - return GetSize() * format_->SizeInBytes(); + uint32_t GetSizeInBytes() const { + if (!format_) + return 0; + return ElementCount() * format_->SizeInBytes(); } /// Sets the data into the buffer. The size will also be updated to be the /// size of the data provided. - virtual Result SetData(std::vector&& data) = 0; + virtual Result SetData(const std::vector& data) = 0; std::vector* ValuePtr() { return &values_; } const std::vector* ValuePtr() const { return &values_; } @@ -130,7 +157,6 @@ class Buffer { Result IsEqual(Buffer* buffer) const; protected: - /// Creates an un-typed buffer. Buffer(); std::vector values_; @@ -139,7 +165,7 @@ class Buffer { private: BufferType buffer_type_ = BufferType::kUnknown; std::string name_; - uint32_t size_ = 0; + uint32_t element_count_ = 0; uint32_t width_ = 0; uint32_t height_ = 0; uint8_t location_ = 0; @@ -154,10 +180,7 @@ class DataBuffer : public Buffer { // Buffer bool IsDataBuffer() const override { return true; } - uint32_t GetSizeInBytes() const override { - return GetSize() * datum_type_.SizeInBytes(); - } - Result SetData(std::vector&& data) override; + Result SetData(const std::vector& data) override; /// Sets the DatumType of the buffer to |type|. void SetDatumType(const DatumType& type) { @@ -183,7 +206,7 @@ class FormatBuffer : public Buffer { // Buffer bool IsFormatBuffer() const override { return true; } - Result SetData(std::vector&& data) override; + Result SetData(const std::vector& data) override; uint32_t GetTexelStride() { return format_->SizeInBytes(); } diff --git a/src/buffer_test.cc b/src/buffer_test.cc index 897b2297f..e5eb71285 100644 --- a/src/buffer_test.cc +++ b/src/buffer_test.cc @@ -24,7 +24,8 @@ using BufferTest = testing::Test; TEST_F(BufferTest, DataBufferEmptyByDefault) { DataBuffer b(BufferType::kColor); - EXPECT_EQ(static_cast(0U), b.GetSize()); + EXPECT_EQ(static_cast(0U), b.ElementCount()); + EXPECT_EQ(static_cast(0U), b.ValueCount()); EXPECT_EQ(static_cast(0U), b.GetSizeInBytes()); } @@ -34,9 +35,10 @@ TEST_F(BufferTest, DataBufferSize) { DataBuffer b(BufferType::kColor); b.SetDatumType(type); - b.SetSize(10); - EXPECT_EQ(10, b.GetSize()); - EXPECT_EQ(2 * 10, b.GetSizeInBytes()); + b.SetElementCount(10); + EXPECT_EQ(10, b.ElementCount()); + EXPECT_EQ(10, b.ValueCount()); + EXPECT_EQ(10 * sizeof(int16_t), b.GetSizeInBytes()); } TEST_F(BufferTest, DataBufferSizeFromData) { @@ -50,8 +52,9 @@ TEST_F(BufferTest, DataBufferSizeFromData) { b.SetDatumType(type); b.SetData(std::move(values)); - EXPECT_EQ(5, b.GetSize()); - EXPECT_EQ(2 * 5, b.GetSizeInBytes()); + EXPECT_EQ(5, b.ElementCount()); + EXPECT_EQ(5, b.ValueCount()); + EXPECT_EQ(5 * sizeof(int16_t), b.GetSizeInBytes()); } TEST_F(BufferTest, DataBufferSizeFromDataOverrideSize) { @@ -63,11 +66,12 @@ TEST_F(BufferTest, DataBufferSizeFromDataOverrideSize) { DataBuffer b(BufferType::kColor); b.SetDatumType(type); - b.SetSize(20); + b.SetElementCount(20); b.SetData(std::move(values)); - EXPECT_EQ(5, b.GetSize()); - EXPECT_EQ(2 * 5, b.GetSizeInBytes()); + EXPECT_EQ(5, b.ElementCount()); + EXPECT_EQ(5, b.ValueCount()); + EXPECT_EQ(5 * sizeof(int16_t), b.GetSizeInBytes()); } TEST_F(BufferTest, DataBufferSizeMatrix) { @@ -78,9 +82,11 @@ TEST_F(BufferTest, DataBufferSizeMatrix) { DataBuffer b(BufferType::kColor); b.SetDatumType(type); - b.SetSize(10); - EXPECT_EQ(10, b.GetSize()); - EXPECT_EQ(2 * 10 * 3 * 2, b.GetSizeInBytes()); + b.SetElementCount(10); + + EXPECT_EQ(10, b.ElementCount()); + EXPECT_EQ(60, b.ValueCount()); + EXPECT_EQ(60 * sizeof(int16_t), b.GetSizeInBytes()); } } // namespace amber diff --git a/src/command.h b/src/command.h index 88ca2fe2f..d00b72728 100644 --- a/src/command.h +++ b/src/command.h @@ -406,13 +406,11 @@ class BufferCommand : public PipelineCommand { void SetSize(uint32_t size) { size_ = size; } uint32_t GetSize() const { return size_; } - void SetFormat(std::unique_ptr fmt) { format_ = std::move(fmt); } - Format* GetFormat() const { return format_.get(); } - void SetValues(std::vector&& values) { values_ = std::move(values); - size_ = static_cast(values_.size() * format_->SizeInBytes()) / - format_->ColumnCount() / format_->RowCount(); + auto fmt = buffer_->GetFormat(); + size_ = static_cast(values_.size() * fmt->SizeInBytes()) / + fmt->ValuesPerElement(); } const std::vector& GetValues() const { return values_; } @@ -427,7 +425,6 @@ class BufferCommand : public PipelineCommand { uint32_t binding_num_ = 0; uint32_t size_ = 0; uint32_t offset_ = 0; - std::unique_ptr format_; std::vector values_; }; diff --git a/src/executor.cc b/src/executor.cc index aa0da8327..840d7ec4c 100644 --- a/src/executor.cc +++ b/src/executor.cc @@ -95,7 +95,7 @@ Result Executor::ExecuteCommand(Engine* engine, Command* cmd) { const auto* buffer = cmd->AsProbe()->GetBuffer(); assert(buffer); - return verifier_.ProbeSSBO(probe_ssbo, buffer->GetSize(), + return verifier_.ProbeSSBO(probe_ssbo, buffer->ElementCount(), buffer->ValuePtr()->data()); } if (cmd->IsClear()) diff --git a/src/format.cc b/src/format.cc index 97e279a6d..47f0990b1 100644 --- a/src/format.cc +++ b/src/format.cc @@ -31,6 +31,10 @@ uint32_t Format::SizeInBytes() const { bits += components_[0].num_bits; uint32_t bytes_per_element = bits / 8; + // Odd number of bits, inflate or byte count to accommodate + if ((bits % 8) != 0) + bytes_per_element += 1; + return bytes_per_element * column_count_; } @@ -42,4 +46,23 @@ bool Format::AreAllComponents(FormatMode mode, uint32_t bits) const { return true; } +bool Format::Equal(const Format* b) const { + if (type_ != b->type_ || is_std140_ != b->is_std140_ || + pack_size_in_bytes_ != b->pack_size_in_bytes_ || + column_count_ != b->column_count_) { + return false; + } + if (components_.size() != b->components_.size()) + return false; + + for (uint32_t i = 0; i < components_.size(); ++i) { + if (components_[i].type != b->components_[i].type || + components_[i].mode != b->components_[i].mode || + components_[i].num_bits != b->components_[i].num_bits) { + return false; + } + } + return true; +} + } // namespace amber diff --git a/src/format.h b/src/format.h index 6ef7fd0df..5b4fe48f6 100644 --- a/src/format.h +++ b/src/format.h @@ -33,6 +33,41 @@ class Format { FormatComponentType type; FormatMode mode; uint8_t num_bits; + + bool IsInt8() const { + return (mode == FormatMode::kSInt || mode == FormatMode::kSNorm || + mode == FormatMode::kSScaled || mode == FormatMode::kSRGB) && + num_bits == 8; + } + bool IsInt16() const { + return (mode == FormatMode::kSInt || mode == FormatMode::kSNorm) && + num_bits == 16; + } + bool IsInt32() const { return mode == FormatMode::kSInt && num_bits == 32; } + bool IsInt64() const { return mode == FormatMode::kSInt && num_bits == 64; } + bool IsUint8() const { + return (mode == FormatMode::kUInt || mode == FormatMode::kUNorm || + mode == FormatMode::kUScaled) && + num_bits == 8; + } + bool IsUint16() const { + return mode == FormatMode::kUInt && num_bits == 16; + } + bool IsUint32() const { + return mode == FormatMode::kUInt && num_bits == 32; + } + bool IsUint64() const { + return mode == FormatMode::kUInt && num_bits == 64; + } + bool IsFloat16() const { + return mode == FormatMode::kSFloat && num_bits == 16; + } + bool IsFloat() const { + return mode == FormatMode::kSFloat && num_bits == 32; + } + bool IsDouble() const { + return mode == FormatMode::kSFloat && num_bits == 64; + } }; Format(); @@ -41,6 +76,8 @@ class Format { Format& operator=(const Format&) = default; + bool Equal(const Format* b) const; + void SetFormatType(FormatType type) { type_ = type; } FormatType GetFormatType() const { return type_; } @@ -68,6 +105,9 @@ class Format { type_ == FormatType::kS8_UINT; } + /// Returns the number of unique numbers for each instance of this format. + uint32_t ValuesPerElement() const { return RowCount() * column_count_; } + uint32_t RowCount() const { return static_cast(components_.size()); } diff --git a/src/pipeline.cc b/src/pipeline.cc index 7707dd2b2..956b15a93 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -146,13 +146,13 @@ Result Pipeline::SetShaderType(const Shader* shader, ShaderType type) { Result Pipeline::Validate() const { size_t fb_size = fb_width_ * fb_height_; for (const auto& attachment : color_attachments_) { - if (attachment.buffer->GetSize() != fb_size) { + if (attachment.buffer->ElementCount() != fb_size) { return Result( "shared framebuffer must have same size over all PIPELINES"); } } - if (depth_buffer_.buffer && depth_buffer_.buffer->GetSize() != fb_size) + if (depth_buffer_.buffer && depth_buffer_.buffer->ElementCount() != fb_size) return Result("shared depth buffer must have same size over all PIPELINES"); if (pipeline_type_ == PipelineType::kGraphics) @@ -203,13 +203,13 @@ void Pipeline::UpdateFramebufferSizes() { for (auto& attachment : color_attachments_) { attachment.buffer->SetWidth(fb_width_); attachment.buffer->SetHeight(fb_height_); - attachment.buffer->SetSize(size); + attachment.buffer->SetElementCount(size); } if (depth_buffer_.buffer) { depth_buffer_.buffer->SetWidth(fb_width_); depth_buffer_.buffer->SetHeight(fb_height_); - depth_buffer_.buffer->SetSize(size); + depth_buffer_.buffer->SetElementCount(size); } } @@ -227,7 +227,7 @@ Result Pipeline::AddColorAttachment(Buffer* buf, uint32_t location) { info.location = location; buf->SetWidth(fb_width_); buf->SetHeight(fb_height_); - buf->SetSize(fb_width_ * fb_height_); + buf->SetElementCount(fb_width_ * fb_height_); return {}; } @@ -251,7 +251,7 @@ Result Pipeline::SetDepthBuffer(Buffer* buf) { depth_buffer_.buffer = buf; buf->SetWidth(fb_width_); buf->SetHeight(fb_height_); - buf->SetSize(fb_width_ * fb_height_); + buf->SetElementCount(fb_width_ * fb_height_); return {}; } diff --git a/src/verifier.cc b/src/verifier.cc index 4731d5b01..20df7c027 100644 --- a/src/verifier.cc +++ b/src/verifier.cc @@ -638,34 +638,38 @@ Result Verifier::Probe(const ProbeCommand* command, } Result Verifier::ProbeSSBO(const ProbeSSBOCommand* command, - size_t size_in_bytes, - const void* cpu_memory) { + uint32_t buffer_element_count, + const void* buffer) { const auto& values = command->GetValues(); - if (!cpu_memory) { - return values.empty() ? Result() - : Result( - "Verifier::ProbeSSBO actual data is empty " - "while expected data is not"); + if (!buffer) { + if (values.empty()) + return {}; + return Result( + "Verifier::ProbeSSBO actual data is empty while expected " + "data is not"); } auto* fmt = command->GetFormat(); - // TODO(dsinclair): This assumes that all components are the same number - // of bits which may not always hold. - size_t bytes_per_elem = fmt->GetComponents()[0].num_bits / kBitsPerByte; + size_t elem_count = values.size() / fmt->ValuesPerElement(); size_t offset = static_cast(command->GetOffset()); - if (values.size() * bytes_per_elem + offset > size_in_bytes) { - return Result( - "Line " + std::to_string(command->GetLine()) + - ": Verifier::ProbeSSBO has more expected values than SSBO size"); + size_t size_in_bytes = buffer_element_count * fmt->SizeInBytes(); + if ((elem_count * fmt->SizeInBytes()) + offset > size_in_bytes) { + return Result("Line " + std::to_string(command->GetLine()) + + ": Verifier::ProbeSSBO request to access to byte " + + std::to_string((elem_count * fmt->SizeInBytes()) + offset) + + " would read outside buffer of size " + + std::to_string(size_in_bytes) + " bytes"); } - if (offset % bytes_per_elem != 0) { - return Result( - "Line " + std::to_string(command->GetLine()) + - ": Verifier::ProbeSSBO given offset is not multiple of bytes_per_elem"); + if (offset % fmt->SizeInBytes() != 0) { + return Result("Line " + std::to_string(command->GetLine()) + + ": Verifier::ProbeSSBO given offset (" + + std::to_string(offset) + ") " + + "is not multiple of element size (" + + std::to_string(fmt->SizeInBytes()) + ")"); } - const uint8_t* ptr = static_cast(cpu_memory) + offset; + const uint8_t* ptr = static_cast(buffer) + offset; if (fmt->IsInt8()) return CheckValue(command, ptr, values); if (fmt->IsUint8()) diff --git a/src/verifier.h b/src/verifier.h index af91bb7b5..9edf26187 100644 --- a/src/verifier.h +++ b/src/verifier.h @@ -43,8 +43,8 @@ class Verifier { /// Check |command| against |cpu_memory|. The result will be success if the /// probe passes correctly. Result ProbeSSBO(const ProbeSSBOCommand* command, - size_t size, - const void* cpu_memory); + uint32_t buffer_element_count, + const void* buffer); }; } // namespace amber diff --git a/src/verifier_test.cc b/src/verifier_test.cc index e5e375a65..76b454f65 100644 --- a/src/verifier_test.cc +++ b/src/verifier_test.cc @@ -711,8 +711,8 @@ TEST_F(VerifierTest, ProbeSSBOUint8Single) { uint8_t ssbo = 13U; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(uint8_t), - static_cast(&ssbo)); + Result r = + verifier.ProbeSSBO(&probe_ssbo, 1, static_cast(&ssbo)); EXPECT_TRUE(r.IsSuccess()); } @@ -736,7 +736,7 @@ TEST_F(VerifierTest, ProbeSSBOUint8Multiple) { const uint8_t ssbo[3] = {2U, 0U, 10U}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(uint8_t) * 3, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 3, ssbo); EXPECT_TRUE(r.IsSuccess()); } @@ -764,8 +764,7 @@ TEST_F(VerifierTest, ProbeSSBOUint8Many) { } Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(uint8_t) * ssbo.size(), - ssbo.data()); + Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data()); EXPECT_TRUE(r.IsSuccess()); } @@ -787,8 +786,8 @@ TEST_F(VerifierTest, ProbeSSBOUint32Single) { uint32_t ssbo = 13U; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(uint32_t), - static_cast(&ssbo)); + Result r = + verifier.ProbeSSBO(&probe_ssbo, 1, static_cast(&ssbo)); EXPECT_TRUE(r.IsSuccess()); } @@ -813,7 +812,7 @@ TEST_F(VerifierTest, ProbeSSBOUint32Multiple) { const uint32_t ssbo[4] = {2U, 0U, 10U, 1234U}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(uint32_t) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_TRUE(r.IsSuccess()); } @@ -841,8 +840,7 @@ TEST_F(VerifierTest, ProbeSSBOUint32Many) { } Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(uint32_t) * ssbo.size(), - ssbo.data()); + Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data()); EXPECT_TRUE(r.IsSuccess()); } @@ -864,8 +862,8 @@ TEST_F(VerifierTest, ProbeSSBOFloatSingle) { float ssbo = 13.7f; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(float), - static_cast(&ssbo)); + Result r = + verifier.ProbeSSBO(&probe_ssbo, 1, static_cast(&ssbo)); EXPECT_TRUE(r.IsSuccess()); } @@ -890,7 +888,7 @@ TEST_F(VerifierTest, ProbeSSBOFloatMultiple) { const float ssbo[4] = {2.9f, 0.73f, 10.0f, 1234.56f}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(float) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_TRUE(r.IsSuccess()); } @@ -918,8 +916,7 @@ TEST_F(VerifierTest, ProbeSSBOFloatMany) { } Verifier verifier; - Result r = - verifier.ProbeSSBO(&probe_ssbo, sizeof(float) * ssbo.size(), ssbo.data()); + Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data()); EXPECT_TRUE(r.IsSuccess()); } @@ -941,8 +938,8 @@ TEST_F(VerifierTest, ProbeSSBODoubleSingle) { double ssbo = 13.7; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double), - static_cast(&ssbo)); + Result r = + verifier.ProbeSSBO(&probe_ssbo, 1, static_cast(&ssbo)); EXPECT_TRUE(r.IsSuccess()); } @@ -967,7 +964,7 @@ TEST_F(VerifierTest, ProbeSSBODoubleMultiple) { const double ssbo[4] = {2.9, 0.73, 10.0, 1234.56}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_TRUE(r.IsSuccess()); } @@ -995,8 +992,7 @@ TEST_F(VerifierTest, ProbeSSBODoubleMany) { } Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * ssbo.size(), - ssbo.data()); + Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data()); EXPECT_TRUE(r.IsSuccess()); } @@ -1021,7 +1017,7 @@ TEST_F(VerifierTest, ProbeSSBOEqualFail) { const double ssbo[4] = {2.8, 0.72, 9.0, 1234.55}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_FALSE(r.IsSuccess()); EXPECT_EQ("Line 1: Verifier failed: 2.800000 == 2.900000, at index 0", r.Error()); @@ -1052,12 +1048,12 @@ TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithAbsoluteTolerance) { const double ssbo_more[4] = {2.999, 0.829, 10.099, 1234.659}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo_more); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo_more); EXPECT_TRUE(r.IsSuccess()); const double ssbo_less[4] = {2.801, 0.631, 9.901, 1234.461}; - r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo_less); + r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo_less); EXPECT_TRUE(r.IsSuccess()); } @@ -1086,7 +1082,7 @@ TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithAbsoluteToleranceFail) { const double ssbo[4] = {3.001, 0.831, 10.101, 1234.661}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_FALSE(r.IsSuccess()); EXPECT_EQ("Line 1: Verifier failed: 3.001000 ~= 2.900000, at index 0", r.Error()); @@ -1117,7 +1113,7 @@ TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithRelativeTolerance) { const double ssbo_more[4] = {2.9028, 0.73072, 10.009, 1235.79455}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo_more); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo_more); EXPECT_TRUE(r.IsSuccess()); const double ssbo_less[4] = {2.8972, 0.72928, 9.991, 1233.32545}; @@ -1151,7 +1147,7 @@ TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithRelativeToleranceFail) { const double ssbo[4] = {2.903, 0.73074, 10.011, 1235.79457}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_FALSE(r.IsSuccess()); EXPECT_EQ("Line 1: Verifier failed: 2.903000 ~= 2.900000, at index 0", r.Error()); @@ -1178,7 +1174,7 @@ TEST_F(VerifierTest, ProbeSSBONotEqual) { const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_TRUE(r.IsSuccess()); } @@ -1203,7 +1199,7 @@ TEST_F(VerifierTest, ProbeSSBONotEqualFail) { const double ssbo[4] = {2.9, 0.73, 10.0, 1234.56}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_FALSE(r.IsSuccess()); EXPECT_EQ("Line 1: Verifier failed: 2.900000 != 2.900000, at index 0", r.Error()); @@ -1230,7 +1226,7 @@ TEST_F(VerifierTest, ProbeSSBOLess) { const double ssbo[4] = {1.9, 0.63, 9.99, 1234.559}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_TRUE(r.IsSuccess()); } @@ -1255,7 +1251,7 @@ TEST_F(VerifierTest, ProbeSSBOLessFail) { const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_FALSE(r.IsSuccess()); EXPECT_EQ("Line 1: Verifier failed: 3.900000 < 2.900000, at index 0", r.Error()); @@ -1282,7 +1278,7 @@ TEST_F(VerifierTest, ProbeSSBOLessOrEqual) { const double ssbo[4] = {1.9, 0.73, 9.99, 1234.560}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_TRUE(r.IsSuccess()); } @@ -1307,7 +1303,7 @@ TEST_F(VerifierTest, ProbeSSBOLessOrEqualFail) { const double ssbo[4] = {1.9, 0.73, 9.99, 1234.561}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_FALSE(r.IsSuccess()); EXPECT_EQ("Line 1: Verifier failed: 1234.561000 <= 1234.560000, at index 3", r.Error()); @@ -1334,7 +1330,7 @@ TEST_F(VerifierTest, ProbeSSBOGreater) { const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_TRUE(r.IsSuccess()); } @@ -1359,7 +1355,7 @@ TEST_F(VerifierTest, ProbeSSBOGreaterFail) { const double ssbo[4] = {3.9, 0.73, 10.1, 1234.57}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_FALSE(r.IsSuccess()); EXPECT_EQ("Line 1: Verifier failed: 0.730000 > 0.730000, at index 1", r.Error()); @@ -1411,7 +1407,7 @@ TEST_F(VerifierTest, ProbeSSBOGreaterOrEqualFail) { const double ssbo[4] = {3.9, 0.73, 10.1, 1234.559}; Verifier verifier; - Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo); + Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo); EXPECT_FALSE(r.IsSuccess()); EXPECT_EQ("Line 1: Verifier failed: 1234.559000 >= 1234.560000, at index 3", r.Error()); diff --git a/src/vkscript/command_parser.cc b/src/vkscript/command_parser.cc index c17e2ef82..7963eaaa2 100644 --- a/src/vkscript/command_parser.cc +++ b/src/vkscript/command_parser.cc @@ -613,7 +613,13 @@ Result CommandParser::ProcessSSBO() { if (!r.IsSuccess()) return r; - cmd->SetFormat(tp.GetType().AsFormat()); + auto fmt = tp.GetType().AsFormat(); + if (cmd->GetBuffer()->GetFormat() && + !cmd->GetBuffer()->GetFormat()->Equal(fmt.get())) { + return Result("probe ssbo format does not match buffer format"); + } + if (!cmd->GetBuffer()->GetFormat()) + cmd->GetBuffer()->SetFormat(std::move(fmt)); token = tokenizer_->NextToken(); if (!token->IsInteger()) { @@ -624,16 +630,17 @@ Result CommandParser::ProcessSSBO() { return Result("offset for SSBO must be positive, got: " + std::to_string(token->AsInt32())); } - if ((token->AsUint32() % cmd->GetFormat()->SizeInBytes()) != 0) { + if ((token->AsUint32() % cmd->GetBuffer()->GetFormat()->SizeInBytes()) != + 0) { return Result( "offset for SSBO must be a multiple of the data size expected " + - std::to_string(cmd->GetFormat()->SizeInBytes())); + std::to_string(cmd->GetBuffer()->GetFormat()->SizeInBytes())); } cmd->SetOffset(token->AsUint32()); std::vector values; - r = ParseValues("ssbo", cmd->GetFormat(), &values, false); + r = ParseValues("ssbo", cmd->GetBuffer()->GetFormat(), &values, false); if (!r.IsSuccess()) return r; @@ -652,7 +659,7 @@ Result CommandParser::ProcessSSBO() { // Resize the buffer so we'll correctly create the descriptor sets. auto* buf = cmd->GetBuffer(); - buf->SetSize(size); + buf->SetElementCount(size); buf->ValuePtr()->resize(size); token = tokenizer_->NextToken(); @@ -716,22 +723,6 @@ Result CommandParser::ProcessUniform() { cmd->SetBinding(val); } - { - // Generate an internal buffer for this binding if needed. - auto set = cmd->GetDescriptorSet(); - auto binding = cmd->GetBinding(); - - auto* buffer = pipeline_->GetBufferForBinding(set, binding); - if (!buffer) { - auto b = MakeUnique(BufferType::kUniform); - b->SetName("AutoBuf-" + std::to_string(script_->GetBuffers().size())); - buffer = b.get(); - script_->AddBuffer(std::move(b)); - pipeline_->AddBuffer(buffer, set, binding); - } - cmd->SetBuffer(buffer); - } - use_std430_layout = true; } else { cmd = MakeUnique(BufferCommand::BufferType::kPushConstant, @@ -739,12 +730,34 @@ Result CommandParser::ProcessUniform() { cmd->SetLine(tokenizer_->GetCurrentLine()); } + { + // Generate an internal buffer for this binding if needed. + auto set = cmd->GetDescriptorSet(); + auto binding = cmd->GetBinding(); + + auto* buffer = pipeline_->GetBufferForBinding(set, binding); + if (!buffer) { + auto b = MakeUnique(BufferType::kUniform); + b->SetName("AutoBuf-" + std::to_string(script_->GetBuffers().size())); + buffer = b.get(); + script_->AddBuffer(std::move(b)); + pipeline_->AddBuffer(buffer, set, binding); + } + cmd->SetBuffer(buffer); + } + DatumTypeParser tp; Result r = tp.Parse(token->AsString()); if (!r.IsSuccess()) return r; - cmd->SetFormat(tp.GetType().AsFormat()); + auto fmt = tp.GetType().AsFormat(); + if (cmd->GetBuffer()->GetFormat() && + !cmd->GetBuffer()->GetFormat()->Equal(fmt.get())) { + return Result("probe ssbo format does not match buffer format"); + } + if (!cmd->GetBuffer()->GetFormat()) + cmd->GetBuffer()->SetFormat(std::move(fmt)); token = tokenizer_->NextToken(); if (!token->IsInteger()) { @@ -759,7 +772,8 @@ Result CommandParser::ProcessUniform() { cmd->SetOffset(token->AsUint32()); std::vector values; - r = ParseValues("uniform", cmd->GetFormat(), &values, use_std430_layout); + r = ParseValues("uniform", cmd->GetBuffer()->GetFormat(), &values, + use_std430_layout); if (!r.IsSuccess()) return r; @@ -2042,10 +2056,17 @@ Result CommandParser::ProcessProbeSSBO() { std::to_string(binding)); } + auto fmt = tp.GetType().AsFormat(); + if (buffer->GetFormat() && !buffer->GetFormat()->Equal(fmt.get())) + return Result("probe format does not match buffer format"); + + if (!buffer->GetFormat()) + buffer->SetFormat(tp.GetType().AsFormat()); + auto cmd = MakeUnique(buffer); cmd->SetLine(cur_line); cmd->SetTolerances(current_tolerances_); - cmd->SetFormat(tp.GetType().AsFormat()); + cmd->SetFormat(std::move(fmt)); cmd->SetDescriptorSet(set); cmd->SetBinding(binding); diff --git a/src/vkscript/command_parser_test.cc b/src/vkscript/command_parser_test.cc index 19f448952..28fe07a92 100644 --- a/src/vkscript/command_parser_test.cc +++ b/src/vkscript/command_parser_test.cc @@ -3094,7 +3094,7 @@ TEST_F(CommandParserTest, SSBOSubdataWithFloat) { EXPECT_EQ(16U, cmd->GetSize()); ASSERT_TRUE(cmd->IsSubdata()); - auto* fmt = cmd->GetFormat(); + auto* fmt = cmd->GetBuffer()->GetFormat(); EXPECT_TRUE(fmt->IsFloat()); EXPECT_EQ(1U, fmt->ColumnCount()); EXPECT_EQ(3U, fmt->RowCount()); @@ -3139,7 +3139,7 @@ TEST_F(CommandParserTest, SSBOSubdataWithDescriptorSet) { EXPECT_EQ(16U, cmd->GetOffset()); EXPECT_EQ(16U, cmd->GetSize()); - auto* fmt = cmd->GetFormat(); + auto* fmt = cmd->GetBuffer()->GetFormat(); EXPECT_TRUE(fmt->IsFloat()); EXPECT_EQ(1U, fmt->ColumnCount()); EXPECT_EQ(3U, fmt->RowCount()); @@ -3173,7 +3173,7 @@ TEST_F(CommandParserTest, SSBOSubdataWithInts) { EXPECT_EQ(8U, cmd->GetOffset()); EXPECT_EQ(8U, cmd->GetSize()); - auto* fmt = cmd->GetFormat(); + auto* fmt = cmd->GetBuffer()->GetFormat(); EXPECT_TRUE(fmt->IsInt16()); EXPECT_EQ(1U, fmt->ColumnCount()); EXPECT_EQ(3U, fmt->RowCount()); @@ -3207,7 +3207,7 @@ TEST_F(CommandParserTest, SSBOSubdataWithMultipleVectors) { EXPECT_EQ(8U, cmd->GetOffset()); EXPECT_EQ(16U, cmd->GetSize()); - auto* fmt = cmd->GetFormat(); + auto* fmt = cmd->GetBuffer()->GetFormat(); EXPECT_TRUE(fmt->IsInt16()); EXPECT_EQ(1U, fmt->ColumnCount()); EXPECT_EQ(3U, fmt->RowCount()); @@ -3340,7 +3340,7 @@ TEST_F(CommandParserTest, Uniform) { EXPECT_EQ(32U, cmd->GetOffset()); EXPECT_EQ(16U, cmd->GetSize()); - auto* fmt = cmd->GetFormat(); + auto* fmt = cmd->GetBuffer()->GetFormat(); EXPECT_TRUE(fmt->IsFloat()); EXPECT_EQ(1U, fmt->ColumnCount()); EXPECT_EQ(3U, fmt->RowCount()); @@ -3382,7 +3382,7 @@ TEST_F(CommandParserTest, UniformWithContinuation) { EXPECT_EQ(16U, cmd->GetOffset()); EXPECT_EQ(32U, cmd->GetSize()); - auto* fmt = cmd->GetFormat(); + auto* fmt = cmd->GetBuffer()->GetFormat(); EXPECT_TRUE(fmt->IsFloat()); EXPECT_EQ(1U, fmt->ColumnCount()); EXPECT_EQ(3U, fmt->RowCount()); @@ -3460,7 +3460,7 @@ TEST_F(CommandParserTest, UniformUBO) { EXPECT_EQ(static_cast(0), cmd->GetOffset()); EXPECT_EQ(16U, cmd->GetSize()); - auto* fmt = cmd->GetFormat(); + auto* fmt = cmd->GetBuffer()->GetFormat(); EXPECT_TRUE(fmt->IsFloat()); EXPECT_EQ(1U, fmt->ColumnCount()); EXPECT_EQ(3U, fmt->RowCount()); @@ -3504,7 +3504,7 @@ TEST_F(CommandParserTest, UniformUBOWithDescriptorSet) { EXPECT_EQ(16U, cmd->GetOffset()); EXPECT_EQ(16U, cmd->GetSize()); - auto* fmt = cmd->GetFormat(); + auto* fmt = cmd->GetBuffer()->GetFormat(); EXPECT_TRUE(fmt->IsFloat()); EXPECT_EQ(1U, fmt->ColumnCount()); EXPECT_EQ(3U, fmt->RowCount()); @@ -3844,7 +3844,7 @@ TEST_F(CommandParserTest, ToleranceWithCommas) { TEST_F(CommandParserTest, ProbeSSBOWithTolerance) { std::string data = R"( -ssbo 3:6 2 +ssbo 3:6 3 tolerance 2 3 4 5 probe ssbo vec3 3:6 2 >= 2.3 4.2 1.2)"; diff --git a/src/vkscript/parser_test.cc b/src/vkscript/parser_test.cc index 8c63b52a0..36eb2f59f 100644 --- a/src/vkscript/parser_test.cc +++ b/src/vkscript/parser_test.cc @@ -261,7 +261,9 @@ TEST_F(VkScriptParserTest, IndicesBlock) { auto buffer = buffer_ptr; EXPECT_TRUE(buffer->GetFormat()->IsUint32()); - EXPECT_EQ(3U, buffer->GetSize()); + EXPECT_EQ(3U, buffer->ElementCount()); + EXPECT_EQ(3U, buffer->ValueCount()); + EXPECT_EQ(3U * sizeof(uint32_t), buffer->GetSizeInBytes()); const auto* data = buffer->GetValues(); EXPECT_EQ(1, data[0]); @@ -288,7 +290,7 @@ TEST_F(VkScriptParserTest, IndicesBlockMultipleLines) { const auto* data = buffers[1]->GetValues(); std::vector results = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - ASSERT_EQ(results.size(), buffers[1]->GetSize()); + ASSERT_EQ(results.size(), buffers[1]->ValueCount()); for (size_t i = 0; i < results.size(); ++i) { EXPECT_EQ(results[i], data[i]); } @@ -338,13 +340,13 @@ TEST_F(VkScriptParserTest, VertexDataHeaderFormatString) { EXPECT_EQ(static_cast(0U), buffers[1]->GetLocation()); EXPECT_EQ(FormatType::kR32G32_SFLOAT, buffers[1]->GetFormat()->GetFormatType()); - EXPECT_EQ(static_cast(0), buffers[1]->GetSize()); + EXPECT_EQ(static_cast(0), buffers[1]->ElementCount()); ASSERT_EQ(BufferType::kVertex, buffers[2]->GetBufferType()); EXPECT_EQ(1U, buffers[2]->GetLocation()); EXPECT_EQ(FormatType::kA8B8G8R8_UNORM_PACK32, buffers[2]->GetFormat()->GetFormatType()); - EXPECT_EQ(static_cast(0), buffers[2]->GetSize()); + EXPECT_EQ(static_cast(0), buffers[2]->ElementCount()); } TEST_F(VkScriptParserTest, VertexDataHeaderGlslString) { @@ -368,7 +370,7 @@ TEST_F(VkScriptParserTest, VertexDataHeaderGlslString) { ASSERT_EQ(2U, comps1.size()); EXPECT_EQ(FormatMode::kSFloat, comps1[0].mode); EXPECT_EQ(FormatMode::kSFloat, comps1[1].mode); - EXPECT_EQ(static_cast(0), buffers[1]->GetSize()); + EXPECT_EQ(static_cast(0), buffers[1]->ElementCount()); ASSERT_EQ(BufferType::kVertex, buffers[2]->GetBufferType()); EXPECT_EQ(1U, buffers[2]->GetLocation()); @@ -379,7 +381,7 @@ TEST_F(VkScriptParserTest, VertexDataHeaderGlslString) { EXPECT_EQ(FormatMode::kSInt, comps2[0].mode); EXPECT_EQ(FormatMode::kSInt, comps2[1].mode); EXPECT_EQ(FormatMode::kSInt, comps2[2].mode); - EXPECT_EQ(static_cast(0), buffers[2]->GetSize()); + EXPECT_EQ(static_cast(0), buffers[2]->ElementCount()); } TEST_F(VkScriptParserTest, TestBlock) { @@ -434,7 +436,7 @@ TEST_F(VkScriptParserTest, VertexDataRows) { std::vector seg_0 = {-1.f, -1.f, 0.25f, 0.25f, -1.f, 0.25f}; const auto* values_0 = buffers[1]->GetValues(); - ASSERT_EQ(seg_0.size(), buffers[1]->GetSize()); + ASSERT_EQ(seg_0.size(), buffers[1]->ValueCount()); for (size_t i = 0; i < seg_0.size(); ++i) { EXPECT_FLOAT_EQ(seg_0[i], values_0[i]); } @@ -443,7 +445,7 @@ TEST_F(VkScriptParserTest, VertexDataRows) { std::vector seg_1 = {255, 128, 1, 255, 128, 255}; const auto* values_1 = buffers[2]->GetValues(); - ASSERT_EQ(seg_1.size(), buffers[2]->GetSize()); + ASSERT_EQ(seg_1.size(), buffers[2]->ValueCount()); for (size_t i = 0; i < seg_1.size(); ++i) { EXPECT_EQ(seg_1[i], values_1[i]); } @@ -493,7 +495,7 @@ TEST_F(VkScriptParserTest, VertexDataRowsWithHex) { std::vector seg_0 = {0xff0000ff, 0xffff0000}; const auto* values_0 = buffers[1]->GetValues(); - ASSERT_EQ(seg_0.size(), buffers[1]->GetSize()); + ASSERT_EQ(seg_0.size(), buffers[1]->ValueCount()); for (size_t i = 0; i < seg_0.size(); ++i) { EXPECT_EQ(seg_0[i], values_0[i]); diff --git a/src/vulkan/buffer_descriptor.cc b/src/vulkan/buffer_descriptor.cc index 985fcca53..527801dc8 100644 --- a/src/vulkan/buffer_descriptor.cc +++ b/src/vulkan/buffer_descriptor.cc @@ -111,7 +111,8 @@ Result BufferDescriptor::MoveResourceToBufferOutput() { } auto size_in_bytes = transfer_buffer_->GetSizeInBytes(); - amber_buffer_->SetSize(size_in_bytes); + amber_buffer_->SetElementCount(size_in_bytes / + amber_buffer_->GetFormat()->SizeInBytes()); amber_buffer_->ValuePtr()->resize(size_in_bytes); std::memcpy(amber_buffer_->ValuePtr()->data(), resource_memory_ptr, size_in_bytes); @@ -146,8 +147,7 @@ void BufferDescriptor::UpdateDescriptorSetIfNeeded( is_descriptor_set_update_needed_ = false; } -Result BufferDescriptor::AddToBuffer(Format* fmt, - uint32_t offset, +Result BufferDescriptor::AddToBuffer(uint32_t offset, uint32_t size_in_bytes, const std::vector& values) { if (!amber_buffer_) @@ -155,10 +155,11 @@ Result BufferDescriptor::AddToBuffer(Format* fmt, if (amber_buffer_->ValuePtr()->size() < offset + size_in_bytes) { amber_buffer_->ValuePtr()->resize(offset + size_in_bytes); - amber_buffer_->SetSize(offset + size_in_bytes); + amber_buffer_->SetElementCount((offset + size_in_bytes) / + amber_buffer_->GetFormat()->SizeInBytes()); } - BufferInput in{offset, size_in_bytes, fmt, values}; + BufferInput in{offset, size_in_bytes, amber_buffer_->GetFormat(), values}; in.UpdateBufferWithValues(amber_buffer_->ValuePtr()->data()); return {}; diff --git a/src/vulkan/buffer_descriptor.h b/src/vulkan/buffer_descriptor.h index 87339320a..d63e16f83 100644 --- a/src/vulkan/buffer_descriptor.h +++ b/src/vulkan/buffer_descriptor.h @@ -68,8 +68,7 @@ class BufferDescriptor { Result MoveResourceToBufferOutput(); void UpdateDescriptorSetIfNeeded(VkDescriptorSet descriptor_set); - Result AddToBuffer(Format* fmt, - uint32_t offset, + Result AddToBuffer(uint32_t offset, uint32_t size_in_bytes, const std::vector& values); diff --git a/src/vulkan/engine_vulkan.cc b/src/vulkan/engine_vulkan.cc index e0d1cedf0..c32d14bc9 100644 --- a/src/vulkan/engine_vulkan.cc +++ b/src/vulkan/engine_vulkan.cc @@ -222,7 +222,6 @@ Result EngineVulkan::CreatePipeline(amber::Pipeline* pipeline) { cmd->SetDescriptorSet(buf_info.descriptor_set); cmd->SetBinding(buf_info.binding); cmd->SetBuffer(buf_info.buffer); - cmd->SetFormat(buf_info.buffer->AsDataBuffer()->GetDatumType().AsFormat()); r = info.vk_pipeline->AddDescriptor(cmd.get()); if (!r.IsSuccess()) diff --git a/src/vulkan/index_buffer.cc b/src/vulkan/index_buffer.cc index 625a18b0e..a86194e36 100644 --- a/src/vulkan/index_buffer.cc +++ b/src/vulkan/index_buffer.cc @@ -33,7 +33,7 @@ Result IndexBuffer::SendIndexData(CommandBuffer* command, Buffer* buffer) { "IndexBuffer::SendIndexData must be called once when it is created"); } - if (buffer->GetSize() == 0) + if (buffer->ElementCount() == 0) return Result("IndexBuffer::SendIndexData |buffer| is empty"); transfer_buffer_ = diff --git a/src/vulkan/pipeline.cc b/src/vulkan/pipeline.cc index 5bfe7a112..a9c6a7cd2 100644 --- a/src/vulkan/pipeline.cc +++ b/src/vulkan/pipeline.cc @@ -300,8 +300,8 @@ Result Pipeline::AddDescriptor(const BufferCommand* cmd) { if (!cmd->GetValues().empty()) { auto* buf_desc = static_cast(desc); - Result r = buf_desc->AddToBuffer(cmd->GetFormat(), cmd->GetOffset(), - cmd->GetSize(), cmd->GetValues()); + Result r = buf_desc->AddToBuffer(cmd->GetOffset(), cmd->GetSize(), + cmd->GetValues()); if (!r.IsSuccess()) return r; } diff --git a/src/vulkan/push_constant.cc b/src/vulkan/push_constant.cc index 9855dc0f2..7bb6b54ed 100644 --- a/src/vulkan/push_constant.cc +++ b/src/vulkan/push_constant.cc @@ -107,7 +107,7 @@ Result PushConstant::AddBufferData(const BufferCommand* command) { "PushConstant::AddBufferData BufferCommand type is not push constant"); push_constant_data_.emplace_back(); - push_constant_data_.back().format = command->GetFormat(); + push_constant_data_.back().format = command->GetBuffer()->GetFormat(); push_constant_data_.back().offset = command->GetOffset(); push_constant_data_.back().size_in_bytes = command->GetSize(); push_constant_data_.back().values = command->GetValues(); diff --git a/src/vulkan/vertex_buffer.h b/src/vulkan/vertex_buffer.h index 8e7d1861f..e6de9774c 100644 --- a/src/vulkan/vertex_buffer.h +++ b/src/vulkan/vertex_buffer.h @@ -58,7 +58,7 @@ class VertexBuffer { uint32_t GetVertexCount() const { if (data_.empty()) return 0; - return data_[0]->GetSize(); + return data_[0]->ElementCount(); } void BindToCommandBuffer(CommandBuffer* command); diff --git a/src/vulkan/vertex_buffer_test.cc b/src/vulkan/vertex_buffer_test.cc index a4bb7e7ae..66384b012 100644 --- a/src/vulkan/vertex_buffer_test.cc +++ b/src/vulkan/vertex_buffer_test.cc @@ -55,7 +55,7 @@ class VertexBufferTest : public testing::Test { ~VertexBufferTest() = default; Result SetIntData(uint8_t location, - std::unique_ptr&& format, + std::unique_ptr format, std::vector values) { auto buffer = MakeUnique(); buffer->SetFormat(std::move(format)); @@ -66,7 +66,7 @@ class VertexBufferTest : public testing::Test { } Result SetDoubleData(uint8_t location, - std::unique_ptr&& format, + std::unique_ptr format, std::vector values) { auto buffer = MakeUnique(); buffer->SetFormat(std::move(format)); @@ -251,7 +251,7 @@ TEST_F(VertexBufferTest, R64G64B64A64_SINT) { values[3].SetIntValue(255); auto format = MakeUnique(); - format->SetFormatType(FormatType::kR64G64B64A64_SINT); + format->SetFormatType(FormatType::kR64G64B64_SINT); format->AddComponent(FormatComponentType::kR, FormatMode::kSInt, 64); format->AddComponent(FormatComponentType::kG, FormatMode::kSInt, 64); format->AddComponent(FormatComponentType::kB, FormatMode::kSInt, 64); @@ -265,105 +265,6 @@ TEST_F(VertexBufferTest, R64G64B64A64_SINT) { EXPECT_EQ(255, ptr[3]); } -TEST_F(VertexBufferTest, R16G11B10_SFLOAT) { - std::vector values(3); - - // 16 bits float to float - // Sig / Exp / Mantissa Sig / Exp / Mantissa - // 1 / 17 / 512 --> 1 / 129 / 4194304 = -1.1(2) * 2^2 = -6 - uint64_t expected = 50688ULL; - values[0].SetDoubleValue(-6.0); - - // 11 bits float to float - // Sig / Exp / Mantissa Sig / Exp / Mantissa - // 0 / 18 / 48 --> 0 / 130 / 12582912 = 1.11(2) * 2^3 = 14 - expected |= 1200ULL << 16ULL; - values[1].SetDoubleValue(14.0); - - // 10 bits float to float - // Sig / Exp / Mantissa Sig / Exp / Mantissa - // 0 / 11 / 28 --> 1 / 123 / 14680064 = 1.111(2) * 2^-4 - // = 0.1171875 - expected |= 380ULL << (16ULL + 11ULL); - values[2].SetDoubleValue(0.1171875); - - auto format = MakeUnique(); - format->SetFormatType(FormatType::kR32G32_SFLOAT); // big enough to cover. - format->AddComponent(FormatComponentType::kR, FormatMode::kSFloat, 16); - format->AddComponent(FormatComponentType::kG, FormatMode::kSFloat, 11); - format->AddComponent(FormatComponentType::kB, FormatMode::kSFloat, 10); - - Result r = SetDoubleData(0, std::move(format), values); - const uint64_t* ptr = static_cast(GetVkBufferPtr()); - EXPECT_EQ(expected, *ptr); -} - -TEST_F(VertexBufferTest, R10G16B11_SFLOAT) { - std::vector values(3); - - // 10 bits float to float - // Sig / Exp / Mantissa Sig / Exp / Mantissa - // 0 / 11 / 28 --> 1 / 123 / 14680064 = 1.111(2) * 2^-4 - // = 0.1171875 - uint64_t expected = 380ULL; - values[0].SetDoubleValue(0.1171875); - - // 16 bits float to float - // Sig / Exp / Mantissa Sig / Exp / Mantissa - // 1 / 17 / 512 --> 1 / 129 / 4194304 = -1.1(2) * 2^2 = -6 - expected |= 50688ULL << 10ULL; - values[1].SetDoubleValue(-6.0); - - // 11 bits float to float - // Sig / Exp / Mantissa Sig / Exp / Mantissa - // 0 / 18 / 48 --> 0 / 130 / 12582912 = 1.11(2) * 2^3 = 14 - expected |= 1200ULL << (16ULL + 10ULL); - values[2].SetDoubleValue(14.0); - - auto format = MakeUnique(); - format->SetFormatType(FormatType::kR32G32_SFLOAT); // big enough to cover. - format->AddComponent(FormatComponentType::kR, FormatMode::kSFloat, 10); - format->AddComponent(FormatComponentType::kG, FormatMode::kSFloat, 16); - format->AddComponent(FormatComponentType::kB, FormatMode::kSFloat, 11); - - Result r = SetDoubleData(0, std::move(format), values); - const uint64_t* ptr = static_cast(GetVkBufferPtr()); - EXPECT_EQ(expected, *ptr); -} - -TEST_F(VertexBufferTest, R11G16B10_SFLOAT) { - std::vector values(3); - - // 11 bits float to float - // Sig / Exp / Mantissa Sig / Exp / Mantissa - // 0 / 18 / 48 --> 0 / 130 / 12582912 = 1.11(2) * 2^3 = 14 - uint64_t expected = 1200ULL; - values[0].SetDoubleValue(14.0); - - // 16 bits float to float - // Sig / Exp / Mantissa Sig / Exp / Mantissa - // 1 / 17 / 512 --> 1 / 129 / 4194304 = -1.1(2) * 2^2 = -6 - expected |= 50688ULL << 11ULL; - values[1].SetDoubleValue(-6.0); - - // 10 bits float to float - // Sig / Exp / Mantissa Sig / Exp / Mantissa - // 0 / 11 / 28 --> 1 / 123 / 14680064 = 1.111(2) * 2^-4 - // = 0.1171875 - expected |= 380ULL << (16ULL + 11ULL); - values[2].SetDoubleValue(0.1171875); - - auto format = MakeUnique(); - format->SetFormatType(FormatType::kR32G32_SFLOAT); // big enough to cover. - format->AddComponent(FormatComponentType::kR, FormatMode::kSFloat, 11); - format->AddComponent(FormatComponentType::kG, FormatMode::kSFloat, 16); - format->AddComponent(FormatComponentType::kB, FormatMode::kSFloat, 10); - - Result r = SetDoubleData(0, std::move(format), values); - const uint64_t* ptr = static_cast(GetVkBufferPtr()); - EXPECT_EQ(expected, *ptr); -} - TEST_F(VertexBufferTest, R32G32B32_SFLOAT) { std::vector values(3); values[0].SetDoubleValue(-6.0); diff --git a/tests/cases/compute_mat2x2.vkscript b/tests/cases/compute_mat2x2.vkscript index ecf6b5cda..95d38b2e8 100644 --- a/tests/cases/compute_mat2x2.vkscript +++ b/tests/cases/compute_mat2x2.vkscript @@ -35,30 +35,6 @@ void main() { [test] -# Fill mat2x2 using float -# MatrixStride == 8 -ssbo 0:0 subdata float 0 1.0 0.0 \ - 0.0 1.0 -# MatrixStride == 16 -uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 - -ssbo 0:2 subdata vec2 0 3.7 9.4 -ssbo 0:2 subdata vec2 8 4.5 6.1 - -compute 1 1 1 - -probe ssbo vec2 0:2 0 ~= 3.7 9.4 -probe ssbo vec2 0:2 8 ~= 4.5 6.1 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 \ - 0.0 0.0 -uniform ubo 0:1 float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 - - # Fill mat2x2 using mat2 # MatrixStride == 8 ssbo 0:0 subdata mat2 0 1.0 0.0 \ diff --git a/tests/cases/compute_mat2x2float.vkscript b/tests/cases/compute_mat2x2float.vkscript new file mode 100644 index 000000000..259e4e643 --- /dev/null +++ b/tests/cases/compute_mat2x2float.vkscript @@ -0,0 +1,51 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat2 identical_mat_0; +}; + +layout(set = 0, binding = 1) uniform block1 { + mat2 identical_mat_1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec2 test0; + vec2 test1; +}; + +void main() { + test0 = identical_mat_0 * test0; + test1 = identical_mat_1 * test1; +} + +[test] +# Fill mat2x2 using float +# MatrixStride == 8 +ssbo 0:0 subdata float 0 1.0 0.0 \ + 0.0 1.0 +# MatrixStride == 16 +uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 + +ssbo 0:2 subdata vec2 0 3.7 9.4 +ssbo 0:2 subdata vec2 8 4.5 6.1 + +compute 1 1 1 + +probe ssbo vec2 0:2 0 ~= 3.7 9.4 +probe ssbo vec2 0:2 8 ~= 4.5 6.1 diff --git a/tests/cases/compute_mat2x3.vkscript b/tests/cases/compute_mat2x3.vkscript index 151e5f996..a1f1005ab 100644 --- a/tests/cases/compute_mat2x3.vkscript +++ b/tests/cases/compute_mat2x3.vkscript @@ -35,30 +35,6 @@ void main() { [test] -# Fill mat2x3 using float -# MatrixStride == 16 -ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 1.0 -# MatrixStride == 16 -uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 1.0 - -ssbo 0:2 subdata vec2 0 3.7 9.4 -ssbo 0:2 subdata vec2 8 4.5 6.1 - -compute 1 1 1 - -probe ssbo vec2 0:2 0 ~= 3.7 9.4 -probe ssbo vec2 0:2 8 ~= 4.5 6.1 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 -uniform ubo 0:1 float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 - - # Fill mat2x3 using mat2x3 # MatrixStride == 16 ssbo 0:0 subdata mat2x3 0 1.0 0.0 0.0 \ diff --git a/tests/cases/compute_mat2x3float.vkscript b/tests/cases/compute_mat2x3float.vkscript new file mode 100644 index 000000000..1d37f85ad --- /dev/null +++ b/tests/cases/compute_mat2x3float.vkscript @@ -0,0 +1,52 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat2x3 transform0; +}; + +layout(set = 0, binding = 1) uniform block1 { + mat2x3 transform1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec2 test0; + vec2 test1; +}; + +void main() { + test0 = (transform0 * test0).xy; + test1 = (transform1 * test1).xy; +} + +[test] + +# Fill mat2x3 using float +# MatrixStride == 16 +ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 1.0 +# MatrixStride == 16 +uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 1.0 + +ssbo 0:2 subdata vec2 0 3.7 9.4 +ssbo 0:2 subdata vec2 8 4.5 6.1 + +compute 1 1 1 + +probe ssbo vec2 0:2 0 ~= 3.7 9.4 +probe ssbo vec2 0:2 8 ~= 4.5 6.1 diff --git a/tests/cases/compute_mat3x2.vkscript b/tests/cases/compute_mat3x2.vkscript index 973edbde0..8f2d4b6c0 100644 --- a/tests/cases/compute_mat3x2.vkscript +++ b/tests/cases/compute_mat3x2.vkscript @@ -34,41 +34,6 @@ void main() { } [test] -# Fill mat3x2 using float -# MatrixStride == 8 -ssbo 0:0 subdata float 0 1.0 0.0 \ - 0.0 1.0 \ - 0.0 1.0 -# MatrixStride == 16 -uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 1.0 - -ssbo 0:2 subdata vec3 0 7.3 9.4 -5.8 -ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 - -compute 1 1 1 - -tolerance 0.1% - -# 3.6 == 9.4 + -5.8 -# i.e., test0.y + test0.z -probe ssbo vec3 0:2 0 ~= 7.3 3.6 1.0 - -# 2.3 == 6.1 + -3.8 -# i.e., test1.y + test1.z -probe ssbo vec3 0:2 16 ~= 4.5 2.3 1.0 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 \ - 0.0 0.0 \ - 0.0 0.0 -uniform ubo 0:1 float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 - - # Fill mat3x2 using float # MatrixStride == 8 ssbo 0:0 subdata mat3x2 0 1.0 0.0 \ diff --git a/tests/cases/compute_mat3x2float.vkscript b/tests/cases/compute_mat3x2float.vkscript new file mode 100644 index 000000000..c84cfd61b --- /dev/null +++ b/tests/cases/compute_mat3x2float.vkscript @@ -0,0 +1,60 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat3x2 transform0; +}; + +layout(set = 0, binding = 1) uniform block1 { + mat3x2 transform1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec3 test0; + vec3 test1; +}; + +void main() { + test0 = vec3(transform0 * test0, 1.0); + test1 = vec3(transform1 * test1, 1.0); +} + +[test] +# Fill mat3x2 using float +# MatrixStride == 8 +ssbo 0:0 subdata float 0 1.0 0.0 \ + 0.0 1.0 \ + 0.0 1.0 +# MatrixStride == 16 +uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 1.0 + +ssbo 0:2 subdata vec3 0 7.3 9.4 -5.8 +ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 + +compute 1 1 1 + +tolerance 0.1% + +# 3.6 == 9.4 + -5.8 +# i.e., test0.y + test0.z +probe ssbo vec3 0:2 0 ~= 7.3 3.6 1.0 + +# 2.3 == 6.1 + -3.8 +# i.e., test1.y + test1.z +probe ssbo vec3 0:2 16 ~= 4.5 2.3 1.0 diff --git a/tests/cases/compute_mat3x3.vkscript b/tests/cases/compute_mat3x3.vkscript index af9fafc6b..22b719a63 100644 --- a/tests/cases/compute_mat3x3.vkscript +++ b/tests/cases/compute_mat3x3.vkscript @@ -34,35 +34,6 @@ void main() { } [test] - -# Fill mat3x3 using float -# MatrixStride == 16 -ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 -# MatrixStride == 16 -uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 - -ssbo 0:2 subdata vec3 0 3.7 9.4 -5.8 -ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 - -compute 1 1 1 - -probe ssbo vec3 0:2 0 ~= 3.7 9.4 -5.8 -probe ssbo vec3 0:2 16 ~= 4.5 6.1 -3.8 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 \ - 0.0 0.0 0.0 -uniform ubo 0:1 float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 - - # Fill mat3x3 using mat3 # MatrixStride == 16 ssbo 0:0 subdata mat3 0 1.0 0.0 0.0 \ diff --git a/tests/cases/compute_mat3x3float.vkscript b/tests/cases/compute_mat3x3float.vkscript new file mode 100644 index 000000000..3bbfd99e4 --- /dev/null +++ b/tests/cases/compute_mat3x3float.vkscript @@ -0,0 +1,54 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat3 identical_mat_0; +}; + +layout(set = 0, binding = 1) uniform block1 { + mat3 identical_mat_1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec3 test0; + vec3 test1; +}; + +void main() { + test0 = identical_mat_0 * test0; + test1 = identical_mat_1 * test1; +} + +[test] + +# Fill mat3x3 using float +# MatrixStride == 16 +ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 +# MatrixStride == 16 +uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 + +ssbo 0:2 subdata vec3 0 3.7 9.4 -5.8 +ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 + +compute 1 1 1 + +probe ssbo vec3 0:2 0 ~= 3.7 9.4 -5.8 +probe ssbo vec3 0:2 16 ~= 4.5 6.1 -3.8 diff --git a/tests/cases/compute_mat3x4.vkscript b/tests/cases/compute_mat3x4.vkscript index 1b682aa39..d5f510e12 100644 --- a/tests/cases/compute_mat3x4.vkscript +++ b/tests/cases/compute_mat3x4.vkscript @@ -34,36 +34,6 @@ void main() { } [test] - -# Fill mat3x4 using float -# MatrixStride == 16 -ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 1.0 -# MatrixStride == 16 -uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 1.0 - -ssbo 0:2 subdata vec3 0 7.3 9.4 -5.8 -ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 - -compute 1 1 1 - -tolerance 0.1% - -probe ssbo vec3 0:2 0 ~= 7.3 9.4 -5.8 -probe ssbo vec3 0:2 16 ~= 4.5 6.1 -3.8 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 -uniform ubo 0:1 float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 - # Fill mat3x4 using mat3x4 # MatrixStride == 16 ssbo 0:0 subdata mat3x4 0 1.0 0.0 0.0 0.0 \ diff --git a/tests/cases/compute_mat3x4float.vkscript b/tests/cases/compute_mat3x4float.vkscript new file mode 100644 index 000000000..031aa8deb --- /dev/null +++ b/tests/cases/compute_mat3x4float.vkscript @@ -0,0 +1,56 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat3x4 transform0; +}; + +layout(set = 0, binding = 1) uniform block1 { + mat3x4 transform1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec3 test0; + vec3 test1; +}; + +void main() { + test0 = (transform0 * test0).xyz; + test1 = (transform1 * test1).xyz; +} + +[test] + +# Fill mat3x4 using float +# MatrixStride == 16 +ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 1.0 +# MatrixStride == 16 +uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 1.0 + +ssbo 0:2 subdata vec3 0 7.3 9.4 -5.8 +ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 + +compute 1 1 1 + +tolerance 0.1% + +probe ssbo vec3 0:2 0 ~= 7.3 9.4 -5.8 +probe ssbo vec3 0:2 16 ~= 4.5 6.1 -3.8 diff --git a/tests/cases/compute_mat4x3.vkscript b/tests/cases/compute_mat4x3.vkscript index ed425200c..d65fb338a 100644 --- a/tests/cases/compute_mat4x3.vkscript +++ b/tests/cases/compute_mat4x3.vkscript @@ -34,40 +34,6 @@ void main() { } [test] - -# Fill mat4x3 using float -# MatrixStride == 16 -ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 0.0 \ - 0.0 0.0 1.0 -# MatrixStride == 16 -uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 0.0 \ - 0.0 0.0 1.0 - -ssbo 0:2 subdata vec4 0 7.3 9.4 -5.8 -0.2 -ssbo 0:2 subdata vec4 16 4.5 6.1 -3.8 -0.7 - -compute 1 1 1 - -tolerance 0.1% - -probe ssbo vec4 0:2 0 ~= 7.3 9.4 -6.0 0 -probe ssbo vec4 0:2 16 ~= 4.5 6.1 -4.5 0 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 -uniform ubo 0:1 float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 - # Fill mat4x3 using mat4x3 # MatrixStride == 16 ssbo 0:0 subdata mat4x3 0 1.0 0.0 0.0 \ diff --git a/tests/cases/compute_mat4x3float.vkscript b/tests/cases/compute_mat4x3float.vkscript new file mode 100644 index 000000000..a018a030e --- /dev/null +++ b/tests/cases/compute_mat4x3float.vkscript @@ -0,0 +1,58 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat4x3 transform0; +}; + +layout(set = 0, binding = 1) uniform block1 { + mat4x3 transform1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec4 test0; + vec4 test1; +}; + +void main() { + test0 = vec4(transform0 * test0, 0); + test1 = vec4(transform1 * test1, 0); +} + +[test] + +# Fill mat4x3 using float +# MatrixStride == 16 +ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 0.0 \ + 0.0 0.0 1.0 +# MatrixStride == 16 +uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 0.0 \ + 0.0 0.0 1.0 + +ssbo 0:2 subdata vec4 0 7.3 9.4 -5.8 -0.2 +ssbo 0:2 subdata vec4 16 4.5 6.1 -3.8 -0.7 + +compute 1 1 1 + +tolerance 0.1% + +probe ssbo vec4 0:2 0 ~= 7.3 9.4 -6.0 0 +probe ssbo vec4 0:2 16 ~= 4.5 6.1 -4.5 0 diff --git a/tests/cases/compute_nothing_with_ssbo.vkscript b/tests/cases/compute_nothing_with_ssbo.vkscript index 050cc0004..49731e543 100644 --- a/tests/cases/compute_nothing_with_ssbo.vkscript +++ b/tests/cases/compute_nothing_with_ssbo.vkscript @@ -23,15 +23,14 @@ void main() { } [test] -ssbo 1:2 subdata vec4 0 0.1 0.2 0.3 0.4 +ssbo 1:2 subdata float 0 0.1 0.2 0.3 0.4 compute 4 1 1 -probe ssbo float 1:2 0 ~= 0.1 0.2 0.3 0.4 - +probe ssbo float 1:2 0 ~= 0.1 0.2 0.3 0.4 ssbo 1:2 subdata float 0 0.57 0.56 0.55 0.54 \ 0.53 0.52 0.51 0.50 \ 0.49 0.48 0.47 compute 4 1 1 -probe ssbo float 1:2 0 ~= 0.57 0.56 0.55 0.54 \ - 0.53 0.52 0.51 0.50 \ - 0.49 0.48 0.47 +probe ssbo float 1:2 0 ~= 0.57 0.56 0.55 0.54 \ + 0.53 0.52 0.51 0.50 \ + 0.49 0.48 0.47 diff --git a/tests/cases/compute_probe_mat3.vkscript b/tests/cases/compute_probe_mat3.vkscript index 9b2a30fd3..6fd4c328d 100644 --- a/tests/cases/compute_probe_mat3.vkscript +++ b/tests/cases/compute_probe_mat3.vkscript @@ -32,16 +32,16 @@ void main() { # MatrixStride == 16 ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 + 0.0 0.0 1.0 0.0 # MatrixStride == 16 uniform ubo 0:1 float 0 1.0 0.0 0.0 0.0 \ 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 + 0.0 0.0 1.0 0.0 compute 1 1 1 tolerance 0.1% -probe ssbo mat3 0:0 0 ~= 1.0 0.0 0.0 \ - 0.0 1.0 0.0 \ - 0.0 0.0 1.0 +probe ssbo float 0:0 0 ~= 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 0.0 diff --git a/tests/cases/compute_push_const_mat2x2.vkscript b/tests/cases/compute_push_const_mat2x2.vkscript index a4dd1034f..7ac52eb64 100644 --- a/tests/cases/compute_push_const_mat2x2.vkscript +++ b/tests/cases/compute_push_const_mat2x2.vkscript @@ -34,31 +34,6 @@ void main() { } [test] - -# Fill mat2x2 using float -# MatrixStride == 8 -ssbo 0:0 subdata float 0 1.0 0.0 \ - 0.0 1.0 -# MatrixStride == 8 -uniform float 0 1.0 0.0 \ - 0.0 1.0 - -ssbo 0:2 subdata vec2 0 3.7 9.4 -ssbo 0:2 subdata vec2 8 4.5 6.1 - -compute 1 1 1 - -probe ssbo vec2 0:2 0 ~= 3.7 9.4 -probe ssbo vec2 0:2 8 ~= 4.5 6.1 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 \ - 0.0 0.0 -uniform float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 - - # Fill mat2x2 using mat2 # MatrixStride == 8 ssbo 0:0 subdata mat2 0 1.0 0.0 \ diff --git a/tests/cases/compute_push_const_mat2x2float.vkscript b/tests/cases/compute_push_const_mat2x2float.vkscript new file mode 100644 index 000000000..73155fb28 --- /dev/null +++ b/tests/cases/compute_push_const_mat2x2float.vkscript @@ -0,0 +1,52 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat2 identical_mat_0; +}; + +layout(push_constant) uniform block1 { + mat2 identical_mat_1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec2 test0; + vec2 test1; +}; + +void main() { + test0 = identical_mat_0 * test0; + test1 = identical_mat_1 * test1; +} + +[test] + +# Fill mat2x2 using float +# MatrixStride == 8 +ssbo 0:0 subdata float 0 1.0 0.0 \ + 0.0 1.0 +# MatrixStride == 8 +uniform float 0 1.0 0.0 \ + 0.0 1.0 + +ssbo 0:2 subdata vec2 0 3.7 9.4 +ssbo 0:2 subdata vec2 8 4.5 6.1 + +compute 1 1 1 + +probe ssbo vec2 0:2 0 ~= 3.7 9.4 +probe ssbo vec2 0:2 8 ~= 4.5 6.1 diff --git a/tests/cases/compute_push_const_mat2x3.vkscript b/tests/cases/compute_push_const_mat2x3.vkscript index 9c6122868..1a9c5a04f 100644 --- a/tests/cases/compute_push_const_mat2x3.vkscript +++ b/tests/cases/compute_push_const_mat2x3.vkscript @@ -34,31 +34,6 @@ void main() { } [test] - -# Fill mat2x3 using float -# MatrixStride == 16 -ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 1.0 -# MatrixStride == 16 -uniform float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 1.0 - -ssbo 0:2 subdata vec2 0 3.7 9.4 -ssbo 0:2 subdata vec2 8 4.5 6.1 - -compute 1 1 1 - -probe ssbo vec2 0:2 0 ~= 3.7 9.4 -probe ssbo vec2 0:2 8 ~= 4.5 6.1 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 -uniform float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 - - # Fill mat2x3 using mat2x3 # MatrixStride == 16 ssbo 0:0 subdata mat2x3 0 1.0 0.0 0.0 \ diff --git a/tests/cases/compute_push_const_mat2x3float.vkscript b/tests/cases/compute_push_const_mat2x3float.vkscript new file mode 100644 index 000000000..d8ad41e04 --- /dev/null +++ b/tests/cases/compute_push_const_mat2x3float.vkscript @@ -0,0 +1,52 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat2x3 transform0; +}; + +layout(push_constant) uniform block1 { + mat2x3 transform1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec2 test0; + vec2 test1; +}; + +void main() { + test0 = (transform0 * test0).xy; + test1 = (transform1 * test1).xy; +} + +[test] + +# Fill mat2x3 using float +# MatrixStride == 16 +ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 1.0 +# MatrixStride == 16 +uniform float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 1.0 + +ssbo 0:2 subdata vec2 0 3.7 9.4 +ssbo 0:2 subdata vec2 8 4.5 6.1 + +compute 1 1 1 + +probe ssbo vec2 0:2 0 ~= 3.7 9.4 +probe ssbo vec2 0:2 8 ~= 4.5 6.1 diff --git a/tests/cases/compute_push_const_mat3x2.vkscript b/tests/cases/compute_push_const_mat3x2.vkscript index 1c1d9c531..47ed72e38 100644 --- a/tests/cases/compute_push_const_mat3x2.vkscript +++ b/tests/cases/compute_push_const_mat3x2.vkscript @@ -34,41 +34,6 @@ void main() { } [test] -# Fill mat3x2 using float -# MatrixStride == 8 -ssbo 0:0 subdata float 0 1.0 0.0 \ - 0.0 1.0 \ - 0.0 1.0 -# MatrixStride == 8 -uniform float 0 1.0 0.0 \ - 0.0 1.0 \ - 0.0 1.0 - -ssbo 0:2 subdata vec3 0 7.3 9.4 -5.8 -ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 - -compute 1 1 1 - -tolerance 0.1% - -# 3.6 == 9.4 + -5.8 -# i.e., test0.y + test0.z -probe ssbo vec3 0:2 0 ~= 7.3 3.6 1.0 - -# 2.3 == 6.1 + -3.8 -# i.e., test1.y + test1.z -probe ssbo vec3 0:2 16 ~= 4.5 2.3 1.0 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 \ - 0.0 0.0 \ - 0.0 0.0 -uniform float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 - - # Fill mat3x2 using float # MatrixStride == 8 ssbo 0:0 subdata mat3x2 0 1.0 0.0 \ diff --git a/tests/cases/compute_push_const_mat3x2float.vkscript b/tests/cases/compute_push_const_mat3x2float.vkscript new file mode 100644 index 000000000..b1a7bd478 --- /dev/null +++ b/tests/cases/compute_push_const_mat3x2float.vkscript @@ -0,0 +1,60 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat3x2 transform0; +}; + +layout(push_constant) uniform block1 { + mat3x2 transform1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec3 test0; + vec3 test1; +}; + +void main() { + test0 = vec3(transform0 * test0, 1.0); + test1 = vec3(transform1 * test1, 1.0); +} + +[test] +# Fill mat3x2 using float +# MatrixStride == 8 +ssbo 0:0 subdata float 0 1.0 0.0 \ + 0.0 1.0 \ + 0.0 1.0 +# MatrixStride == 8 +uniform float 0 1.0 0.0 \ + 0.0 1.0 \ + 0.0 1.0 + +ssbo 0:2 subdata vec3 0 7.3 9.4 -5.8 +ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 + +compute 1 1 1 + +tolerance 0.1% + +# 3.6 == 9.4 + -5.8 +# i.e., test0.y + test0.z +probe ssbo vec3 0:2 0 ~= 7.3 3.6 1.0 + +# 2.3 == 6.1 + -3.8 +# i.e., test1.y + test1.z +probe ssbo vec3 0:2 16 ~= 4.5 2.3 1.0 diff --git a/tests/cases/compute_push_const_mat3x3.vkscript b/tests/cases/compute_push_const_mat3x3.vkscript index 23721a01f..690cd8418 100644 --- a/tests/cases/compute_push_const_mat3x3.vkscript +++ b/tests/cases/compute_push_const_mat3x3.vkscript @@ -34,35 +34,6 @@ void main() { } [test] - -# Fill mat3x3 using float -# MatrixStride == 16 -ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 -# MatrixStride == 16 -uniform float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 - -ssbo 0:2 subdata vec3 0 3.7 9.4 -5.8 -ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 - -compute 1 1 1 - -probe ssbo vec3 0:2 0 ~= 3.7 9.4 -5.8 -probe ssbo vec3 0:2 16 ~= 4.5 6.1 -3.8 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 \ - 0.0 0.0 0.0 -uniform float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 - - # Fill mat3x3 using mat3 # MatrixStride == 16 ssbo 0:0 subdata mat3 0 1.0 0.0 0.0 \ diff --git a/tests/cases/compute_push_const_mat3x3float.vkscript b/tests/cases/compute_push_const_mat3x3float.vkscript new file mode 100644 index 000000000..eff5805da --- /dev/null +++ b/tests/cases/compute_push_const_mat3x3float.vkscript @@ -0,0 +1,54 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat3 identical_mat_0; +}; + +layout(push_constant) uniform block1 { + mat3 identical_mat_1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec3 test0; + vec3 test1; +}; + +void main() { + test0 = identical_mat_0 * test0; + test1 = identical_mat_1 * test1; +} + +[test] + +# Fill mat3x3 using float +# MatrixStride == 16 +ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 +# MatrixStride == 16 +uniform float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 + +ssbo 0:2 subdata vec3 0 3.7 9.4 -5.8 +ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 + +compute 1 1 1 + +probe ssbo vec3 0:2 0 ~= 3.7 9.4 -5.8 +probe ssbo vec3 0:2 16 ~= 4.5 6.1 -3.8 diff --git a/tests/cases/compute_push_const_mat3x4.vkscript b/tests/cases/compute_push_const_mat3x4.vkscript index 364936de0..2ee1d62c7 100644 --- a/tests/cases/compute_push_const_mat3x4.vkscript +++ b/tests/cases/compute_push_const_mat3x4.vkscript @@ -34,36 +34,6 @@ void main() { } [test] - -# Fill mat3x4 using float -# MatrixStride == 16 -ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 1.0 -# MatrixStride == 16 -uniform float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 1.0 - -ssbo 0:2 subdata vec3 0 7.3 9.4 -5.8 -ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 - -compute 1 1 1 - -tolerance 0.1% - -probe ssbo vec3 0:2 0 ~= 7.3 9.4 -5.8 -probe ssbo vec3 0:2 16 ~= 4.5 6.1 -3.8 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 -uniform float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 - # Fill mat3x4 using mat3x4 # MatrixStride == 16 ssbo 0:0 subdata mat3x4 0 1.0 0.0 0.0 0.0 \ diff --git a/tests/cases/compute_push_const_mat3x4float.vkscript b/tests/cases/compute_push_const_mat3x4float.vkscript new file mode 100644 index 000000000..4d4d67786 --- /dev/null +++ b/tests/cases/compute_push_const_mat3x4float.vkscript @@ -0,0 +1,56 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat3x4 transform0; +}; + +layout(push_constant) uniform block1 { + mat3x4 transform1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec3 test0; + vec3 test1; +}; + +void main() { + test0 = (transform0 * test0).xyz; + test1 = (transform1 * test1).xyz; +} + +[test] + +# Fill mat3x4 using float +# MatrixStride == 16 +ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 1.0 +# MatrixStride == 16 +uniform float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 1.0 + +ssbo 0:2 subdata vec3 0 7.3 9.4 -5.8 +ssbo 0:2 subdata vec3 16 4.5 6.1 -3.8 + +compute 1 1 1 + +tolerance 0.1% + +probe ssbo vec3 0:2 0 ~= 7.3 9.4 -5.8 +probe ssbo vec3 0:2 16 ~= 4.5 6.1 -3.8 diff --git a/tests/cases/compute_push_const_mat4x3.vkscript b/tests/cases/compute_push_const_mat4x3.vkscript index 67a460403..0fe51b299 100644 --- a/tests/cases/compute_push_const_mat4x3.vkscript +++ b/tests/cases/compute_push_const_mat4x3.vkscript @@ -34,40 +34,6 @@ void main() { } [test] - -# Fill mat4x3 using float -# MatrixStride == 16 -ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 0.0 \ - 0.0 0.0 1.0 -# MatrixStride == 16 -uniform float 0 1.0 0.0 0.0 0.0 \ - 0.0 1.0 0.0 0.0 \ - 0.0 0.0 1.0 0.0 \ - 0.0 0.0 1.0 - -ssbo 0:2 subdata vec4 0 7.3 9.4 -5.8 -0.2 -ssbo 0:2 subdata vec4 16 4.5 6.1 -3.8 -0.7 - -compute 1 1 1 - -tolerance 0.1% - -probe ssbo vec4 0:2 0 ~= 7.3 9.4 -6.0 0 -probe ssbo vec4 0:2 16 ~= 4.5 6.1 -4.5 0 - - -# Clear matrices -ssbo 0:0 subdata float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 -uniform float 0 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 0.0 \ - 0.0 0.0 0.0 - # Fill mat4x3 using mat4x3 # MatrixStride == 16 ssbo 0:0 subdata mat4x3 0 1.0 0.0 0.0 \ diff --git a/tests/cases/compute_push_const_mat4x3float.vkscript b/tests/cases/compute_push_const_mat4x3float.vkscript new file mode 100644 index 000000000..88ba2f713 --- /dev/null +++ b/tests/cases/compute_push_const_mat4x3float.vkscript @@ -0,0 +1,58 @@ +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[compute shader] +#version 430 + +layout(set = 0, binding = 0) buffer block0 { + mat4x3 transform0; +}; + +layout(push_constant) uniform block1 { + mat4x3 transform1; +}; + +layout(set = 0, binding = 2) buffer block3 { + vec4 test0; + vec4 test1; +}; + +void main() { + test0 = vec4(transform0 * test0, 0); + test1 = vec4(transform1 * test1, 0); +} + +[test] + +# Fill mat4x3 using float +# MatrixStride == 16 +ssbo 0:0 subdata float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 0.0 \ + 0.0 0.0 1.0 +# MatrixStride == 16 +uniform float 0 1.0 0.0 0.0 0.0 \ + 0.0 1.0 0.0 0.0 \ + 0.0 0.0 1.0 0.0 \ + 0.0 0.0 1.0 + +ssbo 0:2 subdata vec4 0 7.3 9.4 -5.8 -0.2 +ssbo 0:2 subdata vec4 16 4.5 6.1 -3.8 -0.7 + +compute 1 1 1 + +tolerance 0.1% + +probe ssbo vec4 0:2 0 ~= 7.3 9.4 -6.0 0 +probe ssbo vec4 0:2 16 ~= 4.5 6.1 -4.5 0 diff --git a/tests/cases/compute_push_constant_and_ssbo.vkscript b/tests/cases/compute_push_constant_and_ssbo.vkscript index 3d75488e3..c095e3d7e 100644 --- a/tests/cases/compute_push_constant_and_ssbo.vkscript +++ b/tests/cases/compute_push_constant_and_ssbo.vkscript @@ -16,14 +16,14 @@ #version 430 layout(set = 0, binding = 0) buffer block0 { - float data_set0_binding0[]; + uint data_set0_binding0[]; }; // push_constant compiled as std430 by glslang layout(push_constant) uniform block1 { - float constant0[3]; // Offset: 0, array stride: 4 + uint constant0[3]; // Offset: 0, array stride: 4 uint constant1; // 12 - vec3 constant2[3]; // 16, array stride: 16 + uvec3 constant2[3]; // 16, array stride: 16 uint constant3; // 64 }; @@ -42,20 +42,20 @@ void main() { } [test] -ssbo 0:0 128 +ssbo 0:0 56 -uniform float 0 1 2 3 -uniform uint 12 4 -uniform float 16 5 6 7 0 \ +uniform uint 0 1 2 3 +uniform uint 12 4 +uniform uint 16 5 6 7 0 \ 8 9 10 0 \ 11 12 13 -uniform uint 64 14 +uniform uint 64 14 compute 3 1 1 -probe ssbo float 0:0 0 ~= 1 2 3 -probe ssbo float 0:0 12 ~= 4 -probe ssbo float 0:0 16 ~= 5 6 7 \ - 8 9 10 \ +probe ssbo uint 0:0 0 == 1 2 3 +probe ssbo uint 0:0 12 == 4 +probe ssbo uint 0:0 16 == 5 6 7 \ + 8 9 10 \ 11 12 13 -probe ssbo float 0:0 52 ~= 14 +probe ssbo uint 0:0 52 == 14 diff --git a/tests/cases/multiple_ssbo_update_with_graphics_pipeline.vkscript b/tests/cases/multiple_ssbo_update_with_graphics_pipeline.vkscript index 78279d814..173a52e61 100644 --- a/tests/cases/multiple_ssbo_update_with_graphics_pipeline.vkscript +++ b/tests/cases/multiple_ssbo_update_with_graphics_pipeline.vkscript @@ -85,22 +85,22 @@ void main() { [test] clear -ssbo 0 subdata vec4 0 0.1 0.2 0.3 0.4 -ssbo 0 subdata vec4 16 0.9 0.8 0.7 0.6 +ssbo 0 subdata float 0 0.1 0.2 0.3 0.4 +ssbo 0 subdata float 16 0.9 0.8 0.7 0.6 -ssbo 1:0 subdata vec4 0 0.1 0.2 0.3 0.4 -ssbo 1:2 subdata vec4 0 0.1 0.2 0.3 0.4 -ssbo 2:1 subdata vec4 0 0.1 0.2 0.3 0.4 -ssbo 2:3 subdata vec4 0 0.1 0.2 0.3 0.4 +ssbo 1:0 subdata float 0 0.1 0.2 0.3 0.4 +ssbo 1:2 subdata float 0 0.1 0.2 0.3 0.4 +ssbo 2:1 subdata float 0 0.1 0.2 0.3 0.4 +ssbo 2:3 subdata float 0 0.1 0.2 0.3 0.4 draw arrays TRIANGLE_LIST 0 6 relative probe rect rgba (0.0, 0.0, 1.0, 1.0) (1.0, 0.75, 0.625, 0.5) -ssbo 0 subdata vec4 0 0.5 0.5 0.25 1.0 \ - 0.3 0.2 0.1 0.4 \ - 0 0 0 0 +ssbo 0 subdata float 0 0.5 0.5 0.25 1.0 \ + 0.3 0.2 0.1 0.4 \ + 0 0 0 0 ssbo 1:0 subdata float 0 0.1 0.2 0.3 0.4 \ 0.5 0.6 0.7 0.8 \ diff --git a/tests/cases/multiple_ssbo_with_sparse_descriptor_set_in_compute_pipeline.vkscript b/tests/cases/multiple_ssbo_with_sparse_descriptor_set_in_compute_pipeline.vkscript index d5f15cf05..47b26421c 100644 --- a/tests/cases/multiple_ssbo_with_sparse_descriptor_set_in_compute_pipeline.vkscript +++ b/tests/cases/multiple_ssbo_with_sparse_descriptor_set_in_compute_pipeline.vkscript @@ -45,10 +45,10 @@ void main() { } [test] -ssbo 1:0 subdata vec4 0 0.1 0.2 0.3 0.4 -ssbo 1:2 subdata vec4 0 0.1 0.2 0.3 0.4 -ssbo 3:1 subdata vec4 0 0.1 0.2 0.3 0.4 -ssbo 5:3 subdata vec4 0 0.1 0.2 0.3 0.4 +ssbo 1:0 subdata float 0 0.1 0.2 0.3 0.4 +ssbo 1:2 subdata float 0 0.1 0.2 0.3 0.4 +ssbo 3:1 subdata float 0 0.1 0.2 0.3 0.4 +ssbo 5:3 subdata float 0 0.1 0.2 0.3 0.4 compute 4 1 1 diff --git a/tests/cases/multiple_ubo_update_with_graphics_pipeline.vkscript b/tests/cases/multiple_ubo_update_with_graphics_pipeline.vkscript index 6afa5715b..e8aaaf29d 100644 --- a/tests/cases/multiple_ubo_update_with_graphics_pipeline.vkscript +++ b/tests/cases/multiple_ubo_update_with_graphics_pipeline.vkscript @@ -79,8 +79,8 @@ void main() { [test] clear -uniform ubo 0 vec4 0 0.1 0.2 0.3 0.4 -uniform ubo 0 vec4 16 0.9 0.8 0.7 0.6 +uniform ubo 0:0 vec4 0 0.1 0.2 0.3 0.4 +uniform ubo 0:0 vec4 16 0.9 0.8 0.7 0.6 uniform ubo 1:0 float 0 0.1 0 0 0 \ 0.2 0 0 0 \ @@ -114,11 +114,9 @@ ssbo 2:3 subdata float 0 0.1 0.2 0.3 0.4 \ draw arrays TRIANGLE_LIST 0 6 relative probe rect rgba (0.0, 0.0, 1.0, 1.0) (1.0, 0.75, 0.625, 0.5) - - -uniform ubo 0 vec4 0 0.5 0.5 0.25 1.0 \ - 0.3 0.2 0.1 0.4 \ - 0 0 0 0 +uniform ubo 0:0 vec4 0 0.5 0.5 0.25 1.0 \ + 0.3 0.2 0.1 0.4 \ + 0 0 0 0 # SPIRV generated by glslang uses std140 layout as a default for UBO uniform ubo 1:0 float 0 0.1 0 0 0 \ @@ -166,6 +164,6 @@ probe ssbo float 2:3 0 ~= 0.1 0.2 0.3 0.4 \ -uniform ubo 0 float 8 0.35 0.6 0.1 0.4 +uniform ubo 0:0 vec4 8 0.35 0.6 0.1 0.4 draw arrays TRIANGLE_LIST 0 6 relative probe rect rgba (0.0, 0.0, 1.0, 1.0) (0.8, 0.7, 0.35, 0.5) diff --git a/tests/cases/probe_no_compute_with_multiple_ssbo_commands.vkscript b/tests/cases/probe_no_compute_with_multiple_ssbo_commands.vkscript index c96a72746..934bbf6ff 100644 --- a/tests/cases/probe_no_compute_with_multiple_ssbo_commands.vkscript +++ b/tests/cases/probe_no_compute_with_multiple_ssbo_commands.vkscript @@ -23,8 +23,8 @@ void main() { } [test] -ssbo 1:2 subdata vec4 0 0.1 0.2 0.3 0.4 -ssbo 1:2 subdata vec4 16 0.5 0.6 0.7 0.8 +ssbo 1:2 subdata float 0 0.1 0.2 0.3 0.4 +ssbo 1:2 subdata float 16 0.5 0.6 0.7 0.8 probe ssbo float 1:2 0 ~= 0.1 0.2 0.3 0.4 probe ssbo float 1:2 16 ~= 0.5 0.6 0.7 0.8 diff --git a/tests/cases/probe_no_compute_with_ssbo.vkscript b/tests/cases/probe_no_compute_with_ssbo.vkscript index a4a94a6bb..d51a0acda 100644 --- a/tests/cases/probe_no_compute_with_ssbo.vkscript +++ b/tests/cases/probe_no_compute_with_ssbo.vkscript @@ -23,7 +23,7 @@ void main() { } [test] -ssbo 1:2 subdata vec4 0 0.1 0.2 0.3 0.4 +ssbo 1:2 subdata float 0 0.1 0.2 0.3 0.4 probe ssbo float 1:2 0 ~= 0.1 0.2 0.3 0.4