Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

BenS1

Member Since 22 Mar 2006
Offline Last Active Apr 04 2013 06:50 AM
-----

Topics I've Started

Strange Text Rendering Crash In Release Mode Only

03 January 2013 - 05:45 AM

I've got a strange crash that only occurs in a Release build and so its very difficult to debug the problem.

 

If I try single stepping through the code, the current instruction jumps around all over the place (Presumably the code is being reordered as an optimization), and when the crash does occur the debugger put the current instructions somewhere completely illogical, I don't think this is a genuine stack corruption issue, I think the debugger just isn't very good when working with release builds.

 

Anyway, getting to the point....

 

The code is a text rendering code (Originally written by MJP), which I've adapted to work with DirectXMath, and sure enough this is where the problem seems to lie.

 

I the text rendering class I have this structure defined:

    struct SpriteDrawData
    {
        XMMATRIX Transform;
        XMFLOAT4 Color; 
        XMFLOAT4 DrawRect;   
    };    

 

Then I have this member that uses this struct:

	SpriteDrawData				m_TextDrawData[constMaxBatchSize];

 

(Where constMaxBatchSize == 1000)

 

Then in the actual code I do this for each character:

 

	m_TextDrawData[currentDraw].Transform = XMMatrixMultiply(transform, XMMatrixTranslation(x_offset, y_offset, 0.0f));
	m_TextDrawData[currentDraw].Color = color;
	m_TextDrawData[currentDraw].DrawRect.x = desc.X;
	m_TextDrawData[currentDraw].DrawRect.y = desc.Y;
	m_TextDrawData[currentDraw].DrawRect.z = desc.Width;
	m_TextDrawData[currentDraw].DrawRect.w = desc.Height;            
	currentDraw++;

 

However, the first line causes a crash.

If I comment out the first line then it doesn't crash.

 

I've even tried changing it to this:

	m_TextDrawData[currentDraw].Transform =	XMMatrixIdentity();
	m_TextDrawData[currentDraw].Color = color;
	m_TextDrawData[currentDraw].DrawRect.x = desc.X;
	m_TextDrawData[currentDraw].DrawRect.y = desc.Y;
	m_TextDrawData[currentDraw].DrawRect.z = desc.Width;
	m_TextDrawData[currentDraw].DrawRect.w = desc.Height;            
	currentDraw++;

 

But it still crashes (Even when currentDraw == 0, so its not that currentDraw is overflowing).

 

I thought it might be an alignment problem, so I changed the structure definition to:

    __declspec(align(32)) struct SpriteDrawData
    {
        XMMATRIX Transform;
        XMFLOAT4 Color; 
        XMFLOAT4 DrawRect;   
    }; 

 

But that didn't help, and I don't think its necessary as XMMATRIX is already defined with 16 byte alignment.

 

Its really strange. It doesn't do it in a debug build, and if I comment out the code then the release build is fine too but obviously I don't see any text.

 

Any help would be appreciated.

 

Thanks

Ben


Loading Meshes\Models in DirectX 11 using VS2012 and Win8 SDK

01 January 2013 - 02:00 PM

Firstly, Happy New Year all smile.png

 

So, now that the DirectX SDK is now part of the Windows SDK and the Windows SDK doesn't include the Effects Framework, is there any support at all for loading models\meshes when using the latest version?

 

It seems strange that Visual studio 2012 can now load and display model files directly in the IDE, yet DirectX itself doesn't seem to offer any support for using the files.

 

I know that you can still get the Effects Framework to work with the latest version of the SDK, but I'd rather not use a deprecated library (Plus I wasn't really a fan of the Effects Framework anyway, but that's irrelevant). So, do I just have to dig out the file specifications for the model formats I want to support and right my own code to load them, or are there existing libraries out there that I could use?

 

Thanks in advance

Ben

 

 


Emulating a HLSL Sample Operation on the CPU

16 December 2012 - 03:01 PM

Hi

In my game I'm generating a terrain in realtime on the GPU using an fBm noise function. This works fine.

Now what I need is to be able to workout the height of a given position on the landscape on the CPU side so that I can do things such as position objects on the surface of the terrain. This means I need to port the GPU code over to the CPU.

So far I've come across a couple of interesting things when running the HLSL code in the Visual Studio 2012 debugger and then doing the same for the CPU....

Firstly I can the code through the GPU and for a given pixel the debugger showed:
PosW = x = 1214.034000000, z = -1214.034000000

When I tried putting these same values in the CPU side I found that on the CPU the values were actually:
PosW = x 1214.03406, z = -1214.03406

i.e. the CPU couldn't represent the GPU float values exactly. Is this to be expected? Do they not both conform to the exact IEEE standard for a float? I noticed this in several places.

The second problem, the one I'm struggling with is regarding how to emulate a Sample HLSL function on the CPU.

Here is what I have in HLSL:
const float mipLevel = 0;
float4 n;
n.x = g_NoiseTexture.SampleLevel(SamplerRepeatPoint, i, mipLevel).x;
n.y = g_NoiseTexture.SampleLevel(SamplerRepeatPoint, i, mipLevel, int2(1,0)).x;
n.z = g_NoiseTexture.SampleLevel(SamplerRepeatPoint, i, mipLevel, int2(0,1)).x;
n.w = g_NoiseTexture.SampleLevel(SamplerRepeatPoint, i, mipLevel, int2(1,1)).x;
(Where g_NoiseTexture is a 256x256 grayscale texture. I thinkt he Sampler name is self explanatory)

And I've tried to emulate this on the CPU like this:
float nx, ny, nz, nw;
nx = m_NoiseData[(int)(iy)  % 256][(int)(ix) % 256] / 256.0f;
ny = m_NoiseData[(int)(iy)  % 256][(int)(ix + 1.0f) % 256] / 256.0f;
nz = m_NoiseData[(int)(iy + 1.0f)  % 256][(int)(ix) % 256] / 256.0f;
nw = m_NoiseData[(int)(iy + 1.0f)  % 256][(int)(ix + 1.0f) % 256] / 256.0f;
(Where m_NoiseData is defined as "unsigned char m_NoiseData[256][256]" and contains the same data as the g_NoiseTexture)

The problem is that I'm getting completely different for n.x vs nx, n.y vs ny etc.

I've even tried to compensate for pixel centres by adding 0.5f to each pixel like this:

float nx, ny, nz, nw;
nx = m_NoiseData[(int)(iy + 0.5f)  % 256][(int)(ix + 0.5f) % 256] / 256.0f;
ny = m_NoiseData[(int)(iy + 0.5f)  % 256][(int)(ix + 1.5f) % 256] / 256.0f;
nz = m_NoiseData[(int)(iy + 1.5f)  % 256][(int)(ix + 0.5f) % 256] / 256.0f;
nw = m_NoiseData[(int)(iy + 1.5f)  % 256][(int)(ix + 1.5f) % 256] / 256.0f;

Any ideas?

Any help much appreciated.

Kind Regards
Ben

HLSL Support for Doubles

24 November 2012 - 08:21 AM

Hi,

I know that DirectX 11 (Shader Model 5) supports doubles (Although technically optional I believe, but both ATI and NVIDIA quote performance figures for double precision operations, so I guess they both support it.), but how exactly is it supported?

Most HLSL functions seem to only support floats, for example Lerp:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb509618(v=vs.85).aspx

So does this mean that doubles can only be used for basic math and not used in most HLSL functions?

My game world is pretty massive (1 million square miles at the moment) and I'm seeing some strange artifacts on the terrain that I believe are due to floating point precision errors. I've always know that this would happen, but I had been planning to switch to using doubles instead at just take the performance hit, but now I'm not sure how good the support for doubles really is in HLSL.

Failing that I guess I'll have to reread the "Vertex Transform Precision" chapter in "3D Engine Design for Virtual Globes" which provides some more complex solutions to handling massive worlds, but I'd prefer to keep it simpler if possible.

Thanks
Ben

Rendering Normals (For Debugging) using the Geometry Shader

22 November 2012 - 03:19 PM

Hi,

I've got an annoying lighting problem with my terrain engine and I'm not sure if the problem is with my calculation of the terrain surface normals or something else.

I've tried single stepping through the HLSL code but personally I find it a little difficult to visualize vectors when they are just presented as numbers, so I'd much rather actually see the vectors (Normals in this case).

I guess it should be quite trivial to create a Geometry shader that renders the normals... but rather than reinvent the wheel I thought I'd just check to see if anyone has such a shader that I could use? (HLSL SM 5 compatible)

I've tried a quick search but all I've found are OpenGL versions and no HLSL versions.

Anyway, if anyone has such a shader then great. If not then I'll write my own and share it on here for anyone else that may want to use it in future.

Thanks
Ben

PARTNERS