| 1 |
// Copyright (C) 2024 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#include <Metal/Metal.h> |
| 5 |
#include <rhi/qrhi.h> |
| 6 |
|
| 7 |
void *makeRateMap(QRhi *rhi, const QSize &outputSizeInPixels) |
| 8 |
{ |
| 9 |
// note that multiview needs two layers, this example only uses one |
| 10 |
|
| 11 |
MTLDevice *dev = static_cast<const QRhiMetalNativeHandles *>(rhi->nativeHandles())->dev; |
| 12 |
MTLRasterizationRateMapDescriptor *descriptor = [[MTLRasterizationRateMapDescriptor alloc] init]; |
| 13 |
descriptor.screenSize = MTLSizeMake(outputSizeInPixels.width(), outputSizeInPixels.height(), 1); |
| 14 |
MTLSize zoneCounts = MTLSizeMake(8, 8, 1); |
| 15 |
MTLRasterizationRateLayerDescriptor *layerDescriptor = [[MTLRasterizationRateLayerDescriptor alloc] initWithSampleCount:zoneCounts]; |
| 16 |
for (uint row = 0; row < zoneCounts.height; row++) |
| 17 |
layerDescriptor.verticalSampleStorage[row] = 1.0; |
| 18 |
for (uint column = 0; column < zoneCounts.width; column++) |
| 19 |
layerDescriptor.horizontalSampleStorage[column] = 1.0; |
| 20 |
layerDescriptor.horizontalSampleStorage[0] = 0.25; |
| 21 |
layerDescriptor.horizontalSampleStorage[7] = 0.25; |
| 22 |
layerDescriptor.verticalSampleStorage[0] = 0.25; |
| 23 |
layerDescriptor.verticalSampleStorage[7] = 0.25; |
| 24 |
[descriptor setLayer:layerDescriptor atIndex:0]; |
| 25 |
id<MTLRasterizationRateMap> rateMap = [dev newRasterizationRateMapWithDescriptor: descriptor]; |
| 26 |
return rateMap; |
| 27 |
} |
| 28 |
|
| 29 |
void releaseRateMap(void *map) |
| 30 |
{ |
| 31 |
id<MTLRasterizationRateMap> rateMap = (id<MTLRasterizationRateMap>) map; |
| 32 |
[rateMap release]; |
| 33 |
} |