Compiling DirectX11 Shader Files - c++

I am currently following the DirectX 11 tutorial from www.rastertek.com in the 2nd series of tutorials. I'm currently using VS2015 on a Windows7 x64. Following this tutorial has me using the Windows 10 kit.
I've successfully completed the first 3 tutorials and was able to render a colored window using DirectX 11. I've just completed tutorial 4 to render a colored triangle using the HLSL with a vertex & pixel shaders. I'm following this tutorial where both the vertex and pixel shaders are in separate files the only difference in my code is the file extension that I'm using. His website uses *.vs and *.ps respectively where I'm using *.vsh and *.psh since this gives me code highlighting. All of my class files compile correctly but when I begin to build out my solution I am getting this error.
1>------ Build started: Project: DirectX 11 Engine, Configuration: Debug x64 ------
1>FXC : error X3501: 'main': entrypoint not found
1>
1> compilation failed; no code produced
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The creator of this website does not have any contact information or community based forums. I do not know if this is an error within the website's tutorial or not. Now I know that this code has worked before using older versions of VS such as 2010, 2012 and 2013 on both Windows Vista and Windows 7 using both Windows 7 & Windows 8 kits from his first series of DirectX 10 & DirectX 11 tutorials. I wasn't able to find any help from www.msdn.com since some of their tutorials are written with the requirement of Windows 8 for DirectX 11 using VS2013. Their documentation is quite poor too.
One of the things that I have noticed that is different within DirectX 11 from the Windows Kit versus the deprecated June 2010 Direct X SDK release when Compiling a Shader file is as follows:
June 2010 Direct X SDK - Uses:
HRESULT result;
result = D3DX11CompileFromFile( "shaderFilename", NULL, NULL, "ShaderName", "*s_5_0" or "*s_5_1", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pShaderBuffer, &pErrorMessage, NULL );
Versus...
This tutorial (Windows 10 kit from VS2015) - Uses:
HRESULT result;
result = D3DCompileFromFile( "shaderFilename", NULL, NULL, "ShaderName", "*s_5_0" or "*s_5_1", D3D10_SHADER_ENABLE_STRICTNESS, 0, &pShaderBuffer, &pErrorMessage );
Where the shader filename, shader name, feature level, and the shader buffer is either a Vertex or Pixel Shader Type. And the feature level being used in both these cases is "5_0" and not "5_1" even though I have specified both feature levels.
I'm not sure what has changed between the different compilers for DirectX's HLSL, and I don't understand where or why this error is being generated from. I do not know if the Shader Source code from the website's tutorial is missing something, or if there is some kind of property or setting in VS2015 not set right that I'm unaware of. I am open for any and all suggestions to help resolve this issue.

Visual Studio automatically compiles the shaders for you using FXC. Here, FXC reports that it cannot find the main entry point, i.e. the function main. This is the default, you have 2 solutions:
Assuming the VertexShader entry point is ColorVertexShader (it is in the tutorial you linked), change it to main
Change the entry point in the properties: Right click on file -> Properties -> HLSL Compiler -> General -> Entrypoint name
Because Visual Studio compiles the shaders for you, you don't have to compile them yourself via D3DCompileFromFile, consider using D3DReadFileToBlob to read the data, then passing them in CreateVertexShader from the ID3D11Device.
If you don't want to FXC to compile the shaders, you can Right click on file -> Properties -> General -> Item type - Change it to Does not participate in build

After I have submitted this question; I happened to stumble onto this question FXC : error X3501: 'main': entrypoint not found and from some of the comments and answers there. I simply ended up right clicking on the "color.psh" and "color.vsh" files and under their properties:
Configuration Properties -> General -> Excluded From Build section I set the flag to "Yes"
HLSL Compiler -> General -> Shader Type section I set the Shader Type respectively for Pixel & Vertex Shader For Each File.
HLSL Compiler -> General -> Shader Model section I set to Shader Model 5.0(/5_0) for both files.
Now every thing builds successfully and I am rendering a Green Triangle on a Black Windowed Background as expected.

The error message is quite explicit, the compiler is not able to find the entry point, by default it is main. My guess is that your shaders use something like vsmain or psmain...
If you look at the documentation of D3DCompileFromFile, then you will see that one parameter is the name of the entry point : https://msdn.microsoft.com/en-us/library/windows/desktop/hh446872(v=vs.85).aspx
Also, imagine that "*s_5_0" or "*s_5_1" is a pseudo code of you, or is a deprecated feature in recent C++ and here would just or two pointer and give true, and the compile function does not recognize wildcards.

Related

Why doesn't the c++ file run in visual studio

So I tried making a basic game on the console using screen buffers, I was able to create it and make a square move in the canvas, but for my next project I looked up a website with the ASCII characters and pasted a couple into a comment at the end of the c++ file, when I ran the file visual studio prompted:
I clicked yes and it didn't run anymore.
Also I recently have installed an extension for visual studio (before it didn't run, the extension works fine but I don't know if the extension may have caused this as I didn't tried running it with the extension downloaded and applied), when I open visual studio and open a file it says:
The last record in the ActivityLog xml file, has a type of error and it's description is:
Microsoft.VisualStudio.Composition.CompositionFailedException: Expected 1 export(s) with contract name "Microsoft.VisualStudio.CppSvc.Internal.CodeAnalysis.ICodeAnalysisService" but found 0 after applying applicable constraints.
at Microsoft.VisualStudio.Composition.ExportProvider.GetExports(ImportDefinition importDefinition)
at Microsoft.VisualStudio.Composition.ExportProvider.GetExports[T,TMetadataView](String contractName, ImportCardinality cardinality)
at
Microsoft.VisualStudio.Composition.ExportProvider.GetExport[T,TMetadataView](String contractName)
at
Microsoft.VisualStudio.Composition.ExportProvider.GetExport[T](String contractName)
at
Microsoft.VisualStudio.Composition.ExportProvider.GetExportT
at
Microsoft.VisualStudio.Composition.ExportProvider.GetExportedValueT
at Microsoft.VisualStudio.ComponentModelHost.ComponentModel.GetServiceT
at Microsoft.VisualStudio.VC.ManagedInterop.<>c.<Initialize>b__52_15()
at
System.Lazy`1.CreateValue()
at
System.Lazy`1.LazyInitValue()
at
System.Lazy`1.get_Value()
at
Microsoft.VisualStudio.VC.CodeAnalysis.ResultTaggerProvider.CreateTagger[T](ITextBuffer buffer)
at
Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator`1.GatherTaggers(ITextBuffer textBuffer)
--- End of stack trace from previous location where exception was thrown ---
at
Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
I have Visual Studio 2017
So why does running the file (with the local windows debugger button) say that there were build errors? And how can I fix it?
When it prompts the build error, and I click no it usually shows the errors but in this case it doesn't, yes will just run the last "successful" build (although I haven't changed the file since I have finished it before this error message started popping up)
Also there is no error in my code as I was able to run it before the build error kept appearing and I haven't touched the file since(only now to show the problems are)
Thanks for your time! if anything was unclear because of my English, comment and I'll try to clarify it
I fixed the error by deleting ComponentModelChache folder located at:
C:\Users\%userName%\AppData\Local\Microsoft\VisualStudio\15.0
15.0 is the version of your visual studio so it varies depending on the version you're using, %userName% is a replacement for the user you're logged in as

integrating cocos2d-x with gaf in visual studio

i'm using cocos2d-x 3.7 on windows, visual studio 2013 and GAF_VERSION 5.0.
i'v downloaded "Cocos2dxGAFPlayer" and copied it into cocos2d/external, after that i added the gafplayer project to my cocos2dx project solution. i'm not sure but i think i have configured it properly as its running while it has this code in "HelloWorld::init()" :
auto animation = GAFAsset::createWithBundle("anim1.zip", "anim1/anim1.gaf", nullptr);
object = animation->createObjectAndRun(true);
object->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
object->setPosition(Director::getInstance()->getVisibleSize() / 2);
this->addChild(object,1);
but by using this only the png file, containing parts of animation is shown( i have attached the file i mean).
when i use the zip file generated by gap in the GAFTest project by only replacing the recourse (not the source code) it works fine.
i've searched the net for a solution, and a correct way to integrate cocos2d-x and gaf. but i couldn't find a way.
please guide me.
is there any tutorial about how to integrate cocos2d-x with gaf on visual studio so i make sure i'm doing the configuration right?
tnx
A member of GAFmedia forum suggested something which solved the problem : http://gafmedia.com/forum/viewtopic.php?f=8&t=447
Postby Dmitry Bushtets ยป October 7th, 2015, 7:36 am
I have one idea. Have you method call to CODE: SELECT ALL
cocos2d::Director::setContentScaleFactor
in the code? (it can be in AppDelegate.cpp) If yes - try to remove
this call (set content scale factor to 1) and check result. Or
convert swf to gaf with CSF 1 and 2 (and 3, 4 maybe :) ). You can find
this option in GAF Converter. [Texture Atlas -> Scale Settings ->
Advanced]

Netbeans IDE 8.0.2 C++ Input/Output Error

I installed netbeans C++ on windows 7 and used Cywgin4 as the compiler. When I run any program even a simple Hello world it does compile and run however I also get the error below. I can't seem to find any reference to it online. Can anyone point me in the right direction for a solution? Thanks!
read from master failed
: Input/output error
RUN FAILED (exit value 1, total time: 47ms)
I do not understand all the surrounding details of this problem as I am new to C/C++. However, if you:
Open up NetBeans
Right click on your C++ project file
Select "Properties"
There should be a category called "Run".
Under this category, find the option called Console Type and make sure that Standard Output is selected as shown in the screenshot below:
I was having the same problems when the console type was selected as Internal Terminal.
For my setup, changing this option to Standard Output got rid of this error. However, I do not fully understand how this change affects the overall properties of my project. Wish you good luck.

C++ Compilation introduce errors

I have a multi-threaded C++ windows project in Visual Studio 2010 which uses Qt (5.1.1) and OpenCV (2.4.8). When I build it in Debug mode everything runs fine, but when I build it in Release mode the program crashes. Both configurations are almost identical (just in Release I have Multi-threaded DLL /MD and in Debug Multi-threaded Debug DLL /MDd), I disabled optimizations for the Release, and even enabled debug to catch the error. What's most weird is that the same piece of code that crashes, runs just fine in another console project.
The error is internal to OpenCV's code, it's not related to my code, my code is just:
void MyProject::findEllipses(QImage &frame, vector<RotatedRect> &ellipses)
{
Mat image = Mat(frame.height(), frame.width(), CV_8UC4, frame.scanLine(0));
cvtColor(image, image, CV_RGB2GRAY);
GaussianBlur(image, image, Size(3, 3), 0, 0, 4);
threshold(image, image, treshVal, 255, THRESH_BINARY);
vector<vector<Point> > contours;
Mat contoursImage = image.clone();
findContours(contoursImage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE, Point(0, 0));
// ....Mode Code
As I said in Debug the code runs without a problem, findContours calls _contours.create(total, 1, 0, -1, true); (in line 1720 of OpenCV's contours.cpp) and moves on that method....BUT in Release, when I step into _contours.create(total, 1, 0, -1, true), instead of executing that method, the program jumps to void _OutputArray::clear() const (line 1674 of matrix.cpp) and get's trapped in there, because it calls int k = kind(); in it's first line, which, instead of calling cv::kind(), calls:
int _InputArray::type(int i) const
{
int k = kind();
Which calls againg kind() which again calls type() (instead of kind()as it should), making an infinite recursive loop, bringing a stack overflow.
I tried to make a new Visual Studio 2010 project to see if this is a project creation problem but the problem persisted.
My guess is that the function adresses are wrong in release mode so when it tries to call create(), it instead calls another address, making a mess in the stack, but that's just my guess. At first I will blame OpenCV release dlls, but, as I said, in another console project that only runs that particular code, the code runs fine in bot build modes. I don't see how my other threads and code can trigger this behavior, since the error goes down to a wrong function call in OpenCV.
This is way beyond my knowledge and I have no idea how to fix this, I appreciate all the help I can get on this problem, because I already exausted all my ideas to fix it....
EDIT :
I made a small project so anyone can see what's happening.
The files are in:
https://app.box.com/s/3owljl44emv57erinrf8
In order to run it, you have to have OpenCV 2.4.8 and Qt 5.1.1 and configure the Visual Studio 2010 project to get the include files from the right places. In the resources folder there is a image that will be loaded, and in the SaraVisualControl.cpp line 20, you have to place the right path to the image, sorry I didnt made this automatic, but I was in a hurry to pack this in a small project. Any other questions about how to run it, please let me know.
EDIT 2
I found this old thread: http://code.opencv.org/issues/2218 the user appears to have the same problem as I have, and just running CMake with OPENCV_CAN_BREAK_BINARY_COMPATIBILITY turned off appears to solve it. But this option is no longer present in the new versions of OpenCV, as stated here http://code.opencv.org/issues/2358. Does anyone knows the implications of this and how it may be related?
I encountered similar symptoms in the past, when mixing VC runtime versions. If you're working in VC2010 and OpenCV 2.4.8 was built on 2012 or even 2013, your ABI does not match. E.g., the layout in memory of std::vector is different, maybe the order of some methods in a vtable somewhere changed, etc.
An easy way to test this is to inspect the 'Modules' window while debugging and look for runtime dll's of a later version. Yours is msvcr100d.dll, if you see msvcr110d or 120d - this might be the source.
(assuming both you and OpenCV link dynamically to the CRT - which I cannot tell).
The debug and release are different in memory allocations. Usually in Debug mode that allocs are bigger.
May be you abuse some openCV call, but you don't aware of it.
I would do next actions:
Validate that the frame is ok. May be it is too big, or width or height are not initiated;
Validate that after next line the image var is OK
Mat image = Mat(frame.height(), frame.width(), CV_8UC4, rame.scanLine(0));
Is it OK to call cvtColor while the 1st and 2nd param are the same (may be you abuse the CV here)
Is it OK to call GaussianBlur while the 1st and 2nd param are the same? Try to put different 2nd param
The same is with threshold function call
Check that after image.clone call, the countoursImage is a valid matrix.
I'm guessing: In addition to checking that the libraries are all correct themselves, check that you specify all libraries in the same order (in all builds). Otherwise, the linker might bind function names to different implementations during the final linker stage.
I had the same issue.I was using Qt 5.1.1 and opencv248 and my application was crashing after returning from findcontours. Turns out I was using the vc10 libs in the pro file and the corresponding dlls whereas the Qt compiler being used was msvc2013. Switching to the vc12 folder in opencv 248 solved the problem for me.
Have you checked your opencv libraries for Release version.
Opencv has different set of libraries for Release and Debug version. if you have accedently included debug libraries in the release mode. your code will compile with no error but will throw excecption when executed.
To check your libraries goto
Project->Properties->Configuration Properties->linker->Input->Additional Dependencies.
make sure none of your Opencv libraries ends with "d" for release mode.
library for Release : 'opencv_core248.lib'
library for Debug : 'opencv_core248d.lib'
notice the d at the end for debug mode.
I hope this would be helpful.

The SDL library I built from source crashes!

I've successfully built SDL from source using bcc 5.5.1 but any SDL test application using it crashes right away at startup. I'm looking for some help and/or guidance on how to resolve this issue.
Just to fill in some info, SDL-1.2.14 was used. The project's compiled as a dll with multithreading enabled and linked to C runtime dynamically. I've also rebuilt it with debugging info. When I step through with a debugger up to the point of crash it seems to be coming from redirect_stdout in the sdlmain. If I remove sdlmain.lib and use the source file sdl_win32_main.c directly in the SDL test project then that doesn't crash anymore. Instead it just crashes later on at SDL_Init routine.
I've already checked the calling conventions used and they all seem to match up -- everything is using cdecl. I've also checked and made sure the compiled sdl.dll and the test application was using the same dynamic c runtime instead of statically linked.
The SDL wiki under Borland section mentions to use the -b to make sure enum's are same size as int but that option is enabled by the compiler by default unless explicitly turned off. I did rebuild SDL with that compiler/linker switch just to be sure though.
When it crashes, it's always a access violation in trying to write to some address(c000005). Like for example during a typical SDL init attempt like this:
// initialize SDL video
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}
After the call into SDL_Init(), control doesn't flow back into the test application. Instead it crashes somewhere bizarre like somewhere in ntdll.dll with something having to do with NTDLL.RtlEnterCriticalSection. When I inspect the stack trace at that point I usually get something like this:
:77982269
:0044A04C
:0043F02B
:0043F7C4
:0043EF25
SDL_CreateSemaphore(1)
SDL_CreateMutex()
SDL_CreateSemaphore(1)
SDL_CreateMutex()
SDL_CreateSemaphore(1)
SDL_CreateMutex()
SDL_CreateSemaphore(1)
SDL_CreateMutex()
SDL_CreateSemaphore(1)
SDL_CreateMutex()
SDL_CreateSemaphore(1)
SDL_CreateMutex()
SDL_CreateSemaphore(1)
//and it keeps recursing... looks like a stackover? :P
I'm not sure whatelse to try at this point as I'm pretty stumped. If anyone have any suggestions or need me to provide more info please feel free to add it to the comments.
Thanks
Alright, I finally found out what the issue was a couple days ago. The reason for the crash was because the wrong source file was compiled for the given platform.
The project file I used kept compiling SDL_sysmutex.c from threads\generic. The correct SDL_sysmutex.c to use under win32 should have been from threads\win32. I found this out when I was tracing the test programs side by side and the threading modules had different lines of code!
With this little oversight fixed the crashing problems have all but disappeared and all the test demos are running as they should :)