Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 04 Jan 2010
Offline Last Active Private

Posts I've Made

In Topic: When you realize how dumb a bug is...

18 May 2016 - 05:45 PM

The picture below supposed to be a voxelized sphere.


Problem: operator << has lower precedence than +. Should have used | or brackets.


Now I feel really dumb. :wacko:

In Topic: HLSL Tools for Visual Studio

25 April 2016 - 10:36 PM

This is great. Thanks alot. :D

In Topic: Array in constant buffer

09 February 2016 - 10:34 AM

tbuffers work similarily. Upload is done the same way. And indeed the limit is higher (at least 128 Mb).
They come in different flavors :
  • generic (e.g. Buffer<float4> in HLSL). Allows what DXGI_FORMAT can cover, not every format is allowed though.
  • structured (e.g. StructuredBuffer<matrix>). Allows self-defined structs, though only (u)ints and floats work directly as basic types.
  • raw (ByteAddressBuffer). Here you basically manage the memory yourself.
They are a bit more complicated to set up since they're now bound indirectly through views (like textures): shader resource view for reading or unordered access view for reading and writing (RW prefix in HLSL, registers u#). It needs a bit fiddling with the flags but the D3D debug layer (which you already have enabled) will help you there.

Here an example of a structured buffer ([RW]StructuredBuffer<float3>):

var arraySize = 12;
structuredBuffer = new SharpDX.Direct3D11.Buffer(device, new BufferDescription()
    BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess,
    CpuAccessFlags = CpuAccessFlags.None,
    OptionFlags = ResourceOptionFlags.BufferStructured,
    SizeInBytes = arraySize * Marshal.SizeOf(typeof(Vector3)),
    StructureByteStride = Marshal.SizeOf(typeof(Vector3)),
    Usage = ResourceUsage.Default,
structureBufferSRV = new ShaderResourceView(device, structuredBuffer, new ShaderResourceViewDescription()
    BufferEx = new ShaderResourceViewDescription.ExtendedBufferResource()
        ElementCount = arraySize,
        FirstElement = 0,
        Flags = ShaderResourceViewExtendedBufferFlags.None,
    Format = Format.Unknown,
    Dimension = ShaderResourceViewDimension.ExtendedBuffer,
structureBufferUAV = new UnorderedAccessView(device, structuredBuffer, new UnorderedAccessViewDescription()
    Buffer = new UnorderedAccessViewDescription.BufferResource()
        ElementCount = arraySize,
        FirstElement = 0,
        Flags = UnorderedAccessViewBufferFlags.None,
    Format = Format.Unknown,
    Dimension = UnorderedAccessViewDimension.Buffer,

In Topic: Array in constant buffer

04 February 2016 - 09:07 AM

I hear you, this is really weird. I put together a working version (minor changes, seems I used a different SharpDX version), including both the approach I showed and your fixed array variant. Had to fix a couple of other bugs which naturally crawled in with your effort.

I can guide you through the how-to if you wish (it's usually better to learn the debugging techniques than just be given the solution wink.png).

For the future: You seem to be under a restrictive NDA, so I'd advertise that more clearly (e.g. in your signature). Otherwise your threads will continue to look this way.

In Topic: Inverting normals when rendering backfaces

31 January 2016 - 11:23 AM

You can determine the vertex "facing" by looking at the sign of the view space normal's z component (this can be determined in the vertex shader). This is just an estimate though since vertex normals aren't face normals. "Facing" can now change within a triangle. (But has it's use: I've seen similar to achieve early back face culling of whole patches in a hull shader - using a bias).


Just throwing around ideas. 


Edit: Seeing the whole picture might help. What are you after exactly ? Maybe another setup is warranted (geo shader, tesselation shader).