Support attachment clearing when some clearing formats are not specified.

Exclude attachment from shader if clearing format is not specified.
This commit is contained in:
Bill Hollings 2022-04-19 09:02:56 -04:00
parent e3f8ce4ebc
commit 751dac4391
3 changed files with 9 additions and 5 deletions

View File

@ -25,6 +25,7 @@ Released TBD
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.

View File

@ -113,8 +113,9 @@ namespace std {
/**
* 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 @@ typedef struct MVKRPSKeyClearAtt {
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); }

View File

@ -330,7 +330,7 @@ id<MTLFunction> MVKCommandResourceFactory::newClearFragFunction(MVKRPSKeyClearAt
[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 @@ id<MTLFunction> MVKCommandResourceFactory::newClearFragFunction(MVKRPSKeyClearAt
[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 @@ NSString* MVKCommandResourceFactory::getMTLFormatTypeString(MTLPixelFormat mtlPi
case kMVKFormatColorFloat:
case kMVKFormatDepthStencil:
case kMVKFormatCompressed: return @"float";
default: return @"unexpected_type";
case kMVKFormatNone: return @"unexpected_MTLPixelFormatInvalid";
}
}