Jump to content
  • Advertisement
komilll

DX11 Wrong HLSL buffer width

Recommended Posts

Posted (edited)
21 minutes ago, komilll said:

What's the difference between .fx and .vs/.ps? Can I modify .fx on runtime and continue to use it?

.fx files are being compiled with the HLSL compiler in Visual Studio, so there is no need to compile all shaders when you start your program - which might take a minute if you have a lot of shaders. And you are not giving away your shader source code to players. Or students. Our professor at university had put the shader code as text into the example program that should just show us how it should look. We could simply look up all the strings to find the code and then use it for our homework which was writing those exact shaders. 😀

 

21 minutes ago, komilll said:

I had no idea, I wasn't thinking about it back then. However, do you still recommend using std::array<float> or C-style array instead of storing XMFLOAT4 in buffer struct? Or is it ok for feature level 10.0?

XMFLOAT4 is fine, it doesn't require alignment. XMVECTOR and XMMATRIX need the 16 bit alignment for the math operations, including copying afaik. If you only put the structs containing them on the stack and use Map, you are fine if you use __declspec(align(16)) for the structs. But in many cases you need 3 or less components and should use XMFLOAT3 etc. anyway. If you ever want to add DirectX 9 support for people using antiquated hardware this will break though.

Edited by Magogan

Share this post


Link to post
Share on other sites
Advertisement

As your code is currently written in Github you aren't explicitly declaring which 'register' each constant buffer should be assigned (you were in the original code snippet you posted).

If you declare two constant buffers and elect not to use one of them and *haven't* explicitly declared which register slot each one belongs to then the compiler will assign the *used* constant buffers an index in ascending order as they appear in the code.

You have MatrixBuffer which is unused in the VS and ScreenSizeBuffer which is used. Therefore ScreenSizeBuffer is going to be VS Constant Buffer 0 and there will be no VS Constant Buffer 1.

The corresponding C++ code is setting the ScreenSizeBuffer to be VS cb1 not cb0, so I don't see how it can be working in its current state.

unsigned int bufferNumber{ 1 };
deviceContext->VSSetConstantBuffers(bufferNumber, 1, &m_screenSizeBuffer);

Is what we're seeing in Github the 'working' code or the 'broken' code?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!