Search code examples
c++directxdirectx-11hlsldirectx-9

Is there any DirectX 11 (HLSL 5.0) equivalent to the DirectX 9 texture "string function" syntax?


I am currently working with the source code from the GPU Gems 2 book, and I'm attempting to convert the Improved Perlin Noise implementation (Chapter 26) to work with DirectX 11. Although relatively painless, the optimisations they've used have been a slight annoyance due to their use of textures to aid lookups. The original code uses a now seemingly defunct method to declare textures which I don't know how to convert to modern DirectX.

An example of the type of texture declaration I'm meaning is: (from the inoise.fxh file)

texture permTexture
<
    string texturetype = "2D";
    string format = "l8";
    string function = "GeneratePermTexture";
    int width = 256, height = 1;
>;

The texture type, format, width and height I understand how to configure outside of the shader, the string function = "GeneratePermTexture" part though has thrown me.

The function it's referring to: (in the same file)

float4 GeneratePermTexture(float p : POSITION) : COLOR
{
    return permutation[p*256] / 255.0;
}

There's a comment above this section of the file (which contains more of these functions for their respective textures) saying // Functions to generate textures using CPU runtime

Is there any simple way to do this with Dx11? My current train of investigation is suggesting I should be using the D3D11_SUBRESOURCE_DATA *pInitialData part of the CreateTexture functions.


Solution

  • The things between the < and > in the texture declaration are called annotations. Although the Effect system in D3DX9 has several "standard annotations", 'function' doesn't appear to be one of them. The standard annotations were mainly used by external tools to aid in authoring shaders, for example in RenderMonkey.

    These values provide no actual extra functionality within the context of DirectX, but likely serve as meta-data, which the C++ code would use to generate the textures. The annotation values can be queried (in C++) with GetAnnotation, or GetAnnotationByName functions. If you are porting these to DirectX 11, you can simply hardcode these values in your C++ code, or, load them from a data file.