Advertisement

Wrong HLSL buffer width

Started by August 11, 2019 12:34 PM
12 comments, last by komilll 5 years, 5 months ago
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.

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?

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

Advertisement

You are seeing broken code on that changeset.

Newest code uses registers - here is .h and .cpp - https://github.com/komilll/LEngine/tree/master/LEngine/src
And here is blur shader - https://github.com/komilll/LEngine/blob/master/LEngine/blurHorizontal.vs

This topic is closed to new replies.

Advertisement