I am trying to follow instructions on creating Custom Direct2D Effects, as described in Custom Effects and Effect Shader Linking. I am getting into number of problems:
The "d2d1effecthelpers.hlsli" file in not found in my Windows SDK. I could only find it here.
When trying to run fxc compiler with model set to lib_4_0_level_9_1_ps_only I get an error that this model is not supported.
When using lib_4_0_level_9_1 instead, I get another compilation error, saying that static variables are not supported for libraries (and this static definition comes from the above HLSLI file, not from my code).
After all my goal is to create a pixel shader for Direct2D, which will be receiving number of textures as input. Maybe something in my environment is missing and I can't follow the examples (I'm using Windows 8.1). Any suggestions are welcome.
Related
I'm working on a little SceneKit project, and I want to generate my textures programmatically using a Metal Compute pipeline for speed. I have a basic pipeline set up that generates an MTLTexture and it works, but as soon as I add the SceneKit framework to the project, it fails claiming Function <X> was not found in the library. If I remove all references to SceneKit it works again.
I must be instantiating my library from the correct URL or it wouldn't work without SceneKit. What's blocking it? Is there a way around this issue, perhaps using an SCNRenderer?
[Edit] For more clarity, here's how I obtain a reference to my MTLLibrary:
guard let url = Bundle.main.url(forResource: "MyLibrary", withExtension: "metallib") else {
throw GeneratorError.metalLibraryNotFound
}
library = device.makeLibrary(URL: url)
A strong reference is kept by the calling object (along with the MTLDevice), and it's a singleton so it remains in memory. To obtain the kernel function itself I then call the following function, which returns an appropriate pipeline state:
guard let function = library.makeFunction(name: functionName) else {
throw GeneratorError.functionNotFound(functionName)
}
return device.makeComputePipelineState(function: function)
Like I say, this works fine until SceneKit is added to the project - and simply adding the framework to the linked frameworks list is enough, I don't have to do anything with it - whereupon it simply can't find any of my functions.
I have found out what was causing this issue, but I am still highly confused as to why, so I'd appreciate any further input people have!
Essentially, I had split my Metal library up amongst several files to make it easier to work on. One had CIFilter-supported functions in, the other had Metal pipeline kernels. Now, I knew that the two were incompatible when both were linked in the main .metal file, so I'd commented one out temporarily but kept it for reference. I also had the linker flag -cikernel in build settings.
I'd suspected that the linker flag might cause problems, but removing it made things worse. Eventually I tried removing the linker flag AND the entire file that I had previously merely commented out. This worked! I guess the compiler must compile ALL .metal files regardless of their inclusion in the main file, and somehow, having CIFilter kernels and texturing kernels in the same library is a big no-no, even though they were not in the same namespace.
If anyone knows the reasoning behind this, I'd love to know! In the meantime I am simply going to remove all CIFilters and work with pure Metal-based compute pipelines instead.
I am using an fmod plugin for Unity3D. Compiling to Windows and OSX is fine because I can dynamically load the DLL/dylib.
The problem comes when I compile for iOS. I use
[DllImport("__Internal")]
Because iOS requires statically linked libraries. When I compile though I get a
SystemException: Duplicate native method found : FMOD_System_CreateSound. Please check your source carefully.
I am quite sure I don't duplicate the symbol. I think this might be due to the fact that Unity imports FMODs itself and that the two might be colliding... But if this is the case, I am surprised that FMOD_System_CreateSound is the first one to get caught. Is there a way around this? thx!
As always, I will be happy to provide any additional details!
Here is a sample project that will cause the error:
Sample Unity Project with FMod
EDIT:
The conflict was caused by iOS not allowing functions to have the same name even though they don't have the same signature. After removing the same-named functions (thus removing some FMOD features that I didn't need), I can compile to iOS, but as expected, I still get an error when Initializing because FMOD is already initialized by Unity.
Unity3d already has a limited version of FMOD that is bundled with it, which is causing the conflict you are seeing. Unfortunately, it doesn't seem possible to disable it at this time, so that you can use the full version of FMOD
In reference to your edit and after looking at the sample, it is true that you cannot have two methods of the same name as the compiler will not recognize which to link to.
The easy fix is to obviously name them differently.
As for the initialization, if you can access the FMOD that Unity 3D already created, then you don't have to reinitialize it.
I assume that a pointer to that object will be sufficient to remove the duplicate initialization. Hope this is clear.
I swear I have been looking for the answer to this question exhaustively, but I found no real solution to my problem. And what problem is that?
Well I am new to DirectX and shaders. There are a few things about shaders that I still don't get.
1 - How to make a shader? Do I have to create an .fx file in the project? Some times it is so, but in some examples I can't find any .fx file. And how do I make this file? My version of Visual Studio can't directly create .fx files; I have to "force" the file to be .fx.
2 - How I compile them? Are they compiled at the same time I compile solution or they have special ways to compile?
3 - Is there a nice tutorial around? I have been looking for a shaders-bible but mostly I found vague and short tutorials explaining few things, and never in a deep way.
1. New to Shader ?
To get the introduction to sharder use the free shazzam shader editor (http://shazzam-tool.com/) for creating the simple shaders by interactive draw tools. Try to play with different option and then compare the automatically generated HLSL(.fx) codes for better understanding. After you got the feel of how the shader code to be written buy a standard book/online tutorial and practice to write your own code according to your requirements.
2. Common Methods for compilation:
a. D3DXCreateEffectFromFile- Write the shader code and save in .fx extension and dynamically compile the code by D3DXCreateEffectFromFile. Compiled code can be used in your core module using effect(ID3DXEffect) interface.
b. Explicit Compilation: Write the shader code and save in .fx extension and explicitly compile the code using fxc.exe (You can find in DirectX SDK Utility folder).
Example:
fxc.exe /Tfx_2_0 /Fo file.fxo file.fx
After binary file is created follow as below
1. Create a buffer and load the generated binary file(.fxo) by the file stream.
2. Call D3DXCreateEffect and give the buffer content as a input parameter.
3. Like "method a" use effect(ID3DXEffect) interface for interacting with the
shader code.
3. Introduction Tutorial:
http://rbwhitaker.wikidot.com/hlsl-tutorials
Shaders are just like normal text files you put your shader code in them. You don't need to add them to your project if you are compiling the shader at runtime with the D3D functions.
There are two ways to do this. One is putting your shader code in .fx files or *.hlsl files and then compiling the shader at runtime using D3D library functions (D3DCompileFromFile). Though Microsoft is not suggesting this anymore because D3DCompileFromFile won't work in Metro style apps. The other way is to use fxc.exe to compile your shaders at build time. Visual Studio 2012 made this process part of the usual build. So you can add your hlsl files into your project and they will be build when you build your project. This will also enable you to see any errors/warnings in the shader at compile time.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb509633(v=vs.85).aspx
Hope that helps.
Im trying to add light options to kiwiviewer for visualization of medical 3D Models, in my case a surface model of a head.
I cant find a starting point for hours becouse when I delete all glsl shaders I still get the console output "INFO: Compiling shaders:" without error and the View with the 3D Model displaying correctly
I would appreciate any help.
Manuel
At build time, each shader is encoded into a cpp file and compiled into the library named libvesShaders.a. If you modify a shader, but do not recompile the library and relink the application, the app will continue to operate with the previous version of the shader.
If you want to avoid the recompile step, you could create a new shader file and add it to the xcode project so that the file is packaged with the app. Then read the shader source from the file on the iOS filesystem at runtime.
You might want to try the VES mailing list for VES and KiwiViewer questions in the future.
I have been having a tough time setting up an experiment where I allocate memory with CUDA on the device, take that pointer to memory on the device, use it in OpenCL, and return the results. I want to see if this is possible. I had a tough time getting a CUDA project to work so I just used Nvidia's template project in their SDK. In the makefile I added -lOpenCL to the libs section of the common.mk. Everything is fine when I do that, but when I add #include <CL/cl.h> to template.cu so I can start making OpenCL calls, I get over a 100 errors. They all look similar to this, but with different function names at the end:
/usr/lib/gcc/x86_64-linux-gnu/4.4.1/include/xmmintrin.h(334): error:
identifier "__builtin_ia32_cmpeqps" is undefined
I am having a hard time figuring out why. Please help if you can. Also, if there is an easier way to set up a project that'll be able to call the CUDA and OpenCL APIs let me know.
I haven't really worked with cuda, so I don't know how helpful my answer is.
From what I understand you are trying to use opencl directly from your cuda hostcode, which is if I remember correctly compiled using some compiler from nvidia instead the standard gcc. So the problem is probably that this compiler doesn't implement the necessary builtins to work with the mentioned headers.
Look here for a similar problem and it's solution:
http://forums.nvidia.com/lofiversion/index.php?t88573.html
It seems you have to put everything which needs the opencl api into a different (non cuda) compilation unit so that it will be compiled by the non nvidia compiler.
However I wouldn't count on this working (since opencl buffers aren't just pointers to the memory but should contain some metainformations to), simply because there is no real reason it should work and if it does there is no guarantee that it continues to do so.
What you could try if you really want to is using opengl for the interop, since both opencl and cuda have extensions to allow creating buffers from opengl buffers.
However why do you need to do this? Whats keeping you from using Apple's implementation shortterm, since IIRC it's open source and most of it (the opencl parts) should be platform independent anyways.