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
24 changes: 12 additions & 12 deletions src/amberscript/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ Result Parser::ToBufferType(const std::string& name, BufferType* type) {
if (name == "color")
*type = BufferType::kColor;
else if (name == "depth_stencil")
*type = BufferType::kDepth;
*type = BufferType::kDepthStencil;
else if (name == "push_constant")
*type = BufferType::kPushConstant;
else if (name == "combined_image_sampler")
Expand Down Expand Up @@ -801,8 +801,8 @@ Result Parser::ParsePipelineBind(Pipeline* pipeline) {
if (!r.IsSuccess())
return r;

} else if (buffer_type == BufferType::kDepth) {
r = pipeline->SetDepthBuffer(buffer);
} else if (buffer_type == BufferType::kDepthStencil) {
r = pipeline->SetDepthStencilBuffer(buffer);
if (!r.IsSuccess())
return r;

Expand Down Expand Up @@ -1083,11 +1083,11 @@ Result Parser::ParsePipelinePolygonMode(Pipeline* pipeline) {
auto mode = token->AsString();

if (mode == "fill")
pipeline->SetPolygonMode(PolygonMode::kFill);
pipeline->GetPipelineData()->SetPolygonMode(PolygonMode::kFill);
else if (mode == "line")
pipeline->SetPolygonMode(PolygonMode::kLine);
pipeline->GetPipelineData()->SetPolygonMode(PolygonMode::kLine);
else if (mode == "point")
pipeline->SetPolygonMode(PolygonMode::kPoint);
pipeline->GetPipelineData()->SetPolygonMode(PolygonMode::kPoint);
else
return Result("invalid polygon mode: " + mode);

Expand Down Expand Up @@ -1775,10 +1775,10 @@ Result Parser::ParseRun() {
if (!token->IsInteger())
return Result("missing X position for RUN command");

auto cmd = MakeUnique<DrawRectCommand>(pipeline, PipelineData{});
auto cmd =
MakeUnique<DrawRectCommand>(pipeline, *pipeline->GetPipelineData());
cmd->SetLine(line);
cmd->EnableOrtho();
cmd->SetPolygonMode(pipeline->GetPolygonMode());

Result r = token->ConvertToDouble();
if (!r.IsSuccess())
Expand Down Expand Up @@ -1845,9 +1845,9 @@ Result Parser::ParseRun() {
if (!token->IsInteger())
return Result("missing X position for RUN command");

auto cmd = MakeUnique<DrawGridCommand>(pipeline);
auto cmd =
MakeUnique<DrawGridCommand>(pipeline, *pipeline->GetPipelineData());
cmd->SetLine(line);
cmd->SetPolygonMode(pipeline->GetPolygonMode());

Result r = token->ConvertToDouble();
if (!r.IsSuccess())
Expand Down Expand Up @@ -1989,12 +1989,12 @@ Result Parser::ParseRun() {
return Result("START_IDX plus COUNT exceeds vertex buffer data size");
}

auto cmd = MakeUnique<DrawArraysCommand>(pipeline, PipelineData{});
auto cmd =
MakeUnique<DrawArraysCommand>(pipeline, *pipeline->GetPipelineData());
cmd->SetLine(line);
cmd->SetTopology(topo);
cmd->SetFirstVertexIndex(start_idx);
cmd->SetVertexCount(count);
cmd->SetPolygonMode(pipeline->GetPolygonMode());

if (indexed)
cmd->EnableIndexed();
Expand Down
5 changes: 3 additions & 2 deletions src/amberscript/parser_bind_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ END)";
ASSERT_EQ(1U, pipelines.size());

const auto* pipeline = pipelines[0].get();
const auto& buf = pipeline->GetDepthBuffer();
const auto& buf = pipeline->GetDepthStencilBuffer();
ASSERT_TRUE(buf.buffer != nullptr);
EXPECT_EQ(90 * 180, buf.buffer->ElementCount());
EXPECT_EQ(90 * 180 * 4, buf.buffer->ValueCount());
Expand Down Expand Up @@ -649,7 +649,8 @@ END)";
Parser parser;
Result r = parser.Parse(in);
ASSERT_FALSE(r.IsSuccess());
EXPECT_EQ("14: can only bind one depth buffer in a PIPELINE", r.Error());
EXPECT_EQ("14: can only bind one depth/stencil buffer in a PIPELINE",
r.Error());
}

TEST_F(AmberScriptParserTest, BindVertexData) {
Expand Down
8 changes: 4 additions & 4 deletions src/amberscript/parser_pipeline_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,13 @@ END)";
const auto& pipelines = script->GetPipelines();
ASSERT_EQ(4U, pipelines.size());

auto mode0 = pipelines[0]->GetPolygonMode();
auto mode0 = pipelines[0]->GetPipelineData()->GetPolygonMode();
ASSERT_EQ(mode0, PolygonMode::kFill);
auto mode1 = pipelines[1]->GetPolygonMode();
auto mode1 = pipelines[1]->GetPipelineData()->GetPolygonMode();
ASSERT_EQ(mode1, PolygonMode::kFill);
auto mode2 = pipelines[2]->GetPolygonMode();
auto mode2 = pipelines[2]->GetPipelineData()->GetPolygonMode();
ASSERT_EQ(mode2, PolygonMode::kLine);
auto mode3 = pipelines[3]->GetPolygonMode();
auto mode3 = pipelines[3]->GetPipelineData()->GetPolygonMode();
ASSERT_EQ(mode3, PolygonMode::kPoint);
}

Expand Down
2 changes: 1 addition & 1 deletion src/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum class BufferType : int8_t {
/// A color buffer.
kColor = 0,
/// A depth/stencil buffer.
kDepth,
kDepthStencil,
/// An index buffer.
kIndex,
/// A sampled image.
Expand Down
4 changes: 2 additions & 2 deletions src/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ DrawRectCommand::DrawRectCommand(Pipeline* pipeline, PipelineData data)

DrawRectCommand::~DrawRectCommand() = default;

DrawGridCommand::DrawGridCommand(Pipeline* pipeline)
: PipelineCommand(Type::kDrawGrid, pipeline) {}
DrawGridCommand::DrawGridCommand(Pipeline* pipeline, PipelineData data)
: PipelineCommand(Type::kDrawGrid, pipeline), data_(data) {}

DrawGridCommand::~DrawGridCommand() = default;

Expand Down
13 changes: 4 additions & 9 deletions src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ class DrawRectCommand : public PipelineCommand {
void SetHeight(float h) { height_ = h; }
float GetHeight() const { return height_; }

void SetPolygonMode(PolygonMode mode) { data_.SetPolygonMode(mode); }

std::string ToString() const override { return "DrawRectCommand"; }

private:
Expand All @@ -192,9 +190,11 @@ class DrawRectCommand : public PipelineCommand {
/// Command to draw a grid of recrangles on screen.
class DrawGridCommand : public PipelineCommand {
public:
explicit DrawGridCommand(Pipeline* pipeline);
DrawGridCommand(Pipeline* pipeline, PipelineData data);
~DrawGridCommand() override;

const PipelineData* GetPipelineData() const { return &data_; }

void SetX(float x) { x_ = x; }
float GetX() const { return x_; }

Expand All @@ -213,19 +213,16 @@ class DrawGridCommand : public PipelineCommand {
void SetRows(uint32_t r) { rows_ = r; }
uint32_t GetRows() const { return rows_; }

void SetPolygonMode(PolygonMode mode) { polygon_mode_ = mode; }
PolygonMode GetPolygonMode() const { return polygon_mode_; }

std::string ToString() const override { return "DrawGridCommand"; }

private:
PipelineData data_;
float x_ = 0.0;
float y_ = 0.0;
float width_ = 0.0;
float height_ = 0.0;
uint32_t columns_ = 0;
uint32_t rows_ = 0;
PolygonMode polygon_mode_ = PolygonMode::kFill;
};

/// Command to draw from a vertex and index buffer.
Expand All @@ -245,8 +242,6 @@ class DrawArraysCommand : public PipelineCommand {
void SetTopology(Topology topo) { topology_ = topo; }
Topology GetTopology() const { return topology_; }

void SetPolygonMode(PolygonMode mode) { data_.SetPolygonMode(mode); }

void SetFirstVertexIndex(uint32_t idx) { first_vertex_index_ = idx; }
uint32_t GetFirstVertexIndex() const { return first_vertex_index_; }

Expand Down
8 changes: 8 additions & 0 deletions src/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ class Format {
uint32_t SizeInBytes() const;

bool IsFormatKnown() const { return format_type_ != FormatType::kUnknown; }
bool HasDepthComponent() const {
return format_type_ == FormatType::kD16_UNORM ||
format_type_ == FormatType::kD16_UNORM_S8_UINT ||
format_type_ == FormatType::kD24_UNORM_S8_UINT ||
format_type_ == FormatType::kD32_SFLOAT ||
format_type_ == FormatType::kD32_SFLOAT_S8_UINT ||
format_type_ == FormatType::kX8_D24_UNORM_PACK32;
}
bool HasStencilComponent() const {
return format_type_ == FormatType::kD24_UNORM_S8_UINT ||
format_type_ == FormatType::kD16_UNORM_S8_UINT ||
Expand Down
38 changes: 15 additions & 23 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ std::unique_ptr<Pipeline> Pipeline::Clone() const {
clone->color_attachments_ = color_attachments_;
clone->vertex_buffers_ = vertex_buffers_;
clone->buffers_ = buffers_;
clone->depth_buffer_ = depth_buffer_;
clone->depth_stencil_buffer_ = depth_stencil_buffer_;
clone->index_buffer_ = index_buffer_;
clone->fb_width_ = fb_width_;
clone->fb_height_ = fb_height_;
clone->set_arg_values_ = set_arg_values_;
clone->pipeline_data_ = pipeline_data_;

if (!opencl_pod_buffers_.empty()) {
// Generate specific buffers for the clone.
Expand Down Expand Up @@ -184,16 +185,6 @@ Result Pipeline::SetShaderType(const Shader* shader, ShaderType type) {
shader->GetName());
}

Result Pipeline::SetPolygonMode(PolygonMode mode) {
if (mode != PolygonMode::kFill && mode != PolygonMode::kLine &&
mode != PolygonMode::kPoint)
return Result("invalid polygon mode specified for pipeline");

polygon_mode_ = mode;

return {};
}

Result Pipeline::Validate() const {
for (const auto& attachment : color_attachments_) {
if (attachment.buffer->ElementCount() !=
Expand All @@ -204,8 +195,8 @@ Result Pipeline::Validate() const {
}
}

if (depth_buffer_.buffer &&
depth_buffer_.buffer->ElementCount() != fb_width_ * fb_height_) {
if (depth_stencil_buffer_.buffer &&
depth_stencil_buffer_.buffer->ElementCount() != fb_width_ * fb_height_) {
return Result("shared depth buffer must have same size over all PIPELINES");
}

Expand Down Expand Up @@ -280,10 +271,10 @@ void Pipeline::UpdateFramebufferSizes() {
attachment.buffer->SetElementCount(mip0_width * mip0_height);
}

if (depth_buffer_.buffer) {
depth_buffer_.buffer->SetWidth(fb_width_);
depth_buffer_.buffer->SetHeight(fb_height_);
depth_buffer_.buffer->SetElementCount(size);
if (depth_stencil_buffer_.buffer) {
depth_stencil_buffer_.buffer->SetWidth(fb_width_);
depth_stencil_buffer_.buffer->SetHeight(fb_height_);
depth_stencil_buffer_.buffer->SetElementCount(size);
}
}

Expand Down Expand Up @@ -323,12 +314,12 @@ Result Pipeline::GetLocationForColorAttachment(Buffer* buf,
return Result("Unable to find requested buffer");
}

Result Pipeline::SetDepthBuffer(Buffer* buf) {
if (depth_buffer_.buffer != nullptr)
return Result("can only bind one depth buffer in a PIPELINE");
Result Pipeline::SetDepthStencilBuffer(Buffer* buf) {
if (depth_stencil_buffer_.buffer != nullptr)
return Result("can only bind one depth/stencil buffer in a PIPELINE");

depth_buffer_.buffer = buf;
depth_buffer_.type = BufferType::kDepth;
depth_stencil_buffer_.buffer = buf;
depth_stencil_buffer_.type = BufferType::kDepthStencil;

buf->SetWidth(fb_width_);
buf->SetHeight(fb_height_);
Expand Down Expand Up @@ -403,7 +394,8 @@ std::unique_ptr<Buffer> Pipeline::GenerateDefaultColorAttachmentBuffer() {
return buf;
}

std::unique_ptr<Buffer> Pipeline::GenerateDefaultDepthAttachmentBuffer() {
std::unique_ptr<Buffer>
Pipeline::GenerateDefaultDepthStencilAttachmentBuffer() {
TypeParser parser;
auto type = parser.Parse(kDefaultDepthBufferFormat);
auto fmt = MakeUnique<Format>(type.get());
Expand Down
29 changes: 16 additions & 13 deletions src/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "amber/result.h"
#include "src/buffer.h"
#include "src/command_data.h"
#include "src/pipeline_data.h"
#include "src/sampler.h"
#include "src/shader.h"

Expand Down Expand Up @@ -245,11 +246,17 @@ class Pipeline {
/// something goes wrong.
Result GetLocationForColorAttachment(Buffer* buf, uint32_t* loc) const;

/// Sets |buf| as the depth buffer for this pipeline.
Result SetDepthBuffer(Buffer* buf);
/// Returns information on the depth buffer bound to the pipeline. If no
/// depth buffer is bound the |BufferInfo::buffer| parameter will be nullptr.
const BufferInfo& GetDepthBuffer() const { return depth_buffer_; }
/// Sets |buf| as the depth/stencil buffer for this pipeline.
Result SetDepthStencilBuffer(Buffer* buf);
/// Returns information on the depth/stencil buffer bound to the pipeline. If
/// no depth buffer is bound the |BufferInfo::buffer| parameter will be
/// nullptr.
const BufferInfo& GetDepthStencilBuffer() const {
return depth_stencil_buffer_;
}

/// Returns pipeline data.
PipelineData* GetPipelineData() { return &pipeline_data_; }

/// Returns information on all vertex buffers bound to the pipeline.
const std::vector<BufferInfo>& GetVertexBuffers() const {
Expand Down Expand Up @@ -306,16 +313,13 @@ class Pipeline {
return push_constant_buffer_;
}

Result SetPolygonMode(PolygonMode mode);
PolygonMode GetPolygonMode() const { return polygon_mode_; }

/// Validates that the pipeline has been created correctly.
Result Validate() const;

/// Generates a default color attachment in B8G8R8A8_UNORM.
std::unique_ptr<Buffer> GenerateDefaultColorAttachmentBuffer();
/// Generates a default depth attachment in D32_SFLOAT_S8_UINT format.
std::unique_ptr<Buffer> GenerateDefaultDepthAttachmentBuffer();
/// Generates a default depth/stencil attachment in D32_SFLOAT_S8_UINT format.
std::unique_ptr<Buffer> GenerateDefaultDepthStencilAttachmentBuffer();

/// Information on values set for OpenCL-C plain-old-data args.
struct ArgSetInfo {
Expand Down Expand Up @@ -359,11 +363,10 @@ class Pipeline {
std::vector<std::unique_ptr<type::Type>> types_;
std::vector<SamplerInfo> samplers_;
std::vector<std::unique_ptr<Format>> formats_;
BufferInfo depth_buffer_;
BufferInfo depth_stencil_buffer_;
BufferInfo push_constant_buffer_;
Buffer* index_buffer_ = nullptr;
PolygonMode polygon_mode_ = PolygonMode::kFill;

PipelineData pipeline_data_;
uint32_t fb_width_ = 250;
uint32_t fb_height_ = 250;

Expand Down
2 changes: 2 additions & 0 deletions src/pipeline_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class PipelineData {
~PipelineData();
PipelineData(const PipelineData&);

PipelineData& operator=(const PipelineData&) = default;

void SetTopology(Topology topo) { topology_ = topo; }
Topology GetTopology() const { return topology_; }

Expand Down
Loading