From 4bbce8528cc2a4258302e4df710a344f405a0fa4 Mon Sep 17 00:00:00 2001 From: David Neto Date: Mon, 31 Jan 2022 16:27:45 -0500 Subject: Show clspv error output when compilation fails (#979) Fixes: #978 --- src/clspv_helper.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/clspv_helper.cc b/src/clspv_helper.cc index 59b8737..4be5bfa 100644 --- a/src/clspv_helper.cc +++ b/src/clspv_helper.cc @@ -258,9 +258,10 @@ Result Compile(Pipeline::ShaderInfo* shader_info, for (const auto& option : shader_info->GetCompileOptions()) { options += option + " "; } + std::string error_log; if (clspv::CompileFromSourceString(src_str, /* sampler map */ "", options, - generated_binary)) { - return Result("Clspv compile failed"); + generated_binary, &error_log)) { + return Result("Clspv compile error: " + error_log); } // Parse the reflection instructions. -- cgit v1.2.3 From 4b1c3c1a41c2a26f2a6882cb2b5f3484a6713443 Mon Sep 17 00:00:00 2001 From: asuonpaa <34128694+asuonpaa@users.noreply.github.com> Date: Thu, 17 Mar 2022 13:20:25 +0200 Subject: Use proper index type based on index buffer format (#981) * Use proper index type based on index buffer format Amber was assuming the index buffer to always be uint32. Now the buffer format is used to determine the index type when binding the index buffer in Vulkan. * Exclude 8 bit indices test from SwiftShader runs --- src/vulkan/index_buffer.cc | 11 +++++++- src/vulkan/index_buffer.h | 1 + tests/cases/draw_indexed_uint16.amber | 48 +++++++++++++++++++++++++++++++++ tests/cases/draw_indexed_uint32.amber | 48 +++++++++++++++++++++++++++++++++ tests/cases/draw_indexed_uint8.amber | 50 +++++++++++++++++++++++++++++++++++ tests/run_tests.py | 2 ++ 6 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 tests/cases/draw_indexed_uint16.amber create mode 100644 tests/cases/draw_indexed_uint32.amber create mode 100644 tests/cases/draw_indexed_uint8.amber diff --git a/src/vulkan/index_buffer.cc b/src/vulkan/index_buffer.cc index b651427..30b223d 100644 --- a/src/vulkan/index_buffer.cc +++ b/src/vulkan/index_buffer.cc @@ -36,6 +36,15 @@ Result IndexBuffer::SendIndexData(CommandBuffer* command, Buffer* buffer) { if (buffer->ElementCount() == 0) return Result("IndexBuffer::SendIndexData |buffer| is empty"); + if (buffer->GetFormat()->IsUint32()) + index_type_ = VK_INDEX_TYPE_UINT32; + else if (buffer->GetFormat()->IsUint16()) + index_type_ = VK_INDEX_TYPE_UINT16; + else if (buffer->GetFormat()->IsUint8()) + index_type_ = VK_INDEX_TYPE_UINT8_EXT; + else + return Result("IndexBuffer::SendIndexData unexpected index buffer format"); + transfer_buffer_ = MakeUnique(device_, buffer->GetSizeInBytes(), nullptr); Result r = transfer_buffer_->AddUsageFlags(VK_BUFFER_USAGE_INDEX_BUFFER_BIT | @@ -62,7 +71,7 @@ Result IndexBuffer::BindToCommandBuffer(CommandBuffer* command) { device_->GetPtrs()->vkCmdBindIndexBuffer(command->GetVkCommandBuffer(), transfer_buffer_->GetVkBuffer(), 0, - VK_INDEX_TYPE_UINT32); + index_type_); return {}; } diff --git a/src/vulkan/index_buffer.h b/src/vulkan/index_buffer.h index 2d21330..4b22ebe 100644 --- a/src/vulkan/index_buffer.h +++ b/src/vulkan/index_buffer.h @@ -46,6 +46,7 @@ class IndexBuffer { private: Device* device_ = nullptr; std::unique_ptr transfer_buffer_; + VkIndexType index_type_; }; } // namespace vulkan diff --git a/tests/cases/draw_indexed_uint16.amber b/tests/cases/draw_indexed_uint16.amber new file mode 100644 index 0000000..f42e2b5 --- /dev/null +++ b/tests/cases/draw_indexed_uint16.amber @@ -0,0 +1,48 @@ +#!amber +# Copyright 2022 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. + +SHADER vertex vert_shader PASSTHROUGH +SHADER fragment frag_shader GLSL +#version 430 +layout(location = 0) out vec4 color_out; +void main() { + color_out = vec4(0.0, 1.0, 0.0, 1.0); +} +END + +BUFFER position DATA_TYPE vec4 DATA +-1.0 1.0 0.0 1.0 + 1.0 1.0 0.0 1.0 + 1.0 -1.0 0.0 1.0 +-1.0 -1.0 0.0 1.0 +END + +BUFFER indices DATA_TYPE uint16 DATA +3 2 1 0 +END + +IMAGE framebuffer FORMAT B8G8R8A8_UNORM DIM_2D WIDTH 64 HEIGHT 64 + +PIPELINE graphics pipeline + ATTACH vert_shader + ATTACH frag_shader + VERTEX_DATA position LOCATION 0 + INDEX_DATA indices + FRAMEBUFFER_SIZE 64 64 + BIND BUFFER framebuffer AS color LOCATION 0 +END + +RUN pipeline DRAW_ARRAY AS TRIANGLE_FAN INDEXED START_IDX 0 COUNT 4 +EXPECT framebuffer IDX 0 0 SIZE 64 64 EQ_RGBA 0 255 0 255 diff --git a/tests/cases/draw_indexed_uint32.amber b/tests/cases/draw_indexed_uint32.amber new file mode 100644 index 0000000..3a2eac2 --- /dev/null +++ b/tests/cases/draw_indexed_uint32.amber @@ -0,0 +1,48 @@ +#!amber +# Copyright 2022 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. + +SHADER vertex vert_shader PASSTHROUGH +SHADER fragment frag_shader GLSL +#version 430 +layout(location = 0) out vec4 color_out; +void main() { + color_out = vec4(0.0, 1.0, 0.0, 1.0); +} +END + +BUFFER position DATA_TYPE vec4 DATA +-1.0 1.0 0.0 1.0 + 1.0 1.0 0.0 1.0 + 1.0 -1.0 0.0 1.0 +-1.0 -1.0 0.0 1.0 +END + +BUFFER indices DATA_TYPE uint32 DATA +3 2 1 0 +END + +IMAGE framebuffer FORMAT B8G8R8A8_UNORM DIM_2D WIDTH 64 HEIGHT 64 + +PIPELINE graphics pipeline + ATTACH vert_shader + ATTACH frag_shader + VERTEX_DATA position LOCATION 0 + INDEX_DATA indices + FRAMEBUFFER_SIZE 64 64 + BIND BUFFER framebuffer AS color LOCATION 0 +END + +RUN pipeline DRAW_ARRAY AS TRIANGLE_FAN INDEXED START_IDX 0 COUNT 4 +EXPECT framebuffer IDX 0 0 SIZE 64 64 EQ_RGBA 0 255 0 255 diff --git a/tests/cases/draw_indexed_uint8.amber b/tests/cases/draw_indexed_uint8.amber new file mode 100644 index 0000000..a038233 --- /dev/null +++ b/tests/cases/draw_indexed_uint8.amber @@ -0,0 +1,50 @@ +#!amber +# Copyright 2022 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. + +DEVICE_EXTENSION VK_EXT_index_type_uint8 + +SHADER vertex vert_shader PASSTHROUGH +SHADER fragment frag_shader GLSL +#version 430 +layout(location = 0) out vec4 color_out; +void main() { + color_out = vec4(0.0, 1.0, 0.0, 1.0); +} +END + +BUFFER position DATA_TYPE vec4 DATA +-1.0 1.0 0.0 1.0 + 1.0 1.0 0.0 1.0 + 1.0 -1.0 0.0 1.0 +-1.0 -1.0 0.0 1.0 +END + +BUFFER indices DATA_TYPE uint8 DATA +3 2 1 0 +END + +IMAGE framebuffer FORMAT B8G8R8A8_UNORM DIM_2D WIDTH 64 HEIGHT 64 + +PIPELINE graphics pipeline + ATTACH vert_shader + ATTACH frag_shader + VERTEX_DATA position LOCATION 0 + INDEX_DATA indices + FRAMEBUFFER_SIZE 64 64 + BIND BUFFER framebuffer AS color LOCATION 0 +END + +RUN pipeline DRAW_ARRAY AS TRIANGLE_FAN INDEXED START_IDX 0 COUNT 4 +EXPECT framebuffer IDX 0 0 SIZE 64 64 EQ_RGBA 0 255 0 255 diff --git a/tests/run_tests.py b/tests/run_tests.py index 6cd8fc3..23789f6 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -98,6 +98,8 @@ SUPPRESSIONS_SWIFTSHADER = [ "draw_rectangles_depth_test_x8d24.amber", # Tessellation not supported "tessellation_isolines.amber", + # 8 bit indices not supported + "draw_indexed_uint8.amber", ] OPENCL_CASES = [ -- cgit v1.2.3 From e754c9081da75b6451e6022ecc13ce3ee5bf0f6e Mon Sep 17 00:00:00 2001 From: gnl21 Date: Mon, 21 Mar 2022 17:59:06 +0000 Subject: Check error return when pushing descriptors (#980) Pipeline::SendDescriptorDataToDeviceIfNeeded was not checking the error return when initializing transfer buffers, which can lead to later code attempting to use invalid buffers and crashing. --- src/vulkan/pipeline.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vulkan/pipeline.cc b/src/vulkan/pipeline.cc index df301e4..8cd4995 100644 --- a/src/vulkan/pipeline.cc +++ b/src/vulkan/pipeline.cc @@ -430,7 +430,9 @@ Result Pipeline::SendDescriptorDataToDeviceIfNeeded() { "Vulkan: Pipeline::SendDescriptorDataToDeviceIfNeeded() " "descriptor's transfer resource is not found"); } - descriptor_transfer_resources_[buffer]->Initialize(); + Result r = descriptor_transfer_resources_[buffer]->Initialize(); + if (!r.IsSuccess()) + return r; } // Note that if a buffer for a descriptor is host accessible and -- cgit v1.2.3 From 627ee453d6047ced0e2dd13cde983b341d0615e3 Mon Sep 17 00:00:00 2001 From: alan-baker Date: Wed, 30 Mar 2022 12:59:28 -0400 Subject: Remove dead variable (#984) --- src/vkscript/command_parser.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/vkscript/command_parser.cc b/src/vkscript/command_parser.cc index 610c7e6..3429d4d 100644 --- a/src/vkscript/command_parser.cc +++ b/src/vkscript/command_parser.cc @@ -486,7 +486,6 @@ Result CommandParser::ParseValues(const std::string& name, std::vector* values) { assert(values); - uint32_t row_index = 0; auto token = tokenizer_->NextToken(); size_t seen = 0; while (!token->IsEOL() && !token->IsEOS()) { @@ -515,7 +514,6 @@ Result CommandParser::ParseValues(const std::string& name, values->push_back(v); token = tokenizer_->NextToken(); - ++row_index; ++seen; } -- cgit v1.2.3 From 8b145a6c89dcdb4ec28173339dd176fb7b6f43ed Mon Sep 17 00:00:00 2001 From: asuonpaa <34128694+asuonpaa@users.noreply.github.com> Date: Thu, 21 Apr 2022 11:17:13 +0300 Subject: Add depth compare support for samplers (#987) --- docs/amber_script.md | 16 ++++++++++++++-- src/amberscript/parser.cc | 24 ++++++++++++++++++++++++ src/amberscript/parser_sampler_test.cc | 8 +++++++- src/sampler.h | 11 +++++++++++ src/vulkan/sampler.cc | 28 ++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 3 deletions(-) diff --git a/docs/amber_script.md b/docs/amber_script.md index 7c78d82..9bd58d7 100644 --- a/docs/amber_script.md +++ b/docs/amber_script.md @@ -350,9 +350,19 @@ sampled image or combined image sampler. * `float_opaque_white` * `int_opaque_white` +#### Compare operations +* `never` +* `less` +* `equal` +* `less_or_equal` +* `greater` +* `not_equal` +* `greater_or_equal` +* `always` + ```groovy -# Creates a sampler with |name|. +# Creates a sampler with |name|. |compare_enable| is either on or off. SAMPLER {name} \ [ MAG_FILTER {filter_type} (default nearest) ] \ [ MIN_FILTER {filter_type} (default nearest) ] \ @@ -362,7 +372,9 @@ SAMPLER {name} \ [ BORDER_COLOR {border_color} (default float_transparent_black) ] \ [ MIN_LOD _val_ (default 0.0) ] \ [ MAX_LOD _val_ (default 1.0) ] \ - [ NORMALIZED_COORDS | UNNORMALIZED_COORDS (default NORMALIZED_COORDS) ] + [ NORMALIZED_COORDS | UNNORMALIZED_COORDS (default NORMALIZED_COORDS) ] \ + [ COMPARE _compare_enable_ (default off) ] \ + [ COMPARE_OP _compare_op_ (default never) ] ``` Note: unnormalized coordinates will override MIN\_LOD and MAX\_LOD to 0.0. diff --git a/src/amberscript/parser.cc b/src/amberscript/parser.cc index d3e0eb6..8cd6e19 100644 --- a/src/amberscript/parser.cc +++ b/src/amberscript/parser.cc @@ -3893,6 +3893,30 @@ Result Parser::ParseSampler() { sampler->SetNormalizedCoords(false); sampler->SetMinLOD(0.0f); sampler->SetMaxLOD(0.0f); + } else if (param == "COMPARE") { + token = tokenizer_->NextToken(); + + if (!token->IsIdentifier()) + return Result("invalid value for COMPARE"); + + if (token->AsString() == "on") + sampler->SetCompareEnable(true); + else if (token->AsString() == "off") + sampler->SetCompareEnable(false); + else + return Result("invalid value for COMPARE: " + token->AsString()); + } else if (param == "COMPARE_OP") { + token = tokenizer_->NextToken(); + + if (!token->IsIdentifier()) + return Result("invalid value for COMPARE_OP"); + + CompareOp compare_op = StrToCompareOp(token->AsString()); + if (compare_op != CompareOp::kUnknown) { + sampler->SetCompareOp(compare_op); + } else { + return Result("invalid value for COMPARE_OP: " + token->AsString()); + } } else { return Result("unexpected sampler parameter " + param); } diff --git a/src/amberscript/parser_sampler_test.cc b/src/amberscript/parser_sampler_test.cc index 6cba69d..d4b0dd1 100644 --- a/src/amberscript/parser_sampler_test.cc +++ b/src/amberscript/parser_sampler_test.cc @@ -45,6 +45,8 @@ TEST_F(AmberScriptParserTest, SamplerDefaultValues) { EXPECT_EQ(0.0, sampler->GetMinLOD()); EXPECT_EQ(1.0, sampler->GetMaxLOD()); EXPECT_EQ(true, sampler->GetNormalizedCoords()); + EXPECT_EQ(false, sampler->GetCompareEnable()); + EXPECT_EQ(CompareOp::kNever, sampler->GetCompareOp()); } TEST_F(AmberScriptParserTest, SamplerCustomValues) { @@ -57,7 +59,9 @@ SAMPLER sampler MAG_FILTER linear \ BORDER_COLOR float_opaque_white \ MIN_LOD 2.5 \ MAX_LOD 5.0 \ - NORMALIZED_COORDS)"; + NORMALIZED_COORDS \ + COMPARE on \ + COMPARE_OP greater)"; Parser parser; Result r = parser.Parse(in); @@ -81,6 +85,8 @@ SAMPLER sampler MAG_FILTER linear \ EXPECT_EQ(2.5, sampler->GetMinLOD()); EXPECT_EQ(5.0, sampler->GetMaxLOD()); EXPECT_EQ(true, sampler->GetNormalizedCoords()); + EXPECT_EQ(true, sampler->GetCompareEnable()); + EXPECT_EQ(CompareOp::kGreater, sampler->GetCompareOp()); } TEST_F(AmberScriptParserTest, SamplerUnexpectedParameter) { diff --git a/src/sampler.h b/src/sampler.h index c44316a..f16e4cd 100644 --- a/src/sampler.h +++ b/src/sampler.h @@ -23,6 +23,7 @@ #include "amber/result.h" #include "amber/value.h" +#include "src/command_data.h" #include "src/format.h" namespace amber { @@ -86,6 +87,14 @@ class Sampler { void SetNormalizedCoords(bool norm) { normalized_coords_ = norm; } bool GetNormalizedCoords() const { return normalized_coords_; } + void SetCompareEnable(bool compare_enable) { + compare_enable_ = compare_enable; + } + bool GetCompareEnable() const { return compare_enable_; } + + void SetCompareOp(CompareOp compare_op) { compare_op_ = compare_op; } + CompareOp GetCompareOp() const { return compare_op_; } + private: std::string name_; FilterType min_filter_ = FilterType::kNearest; @@ -98,6 +107,8 @@ class Sampler { float min_lod_ = 0.0f; float max_lod_ = 1.0f; bool normalized_coords_ = true; + bool compare_enable_ = false; + CompareOp compare_op_ = CompareOp::kNever; }; } // namespace amber diff --git a/src/vulkan/sampler.cc b/src/vulkan/sampler.cc index 979c098..c8995e8 100644 --- a/src/vulkan/sampler.cc +++ b/src/vulkan/sampler.cc @@ -52,6 +52,31 @@ VkBorderColor GetVkBorderColor(BorderColor color) { } } +VkCompareOp ToVkCompareOp(CompareOp op) { + switch (op) { + case CompareOp::kNever: + return VK_COMPARE_OP_NEVER; + case CompareOp::kLess: + return VK_COMPARE_OP_LESS; + case CompareOp::kEqual: + return VK_COMPARE_OP_EQUAL; + case CompareOp::kLessOrEqual: + return VK_COMPARE_OP_LESS_OR_EQUAL; + case CompareOp::kGreater: + return VK_COMPARE_OP_GREATER; + case CompareOp::kNotEqual: + return VK_COMPARE_OP_NOT_EQUAL; + case CompareOp::kGreaterOrEqual: + return VK_COMPARE_OP_GREATER_OR_EQUAL; + case CompareOp::kAlways: + return VK_COMPARE_OP_ALWAYS; + case CompareOp::kUnknown: + break; + } + assert(false && "Vulkan::Unknown CompareOp"); + return VK_COMPARE_OP_NEVER; +} + } // namespace Sampler::Sampler(Device* device) : device_(device) {} @@ -76,6 +101,9 @@ Result Sampler::CreateSampler(amber::Sampler* sampler) { sampler_info.maxLod = sampler->GetMaxLOD(); sampler_info.unnormalizedCoordinates = (sampler->GetNormalizedCoords() ? VK_FALSE : VK_TRUE); + sampler_info.compareEnable = + (sampler->GetCompareEnable() ? VK_TRUE : VK_FALSE); + sampler_info.compareOp = ToVkCompareOp(sampler->GetCompareOp()); if (device_->GetPtrs()->vkCreateSampler(device_->GetVkDevice(), &sampler_info, nullptr, &sampler_) != VK_SUCCESS) { -- cgit v1.2.3