Support attachment clearing when some clearing formats are not specified.
Exclude attachment from shader if clearing format is not specified.
diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md
index d23a6cc..ea56077 100644
--- a/Docs/Whats_New.md
+++ b/Docs/Whats_New.md
@@ -25,6 +25,7 @@
runtime loading on *macOS* via the *Vulkan Loader*.
- Fix error where previously bound push constants can override a descriptor buffer binding
used by a subsequent pipeline that does not use push constants.
+- Support attachment clearing when some clearing formats are not specified.
diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h
index e73ebd1..a23dd0d 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h
+++ b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h
@@ -113,8 +113,9 @@
/**
* Key to use for looking up cached MTLRenderPipelineState instances.
- * Indicates which attachments are used, and holds the Metal pixel formats for each
- * color attachment plus one depth/stencil attachment. Also holds the Metal sample count.
+ * Indicates which attachments are enabled and used, and holds the Metal pixel formats for
+ * each color attachment plus one depth/stencil attachment. Also holds the Metal sample count.
+ * An attachment is considered used if it is enabled and has a valid Metal pixel format.
*
* This structure can be used as a key in a std::map and std::unordered_map.
*/
@@ -131,6 +132,8 @@
bool isAttachmentEnabled(uint32_t attIdx) { return mvkIsAnyFlagEnabled(flags, bitFlag << attIdx); }
+ bool isAttachmentUsed(uint32_t attIdx) { return isAttachmentEnabled(attIdx) && attachmentMTLPixelFormats[attIdx]; }
+
bool isAnyAttachmentEnabled() { return mvkIsAnyFlagEnabled(flags, (bitFlag << kMVKClearAttachmentCount) - 1); }
void enableLayeredRendering() { mvkEnableFlags(flags, bitFlag << kMVKClearAttachmentLayeredRenderingBitIndex); }
diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm
index e0f6fb0..fffa842 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm
+++ b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm
@@ -330,7 +330,7 @@
[msl appendLineMVK];
[msl appendLineMVK: @"typedef struct {"];
for (uint32_t caIdx = 0; caIdx < kMVKClearAttachmentDepthStencilIndex; caIdx++) {
- if (attKey.isAttachmentEnabled(caIdx)) {
+ if (attKey.isAttachmentUsed(caIdx)) {
NSString* typeStr = getMTLFormatTypeString((MTLPixelFormat)attKey.attachmentMTLPixelFormats[caIdx]);
[msl appendFormat: @" %@4 color%u [[color(%u)]];", typeStr, caIdx, caIdx];
[msl appendLineMVK];
@@ -344,7 +344,7 @@
[msl appendLineMVK];
[msl appendLineMVK: @" ClearColorsOut ccOut;"];
for (uint32_t caIdx = 0; caIdx < kMVKClearAttachmentDepthStencilIndex; caIdx++) {
- if (attKey.isAttachmentEnabled(caIdx)) {
+ if (attKey.isAttachmentUsed(caIdx)) {
NSString* typeStr = getMTLFormatTypeString((MTLPixelFormat)attKey.attachmentMTLPixelFormats[caIdx]);
[msl appendFormat: @" ccOut.color%u = %@4(ccIn.colors[%u]);", caIdx, typeStr, caIdx];
[msl appendLineMVK];
@@ -371,7 +371,7 @@
case kMVKFormatColorFloat:
case kMVKFormatDepthStencil:
case kMVKFormatCompressed: return @"float";
- default: return @"unexpected_type";
+ case kMVKFormatNone: return @"unexpected_MTLPixelFormatInvalid";
}
}