8 #include "fml/status.h"
16 : context_(
std::move(context)),
17 sample_count_(target.GetSampleCount()),
18 pixel_format_(target.GetRenderTargetPixelFormat()),
19 has_depth_attachment_(target.GetDepthAttachment().has_value()),
20 has_stencil_attachment_(target.GetStencilAttachment().has_value()),
21 render_target_size_(target.GetRenderTargetSize()),
22 render_target_(target),
23 orthographic_(
Matrix::MakeOrthographic(render_target_size_)) {}
63 if (!command.IsValid()) {
64 VALIDATION_LOG <<
"Attempted to add an invalid command to the render pass.";
68 if (command.element_count == 0u || command.instance_count == 0u) {
74 commands_.emplace_back(std::move(command));
89 pending_.
pipeline = std::move(pipeline);
99 pending_.label = std::string(label);
148 size_t vertex_buffer_count) {
153 if (!vertex_buffers_start_.has_value()) {
158 for (
size_t i = 0; i < vertex_buffer_count; i++) {
175 size_t vertex_buffer_count) {
178 <<
" vertex buffers, but the maximum is "
183 for (
size_t i = 0; i < vertex_buffer_count; i++) {
184 if (!vertex_buffers[i]) {
196 VALIDATION_LOG <<
"Cannot bind an index buffer with an unknown index type.";
212 auto result =
AddCommand(std::move(pending_));
214 bound_textures_start_ = std::nullopt;
215 bound_buffers_start_ = std::nullopt;
216 vertex_buffers_start_ = std::nullopt;
218 return fml::Status();
220 return fml::Status(fml::StatusCode::kInvalidArgument,
221 "Failed to encode command");
235 return BindBuffer(stage, slot, std::move(resouce));
243 std::shared_ptr<const Texture> texture,
248 if (!texture || !texture->IsValid()) {
252 return BindTexture(stage, slot, std::move(resource), sampler);
258 std::unique_ptr<ShaderMetadata> metadata,
267 return BindBuffer(stage, slot, std::move(resouce));
274 std::unique_ptr<ShaderMetadata> metadata,
275 std::shared_ptr<const Texture> texture,
282 if (!texture || !texture->IsValid()) {
287 return BindTexture(stage, slot, std::move(resource), sampler);
293 if (!bound_buffers_start_.has_value()) {
303 const SampledImageSlot& slot,
305 raw_ptr<const Sampler> sampler) {
306 TextureAndSampler
data = TextureAndSampler{
308 .texture = std::move(resource),
313 if (!bound_textures_start_.has_value()) {
std::vector< TextureAndSampler > bound_textures_
virtual bool BindDynamicResource(ShaderStage stage, DescriptorType type, const SampledImageSlot &slot, std::unique_ptr< ShaderMetadata > metadata, std::shared_ptr< const Texture > texture, raw_ptr< const Sampler >)
Bind with dynamically generated shader metadata.
const bool has_depth_attachment_
static bool ValidateIndexBuffer(const BufferView &index_buffer, IndexType index_type)
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
virtual bool BindResource(ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const ShaderMetadata *metadata, BufferView view) override
const bool has_stencil_attachment_
virtual void SetStencilReference(uint32_t value)
const RenderTarget & GetRenderTarget() const
SampleCount GetSampleCount() const
The sample count of the attached render target.
virtual bool SetIndexBuffer(BufferView index_buffer, IndexType index_type)
Specify an index buffer to use for this command. To unset the index buffer, pass IndexType::kNone to ...
bool AddCommand(Command &&command)
Record a command for subsequent encoding to the underlying command buffer. No work is encoded into th...
const SampleCount sample_count_
virtual bool OnEncodeCommands(const Context &context) const =0
virtual void SetScissor(IRect scissor)
PixelFormat GetRenderTargetPixelFormat() const
The pixel format of the attached render target.
const Matrix & GetOrthographicTransform() const
RenderPass(std::shared_ptr< const Context > context, const RenderTarget &target)
std::vector< Command > commands_
const std::shared_ptr< const Context > context_
std::vector< BufferResource > bound_buffers_
static bool ValidateVertexBuffers(const BufferView vertex_buffers[], size_t vertex_buffer_count)
bool HasStencilAttachment() const
Whether the render target has an stencil attachment.
virtual void OnSetLabel(std::string_view label)=0
const Matrix orthographic_
void SetLabel(std::string_view label)
std::vector< BufferView > vertex_buffers_
virtual void SetPipeline(PipelineRef pipeline)
The pipeline to use for this command.
const ISize render_target_size_
ISize GetRenderTargetSize() const
virtual void SetInstanceCount(size_t count)
virtual fml::Status Draw()
Record the currently pending command.
bool HasDepthAttachment() const
Whether the render target has a depth attachment.
virtual void SetElementCount(size_t count)
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
bool EncodeCommands() const
Encode the recorded commands to the underlying command buffer.
const std::shared_ptr< const Context > & GetContext() const
virtual void SetBaseVertex(uint64_t value)
virtual void SetViewport(Viewport viewport)
const RenderTarget render_target_
const PixelFormat pixel_format_
static Resource MakeDynamic(std::unique_ptr< ShaderMetadata > metadata, ResourceType p_resource)
static constexpr size_t kReservedVertexBufferIndex
@ kNone
Does not use the index buffer.
Resource< std::shared_ptr< const Texture > > TextureResource
raw_ptr< Pipeline< PipelineDescriptor > > PipelineRef
A raw ptr to a pipeline object.
Resource< BufferView > BufferResource
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
constexpr size_t kMaxVertexBuffers
An object used to specify work to the GPU along with references to resources the GPU will used when d...
uint32_t stencil_reference
BufferView index_buffer
The index buffer binding used by the vertex shader stage.
std::optional< Viewport > viewport
std::optional< IRect > scissor
A 4x4 matrix using column-major storage.
Metadata required to bind a combined texture and sampler.
BufferView index_buffer
The index buffer binding used by the vertex shader stage.
std::shared_ptr< const fml::Mapping > data