metal-cpp

RSS for tag

C++ games and apps can tap into the power of Metal by bridging with metal-cpp.

Posts under metal-cpp tag

13 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Metal Inline Functions
Hi! How to define and call an inline function in Metal? Or simple function that will return some value. Case: inline uint index4D(constant _4D& shape, constant uint& n, constant uint& c, constant uint& h, constant uint& w) { return n * shape.C * shape.H * shape.W + c * shape.H * shape.W + h * shape.W + w; } When I call it in my kernel function I get No matching function for call error. Thx in advance.
1
0
102
2d
Errors Building XCode Project
This project had been stable for years, doing hundreds of updates for customers but XCode has suddenly started generating lists of errors with every build. I have sent in reports in Feedback Assistant but never get any response. Is this a recent regression in XCode? This project is Objective-C++ with C++11, clang with lots of assembly for both CPU families. Cleaning up ... Building XCode Project... --- xcodebuild: WARNING: Using the first of multiple matching destinations: { platform:macOS, arch:arm64, id:00006001-000851861A42401E } { platform:macOS, arch:x86_64, id:00006001-000851861A42401E } { platform:macOS, name:Any Mac } --- xcodebuild: WARNING: Using the first of multiple matching destinations: { platform:macOS, arch:arm64, id:00006001-000851861A42401E } { platform:macOS, arch:x86_64, id:00006001-000851861A42401E } { platform:macOS, name:Any Mac } 2024-10-02 22:42:09.000 xcodebuild[3235:7055835] [MT] DVTAssertions: Warning in /System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot11/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-22269/IDEFoundation/Provisioning/Capabilities Infrastructure/IDECapabilityQuerySelection.swift:103 Details: createItemModels creation requirements should not create capability item model for a capability item model that already exists. Function: createItemModels(for:itemModelSource:) Thread: <_NSMainThread: 0x6000033fc2c0>{number = 1, name = main} Please file a bug at https://feedbackassistant.apple.com with this warning message and any useful information you can provide. 2024-10-02 22:42:09.000 xcodebuild[3235:7055835] [MT] DVTAssertions: Warning in /System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot11/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-22269/IDEFoundation/Provisioning/Capabilities Infrastructure/IDECapabilityQuerySelection.swift:103 Details: createItemModels creation requirements should not create capability item model for a capability item model that already exists. Function: createItemModels(for:itemModelSource:) Thread: <_NSMainThread: 0x6000033fc2c0>{number = 1, name = main} Please file a bug at https://feedbackassistant.apple.com with this warning message and any useful information you can provide. 2024-10-02 22:42:09.000 xcodebuild[3235:7055835] [MT] DVTAssertions: Warning in /System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot11/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-22269/IDEFoundation/Provisioning/Capabilities Infrastructure/IDECapabilityQuerySelection.swift:103 Details: createItemModels creation requirements should not create capability item model for a capability item model that already exists. Function: createItemModels(for:itemModelSource:) Thread: <_NSMainThread: 0x6000033fc2c0>{number = 1, name = main} Please file a bug at https://feedbackassistant.apple.com with this warning message and any useful information you can provide. 2024-10-02 22:42:09.000 xcodebuild[3235:7055835] [MT] DVTAssertions: Warning in /System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot11/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-22269/IDEFoundation/Provisioning/Capabilities Infrastructure/IDECapabilityQuerySelection.swift:103 Details: createItemModels creation requirements should not create capability item model for a capability item model that already exists. Function: createItemModels(for:itemModelSource:) Thread: <_NSMainThread: 0x6000033fc2c0>{number = 1, name = main} Please file a bug at https://feedbackassistant.apple.com with this warning message and any useful information you can provide. 2024-10-02 22:42:09.000 xcodebuild[3235:7055835] [MT] DVTAssertions: Warning in === CUT 10000 LINES of XCode Errors === PS: the maximum length on these forum posts is crazy small!
1
0
260
Oct ’24
Can't link metal-cpp to Modern Rendering With Metal sample
There is a sample project from Apple here. It has a scene of a city at night and you can move in it. It basically has 2 parts: application code written in what looks like Objective-C (I am more familiar with C++), which inherits from things like NSObject, MTKView, NSViewController and so on - it processes input and all app-related and window-related stuff. rendering code that also looks like Objective-C. Btw both parts are mostly in .mm files (Obj-C++ AFAIK). The application part directly uses only one class from the rendering part - AAPLRenderer. I want to move the rendering part to C++ using metal-cpp. For that I need to link metal-cpp to the project. I did it successfully with blank projects several times before using this tutorial. But with this sample project Xcode can't find Foundation/Foundation.hpp (and other metal-cpp headers). The error says this: Did not find header 'Foundation.hpp' in framework 'Foundation' (loaded from '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/System/Library/Frameworks') Pls help
1
0
291
Sep ’24
A little trick
I had a problem that my app did not work outside Xcode (had to include the metalkit.framework I found a simple trick to get my NSLog outputs and locate the issue: NSURL *downloadsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDownloadsDirectory inDomains:NSUserDomainMask] firstObject]; NSURL *fileURL = [downloadsDirectory URLByAppendingPathComponent:@"Log.txt"]; NSString *filePath = [fileURL path]; // Redirect stderr to the file freopen([filePath fileSystemRepresentation], "a+", stderr); Now you get debug info in your Download folder!
2
0
462
Jul ’24
Can't link metal-cpp to C++ framework in Swift Mac app
I have a very simple Mac app with just a MTKView in it which shows a single color. I want to move the rendering code to C++. For this I created a C++ framework target which interoperates with the Swift code - main project target. I am trying to link metal-cpp library to the C++ framework target using these instructions. Approach described in this article works with simple C++ Mac console apps. But in my mixed Swift/C++ project Xcode cannot find Foundation/Foundation.hpp (and probably other headers) to include into the C++ header. I inserted metal-cpp folder into my project and added it to C++ target's header search paths, as written in the instructions.
4
0
594
Oct ’24
Metal-cpp doesn't show window content on startup
I'm trying to follow the metal-cpp tutorials I've found at https://developer.apple.com/metal/sample-code/?q=learn The program seems to be launching correctly (I can see the menu bar and interact with it), but nothing is rendered inside the window. I suppose the culprit is somewhere in the following function (I see it binds the device, the view and the window with the object in charge of drawing stuff in the view) void core::Application::applicationDidFinishLaunching(NS::Notification *pNotification) { CGRect frame = (CGRect){{100.0, 100.0}, {512.0, 512.0}}; m_Window->init(frame, NS::WindowStyleMaskClosable | NS::WindowStyleMaskTitled, NS::BackingStoreBuffered, false); m_Device = MTL::CreateSystemDefaultDevice(); m_View = MTK::View::alloc()->init(frame, m_Device); m_View->setColorPixelFormat(MTL::PixelFormat::PixelFormatBGRA8Unorm); m_View->setClearColor(MTL::ClearColor::Make(1.0, 0.0, 0.0, 1.0)); m_ViewDelegate = new graphics::ViewDelegate(m_Device); m_View->setDelegate(m_ViewDelegate); m_Window->setContentView(m_View); m_Window->setTitle(NS::String::string("Template 1", NS::StringEncoding::UTF8StringEncoding)); m_Window->makeKeyAndOrderFront(nullptr); NS::Application* nsApp = reinterpret_cast<NS::Application*>(pNotification->object()); nsApp->activateIgnoringOtherApps(true); } but, as you can infer from the fact that I'm failing at the very first tutorial of the bunch, I'm quite lost. I've tried debugging the app with the Xcode debugger and I saw that it never enters in this function. void ViewDelegate::drawInMTKView(MTK::View *pView) { m_Renderer->Draw(pView); } Can it be a symptom of some call missing from my code? Thank you in advance for your help
0
0
570
Apr ’24
Overrides symbols on linking
environment: Apple clang version 14.0.3 (clang-1403.0.22.14.1) I am trying to override c++ symbols at linking time for the purpose of inserting measurement code into an existing library. Perhaps typical linkers would search for symbols in specifing order of library and adopt the first hit. Xcode's ld apparently does this in units of a object file. If you create one object file to override one function and link it first, but call another function in the same object file contained in the original library, that one will be adopted. As a result, you cannot override function. To override a function, the function to be overridden must be moved to a new cpp file and separated from the object file. Here is a sample program to test this. https://onedrive.live.com/redir?resid=DD46698E2D493F32!395&authkey=!AJqfiva7CXIDI_Y&e=OaFlSr As you can see in main.cpp, func() and bar() are called from main(). func() and bar() are implemented in func.cpp and bar.cpp, respectively. They are linked to libTest.lib. To override func(), link libTest2.lib implementing func2() in func2.cpp, before libTest.lib. If you run make and look at the code with objdump -d a.out, you can see the override. Because the content of func2() is return i+1, __Z4funci contains leal 1(%rdi), %eax. Then, build with make clean and make CONCAT=1, func() and bar() are concatenated into one cpp file and compiled. The generated a.out is checked in the same way, you will see movl %edi, %eax at same position which means return i; which is the content of func(). This sample is small in scale, but in a larger project, it can be quite a hassle to isolate the functions you want to override. Is there any easier way to override the function? Since the original function name cannot be changed, it is our policy not to use -alias symbol_name alternate_symbol_name. Thanks.
7
0
901
Mar ’24
Metal API on visionOS?
Is it possible to use the Metal API on vision Pro? I noticed that using MTKView in my visionOS app is not recognized, and also noticed other forum posts from months ago saying that MTKView is not yet supported. If it is still not an option, if and when will it be supported? Also wondering about metal-cpp support as well, since my app involves integrating an existing C++ library with visionOS (see here: https://github.com/MinVR/MinVR). Is this possible?
3
1
1.8k
Feb ’24
Unable to read Internal APFS SSD drive
We are trying to read disk sectors raw Data. Sample code can be found at the bottom. For external drive, it is working fine. We are able to see raw data which is not zero. For internal ssd APFS drive, We only get data filled with zeroes. We have tried with System Integrity Protection enabling and disabling. Please let us know Why same API failing for internal APFS drive? Is there any specific API available for reading raw data of internal APFS drive? #include <fcntl.h> #include <unistd.h> #include <iomanip> int main() { // Adjust this to your disk device on macOS const char* diskPath = "/dev/rdisk1"; //internal SSD device on macOS // Size of a sector (usually 4096 bytes for most disks on macOS) const int sectorSize = 4096; // Number of sectors you want to read const int numSectors = 8; // Starting sector number off_t startSector = 0; // Open the disk device using low-level file I/O int diskFile = open(diskPath, O_RDONLY); if (diskFile == -1) { std::cerr << "Error opening disk file." << std::endl; return 1; } // Read multiple sectors into a buffer char buffer[numSectors * sectorSize]; ssize_t bytesRead = pread(diskFile, buffer, numSectors * sectorSize, startSector * sectorSize); // Close the disk file close(diskFile); if (bytesRead != numSectors * sectorSize) { std::cerr << "Error reading sectors." << std::endl; return 1; } // Display the contents of the sectors in hex for (int i = 0; i < numSectors * sectorSize; ++i) { std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)(unsigned char)buffer[i] << " "; if ((i + 1) % 16 == 0) { std::cout << std::endl; } } return 0; }
0
0
604
Feb ’24