Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/amber_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ The following commands are all specified within the `PIPELINE` command.
#### Buffer Types
* `uniform`
* `storage`
* `uniform_texel_buffer`
* `storage_texel_buffer`

TODO(dsinclair): Sync the BufferTypes with the list of Vulkan Descriptor types.

Expand Down Expand Up @@ -492,17 +494,17 @@ contain image attachment content, depth/stencil content, uniform buffers, etc.
# Attach |buffer_name| as a storage image. The MIP level will have a base
# value of |level|.
BIND BUFFER {buffer_name} AS storage_image \
[ BASE_MIP_LEVEL _level_ (default 0) ]
DESCRIPTOR_SET _id_ BINDING _id_ [ BASE_MIP_LEVEL _level_ (default 0) ]

# Attach |buffer_name| as a sampled image. The MIP level will have a base
# value of |level|.
BIND BUFFER {buffer_name} AS sampled_image \
[ BASE_MIP_LEVEL _level_ (default 0) ]
DESCRIPTOR_SET _id_ BINDING _id_ [ BASE_MIP_LEVEL _level_ (default 0) ]

# Attach |buffer_name| as a combined image sampler. A sampler |sampler_name|
# must also be specified. The MIP level will have a base value of 0.
BIND BUFFER {buffer_name} AS combined_image_sampler SAMPLER {sampler_name} \
[ BASE_MIP_LEVEL _level_ (default) 0) ]
DESCRIPTOR_SET _id_ BINDING _id_ [ BASE_MIP_LEVEL _level_ (default) 0) ]

# Bind the sampler at the given descriptor set and binding.
BIND SAMPLER {sampler_name} DESCRIPTOR_SET _id_ BINDING _id_
Expand Down
8 changes: 7 additions & 1 deletion src/amberscript/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,10 @@ Result Parser::ToBufferType(const std::string& name, BufferType* type) {
*type = BufferType::kSampledImage;
else if (name == "combined_image_sampler")
*type = BufferType::kCombinedImageSampler;
else if (name == "uniform_texel_buffer")
*type = BufferType::kUniformTexelBuffer;
else if (name == "storage_texel_buffer")
*type = BufferType::kStorageTexelBuffer;
else
return Result("unknown buffer_type: " + name);

Expand Down Expand Up @@ -1045,7 +1049,9 @@ Result Parser::ParsePipelineBind(Pipeline* pipeline) {
buffer_type == BufferType::kUniform ||
buffer_type == BufferType::kStorageImage ||
buffer_type == BufferType::kSampledImage ||
buffer_type == BufferType::kCombinedImageSampler) {
buffer_type == BufferType::kCombinedImageSampler ||
buffer_type == BufferType::kUniformTexelBuffer ||
buffer_type == BufferType::kStorageTexelBuffer) {
// If the buffer type is known, then we proccessed the AS block above
// and have to advance to the next token. Otherwise, we're already on
// the next token and don't want to advance.
Expand Down
272 changes: 272 additions & 0 deletions src/amberscript/parser_bind_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2064,6 +2064,278 @@ END)";
r.Error());
}

TEST_F(AmberScriptParserTest, BindBufferUniformTexelBufferCompute) {
std::string in = R"(
SHADER compute compute_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM

PIPELINE compute pipeline
ATTACH compute_shader
BIND BUFFER texture AS uniform_texel_buffer DESCRIPTOR_SET 0 BINDING 0
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();

auto script = parser.GetScript();
const auto& pipelines = script->GetPipelines();
ASSERT_EQ(1U, pipelines.size());

const auto* pipeline = pipelines[0].get();
const auto& bufs = pipeline->GetBuffers();
ASSERT_EQ(1U, bufs.size());
EXPECT_EQ(BufferType::kUniformTexelBuffer, bufs[0].type);
}

TEST_F(AmberScriptParserTest, BindBufferUniformTexelBufferGraphics) {
std::string in = R"(
SHADER vertex vert_shader PASSTHROUGH
SHADER fragment frag_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM
BUFFER framebuffer FORMAT R8G8B8A8_UNORM

PIPELINE graphics pipeline
ATTACH vert_shader
ATTACH frag_shader
BIND BUFFER texture AS uniform_texel_buffer DESCRIPTOR_SET 0 BINDING 0
BIND BUFFER framebuffer AS color LOCATION 0
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();

auto script = parser.GetScript();
const auto& pipelines = script->GetPipelines();
ASSERT_EQ(1U, pipelines.size());

const auto* pipeline = pipelines[0].get();
const auto& bufs = pipeline->GetBuffers();
ASSERT_EQ(1U, bufs.size());
EXPECT_EQ(BufferType::kUniformTexelBuffer, bufs[0].type);
}

TEST_F(AmberScriptParserTest,
BindBufferUniformTexelBufferMissingDescriptorSetValue) {
std::string in = R"(
SHADER compute compute_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM

PIPELINE compute pipeline
ATTACH compute_shader
BIND BUFFER texture AS uniform_texel_buffer DESCRIPTOR_SET BINDING 0
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_FALSE(r.IsSuccess());
EXPECT_EQ("10: invalid value for DESCRIPTOR_SET in BIND command", r.Error());
}

TEST_F(AmberScriptParserTest,
BindBufferUniformTexelBufferMissingDescriptorSet) {
std::string in = R"(
SHADER compute compute_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM

PIPELINE compute pipeline
ATTACH compute_shader
BIND BUFFER texture AS uniform_texel_buffer BINDING 0
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_FALSE(r.IsSuccess());
EXPECT_EQ("10: missing DESCRIPTOR_SET or KERNEL for BIND command", r.Error());
}

TEST_F(AmberScriptParserTest, BindBufferUniformTexelBufferMissingBindingValue) {
std::string in = R"(
SHADER compute compute_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM

PIPELINE compute pipeline
ATTACH compute_shader
BIND BUFFER texture AS uniform_texel_buffer DESCRIPTOR_SET 0 BINDING
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_FALSE(r.IsSuccess());
EXPECT_EQ("11: invalid value for BINDING in BIND command", r.Error());
}

TEST_F(AmberScriptParserTest, BindBufferUniformTexelBufferMissingBinding) {
std::string in = R"(
SHADER compute compute_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM

PIPELINE compute pipeline
ATTACH compute_shader
BIND BUFFER texture AS uniform_texel_buffer DESCRIPTOR_SET 0
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_FALSE(r.IsSuccess());
EXPECT_EQ("11: missing BINDING for BIND command", r.Error());
}

TEST_F(AmberScriptParserTest, BindBufferStorageTexelBufferCompute) {
std::string in = R"(
SHADER compute compute_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM

PIPELINE compute pipeline
ATTACH compute_shader
BIND BUFFER texture AS storage_texel_buffer DESCRIPTOR_SET 0 BINDING 0
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();

auto script = parser.GetScript();
const auto& pipelines = script->GetPipelines();
ASSERT_EQ(1U, pipelines.size());

const auto* pipeline = pipelines[0].get();
const auto& bufs = pipeline->GetBuffers();
ASSERT_EQ(1U, bufs.size());
EXPECT_EQ(BufferType::kStorageTexelBuffer, bufs[0].type);
}

TEST_F(AmberScriptParserTest, BindBufferStorageTexelBufferGraphics) {
std::string in = R"(
SHADER vertex vert_shader PASSTHROUGH
SHADER fragment frag_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM
BUFFER framebuffer FORMAT R8G8B8A8_UNORM

PIPELINE graphics pipeline
ATTACH vert_shader
ATTACH frag_shader
BIND BUFFER texture AS storage_texel_buffer DESCRIPTOR_SET 0 BINDING 0
BIND BUFFER framebuffer AS color LOCATION 0
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_TRUE(r.IsSuccess()) << r.Error();

auto script = parser.GetScript();
const auto& pipelines = script->GetPipelines();
ASSERT_EQ(1U, pipelines.size());

const auto* pipeline = pipelines[0].get();
const auto& bufs = pipeline->GetBuffers();
ASSERT_EQ(1U, bufs.size());
EXPECT_EQ(BufferType::kStorageTexelBuffer, bufs[0].type);
}

TEST_F(AmberScriptParserTest,
BindBufferStorageTexelBufferMissingDescriptorSetValue) {
std::string in = R"(
SHADER compute compute_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM

PIPELINE compute pipeline
ATTACH compute_shader
BIND BUFFER texture AS storage_texel_buffer DESCRIPTOR_SET BINDING 0
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_FALSE(r.IsSuccess());
EXPECT_EQ("10: invalid value for DESCRIPTOR_SET in BIND command", r.Error());
}

TEST_F(AmberScriptParserTest,
BindBufferStorageTexelBufferMissingDescriptorSet) {
std::string in = R"(
SHADER compute compute_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM

PIPELINE compute pipeline
ATTACH compute_shader
BIND BUFFER texture AS storage_texel_buffer BINDING 0
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_FALSE(r.IsSuccess());
EXPECT_EQ("10: missing DESCRIPTOR_SET or KERNEL for BIND command", r.Error());
}

TEST_F(AmberScriptParserTest, BindBufferStorageTexelBufferMissingBindingValue) {
std::string in = R"(
SHADER compute compute_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM

PIPELINE compute pipeline
ATTACH compute_shader
BIND BUFFER texture AS storage_texel_buffer DESCRIPTOR_SET 0 BINDING
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_FALSE(r.IsSuccess());
EXPECT_EQ("11: invalid value for BINDING in BIND command", r.Error());
}

TEST_F(AmberScriptParserTest, BindBufferStorageTexelBufferMissingBinding) {
std::string in = R"(
SHADER compute compute_shader GLSL
# GLSL Shader
END

BUFFER texture FORMAT R8G8B8A8_UNORM

PIPELINE compute pipeline
ATTACH compute_shader
BIND BUFFER texture AS storage_texel_buffer DESCRIPTOR_SET 0
END)";

Parser parser;
Result r = parser.Parse(in);
ASSERT_FALSE(r.IsSuccess());
EXPECT_EQ("11: missing BINDING for BIND command", r.Error());
}

TEST_F(AmberScriptParserTest, BindSampler) {
std::string in = R"(
SHADER vertex vert_shader PASSTHROUGH
Expand Down
8 changes: 6 additions & 2 deletions src/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ enum class BufferType : int8_t {
kPushConstant,
/// A vertex buffer.
kVertex,
/// A storage image
kStorageImage
/// A storage image.
kStorageImage,
/// A uniform texel buffer.
kUniformTexelBuffer,
/// A storage texel buffer.
kStorageTexelBuffer
};

/// A buffer stores data. The buffer maybe provided from the input script, or
Expand Down
10 changes: 9 additions & 1 deletion src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ class BufferCommand : public BindableResourceCommand {
kPushConstant,
kStorageImage,
kSampledImage,
kCombinedImageSampler
kCombinedImageSampler,
kUniformTexelBuffer,
kStorageTexelBuffer
};

BufferCommand(BufferType type, Pipeline* pipeline);
Expand All @@ -510,6 +512,12 @@ class BufferCommand : public BindableResourceCommand {
bool IsCombinedImageSampler() const {
return buffer_type_ == BufferType::kCombinedImageSampler;
}
bool IsUniformTexelBuffer() const {
return buffer_type_ == BufferType::kUniformTexelBuffer;
}
bool IsStorageTexelBuffer() const {
return buffer_type_ == BufferType::kStorageTexelBuffer;
}
bool IsPushConstant() const {
return buffer_type_ == BufferType::kPushConstant;
}
Expand Down
Loading