Temp workaround: provide shader as a string to device.newLibraryWithSource metal-prototype-branch
authoraghaisas
Mon, 25 Feb 2019 15:15:46 +0530
branchmetal-prototype-branch
changeset 57209 268875216dfc
parent 57206 77a160ad0db7
child 57233 faf96b92a47b
Temp workaround: provide shader as a string to device.newLibraryWithSource
src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MetalLayer.m
--- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MetalLayer.m	Fri Feb 22 16:07:58 2019 +0530
+++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MetalLayer.m	Mon Feb 25 15:15:46 2019 +0530
@@ -233,11 +233,41 @@
     //        Need to complete build changes - to build it and read from some other location within jdk
     // ------------------------------------------------------------------------------------------------
     // Load shader library
-    NSError *error = nil;
+    /*NSError *error = nil;
     mtlLayer.mtlLibrary = [mtlLayer.device newLibraryWithFile: @"/tmp/BaseShader.metallib" error:&error];
     if (!mtlLayer.mtlLibrary) {
         NSLog(@"Failed to load library. error %@", error);
         //exit(0);
+    }*/
+
+    NSError* error = nil;
+    NSString* content = @"#include <metal_stdlib>\n"
+    "#include <simd/simd.h>\n"
+    "using namespace metal;\n"
+    "struct MetalVertex"
+    "{"
+    "vector_float4 position;"
+    "vector_float4 color;"
+    "};\n"
+    "struct VertexOut {"
+    "float4 color;"
+    "float4 pos [[position]];"
+    "};\n"
+    "vertex VertexOut vertexShader(device MetalVertex *vertices [[buffer(0)]], uint vid [[vertex_id]]) {"
+    "VertexOut out;"
+    "\n"
+    "out.pos = vertices[vid].position;"
+    "out.color = vertices[vid].color;"
+    "return out;"
+    "}\n"
+    "fragment float4 fragmentShader(MetalVertex in [[stage_in]]) {"
+    "return in.color;"
+    "}";
+
+    mtlLayer.mtlLibrary = [mtlLayer.device newLibraryWithSource:content options:nil error:&error];
+    if (!mtlLayer.mtlLibrary) {
+        NSLog(@"Failed to create shader library from source. error %@", error);
+        //exit(0);
     }
 
     //create a vertex and fragment objects