18 std::shared_ptr<Allocator> allocator)
19 : allocator_(
std::move(allocator)) {}
27 return allocator_->CreateTexture(desc);
38 <<
"Render target does not have color attachment at index 0.";
44 std::optional<ISize> size;
45 bool sizes_are_same =
true;
46 auto iterator = [&](
const Attachment& attachment) ->
bool {
47 if (!size.has_value()) {
48 size = attachment.texture->GetSize();
50 if (size != attachment.texture->GetSize()) {
51 sizes_are_same =
false;
57 if (!sizes_are_same) {
59 <<
"Sizes of all render target attachments are not the same.";
66 std::optional<TextureType> texture_type;
67 std::optional<SampleCount> sample_count;
68 bool passes_type_validation =
true;
69 auto iterator = [&](
const Attachment& attachment) ->
bool {
70 if (!texture_type.has_value() || !sample_count.has_value()) {
71 texture_type = attachment.texture->GetTextureDescriptor().type;
72 sample_count = attachment.texture->GetTextureDescriptor().sample_count;
75 if (texture_type != attachment.texture->GetTextureDescriptor().type) {
76 passes_type_validation =
false;
80 attachment.texture->GetTextureDescriptor().type)
86 attachment.texture->GetTextureDescriptor().sample_count) {
87 passes_type_validation =
false;
89 <<
") has incompatible sample counts.";
97 if (!passes_type_validation) {
106 const std::function<
bool(
const Attachment& attachment)>& iterator)
const {
107 for (
const auto& color : colors_) {
108 if (!iterator(color.second)) {
113 if (depth_.has_value()) {
114 if (!iterator(depth_.value())) {
119 if (stencil_.has_value()) {
120 if (!iterator(stencil_.value())) {
127 if (
auto found = colors_.find(0u); found != colors_.end()) {
128 return found->second.texture->GetTextureDescriptor().sample_count;
134 if (
auto found = colors_.find(index); found != colors_.end()) {
141 auto found = colors_.find(index);
143 if (found == colors_.end()) {
147 return found->second.texture->GetSize();
152 return size.has_value() ? size.value() :
ISize{};
156 auto found = colors_.find(0u);
157 if (found == colors_.end()) {
160 return found->second.resolve_texture ? found->second.resolve_texture
161 : found->second.texture;
166 return texture->GetTextureDescriptor().format;
174 for (
const auto& color : colors_) {
175 max = std::max(color.first, max);
184 colors_[index] = attachment;
190 std::optional<DepthAttachment> attachment) {
191 if (!attachment.has_value()) {
192 depth_ = std::nullopt;
193 }
else if (attachment->IsValid()) {
194 depth_ = std::move(attachment);
200 std::optional<StencilAttachment> attachment) {
201 if (!attachment.has_value()) {
202 stencil_ = std::nullopt;
203 }
else if (attachment->IsValid()) {
204 stencil_ = std::move(attachment);
227 const std::string& label,
229 std::optional<AttachmentConfig> stencil_attachment_config) {
238 color_tex0.
format = pixel_format;
239 color_tex0.
size = size;
252 color0.
texture->SetLabel(
SPrintF(
"%s Color Texture", label.c_str()));
255 if (stencil_attachment_config.has_value()) {
257 stencil_attachment_config.value());
269 const std::string& label,
271 std::optional<AttachmentConfig> stencil_attachment_config) {
285 color0_tex_desc.
format = pixel_format;
286 color0_tex_desc.
size = size;
294 auto color0_msaa_tex = allocator.
CreateTexture(color0_tex_desc);
295 if (!color0_msaa_tex) {
299 color0_msaa_tex->SetLabel(
300 SPrintF(
"%s Color Texture (Multisample)", label.c_str()));
307 color0_resolve_tex_desc.
format = pixel_format;
308 color0_resolve_tex_desc.
size = size;
310 color0_resolve_tex_desc.
usage =
314 auto color0_resolve_tex = allocator.
CreateTexture(color0_resolve_tex_desc);
315 if (!color0_resolve_tex) {
319 color0_resolve_tex->SetLabel(
SPrintF(
"%s Color Texture", label.c_str()));
327 color0.
texture = color0_msaa_tex;
345 if (stencil_attachment_config.has_value()) {
347 stencil_attachment_config.value());
360 const std::string& label,
369 stencil_tex0.
size = size;
382 stencil0.
texture->SetLabel(
SPrintF(
"%s Stencil Texture", label.c_str()));
388 for (
const auto& [_, color] : colors_) {
392 if (color.resolve_texture) {
396 if (depth_.has_value()) {
399 if (stencil_.has_value()) {
406 std::stringstream stream;
408 for (
const auto& [index, color] : colors_) {
409 stream <<
SPrintF(
"Color[%zu]=(%s)", index,
414 stream <<
SPrintF(
"Depth=(%s)",
419 stream <<
SPrintF(
"Stencil=(%s)",