Initial RPS CUDA implementation
This commit is contained in:
commit
8d583036d0
33 changed files with 2968 additions and 0 deletions
59
tests/metal_render.mm
Normal file
59
tests/metal_render.mm
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#include "renderer.hpp"
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
int main() {
|
||||
@autoreleasepool {
|
||||
auto device = MTLCreateSystemDefaultDevice();
|
||||
auto queue = [device newCommandQueue];
|
||||
auto pipeline = buildPipeline(device);
|
||||
if (!queue || !pipeline)
|
||||
return 1;
|
||||
auto texture = [&](int w, int h, MTLTextureUsage usage) {
|
||||
auto desc = [MTLTextureDescriptor
|
||||
texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
|
||||
width:w
|
||||
height:h
|
||||
mipmapped:NO];
|
||||
desc.usage = usage;
|
||||
desc.storageMode = MTLStorageModeShared;
|
||||
return [device newTextureWithDescriptor:desc];
|
||||
};
|
||||
// BGRA in little-endian memory. Distinct corners detect axis inversions.
|
||||
const std::array<uint32_t, 4> corners{0xffff0000u, 0xff00ff00u, 0xff0000ffu,
|
||||
0xffffffffu};
|
||||
auto input = texture(2, 2, MTLTextureUsageShaderRead);
|
||||
[input replaceRegion:MTLRegionMake2D(0, 0, 2, 2)
|
||||
mipmapLevel:0
|
||||
withBytes:corners.data()
|
||||
bytesPerRow:8];
|
||||
auto target = texture(8, 4, MTLTextureUsageRenderTarget);
|
||||
auto pass = [MTLRenderPassDescriptor renderPassDescriptor];
|
||||
auto dst = pass.colorAttachments[0];
|
||||
dst.texture = target;
|
||||
dst.loadAction = MTLLoadActionClear;
|
||||
dst.storeAction = MTLStoreActionStore;
|
||||
dst.clearColor = MTLClearColorMake(0, 0, 0, 1);
|
||||
auto cmd = [queue commandBuffer];
|
||||
if (!encodeImage(cmd, pass, input, pipeline))
|
||||
return 1;
|
||||
[cmd commit];
|
||||
[cmd waitUntilCompleted];
|
||||
if (cmd.status != MTLCommandBufferStatusCompleted)
|
||||
return 1;
|
||||
std::array<uint32_t, 32> actual{};
|
||||
[target getBytes:actual.data()
|
||||
bytesPerRow:32
|
||||
fromRegion:MTLRegionMake2D(0, 0, 8, 4)
|
||||
mipmapLevel:0];
|
||||
for (int y = 0; y < 4; ++y)
|
||||
for (int x = 0; x < 8; ++x) {
|
||||
uint32_t expected =
|
||||
x < 2 || x >= 6 ? 0xff000000u : corners[y / 2 * 2 + (x - 2) / 2];
|
||||
if (actual[y * 8 + x] != expected) {
|
||||
fprintf(stderr, "pixel mismatch at %d,%d\n", x, y);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
puts("PASS Metal BGRA pixels, nearest filtering, aspect and orientation");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue