Call hardware features from HLSL shader code

Started by
6 comments, last by Meltac 11 years, 9 months ago
Hello

Is it somehow possible to call the hardware-supported features of the respective DirectX version, such as volumetric light and fog in DX10, directly from a vertex or pixel shader using pure HLSL code? Or is the only way to do this with the "D3D..." API functions being called from the main program?

Thanks.
Advertisement
"Volumetric light and fog" aren't hardware features of DX10 GPUs. There's no main-program API, nor HLSL intrinsic that maps to a 'feature' like that... You build advanced features (such as volumetric effects) out of the simpler features of the API/shaders.
Thanks for the correction, but that was not very helpful. As you know very well every DirectX version brings a set of new or improved high-level methods to address low-level methods and GPU hardware features. Some hardware features that could not be addressed directly from a high-level API in a specific DirectX version thus needed to be done purely software-wise, can be addressed fairly simple in a subsequent DirectX version from the main app (as long as the GPU also supports that feature hardware-wise).

So forget about volumetric light and fog, please just tell me if it's possible to address what you call "simpler features" purely from within HLSL shader code, in order to "build advanced features", or if those features are only accessible by the D3D... or whatever API functions.
every DirectX version brings a set of new or improved high-level methods to address low-level methods and GPU hardware features.
This is reflected by the different versions (targets) of HLSL.

DX9 supports Shader Model 1/2/3. DX10 added Shader Model 4. DX11 added Shader Model 5.

e.g. HLSL code that's compiled against the ps_3_0 target can use intrinsic functions that didn't exist in ps_2_0, such as [font=courier new,courier,monospace]ddx[/font].
or another example, DX11 GPU's added support for ps_5_0, which includes functions like [font=courier new,courier,monospace]firstbitlow[/font].
If you tried to use [font=courier new,courier,monospace]ddx[/font] or [font=courier new,courier,monospace]firstbitlow[/font] when compiling your shaders against the ps_2_0 target, you'll get a compile error.

If you compile against a higher target than your GPU supports (e.g. you compile a shader against ps_5_0, and then try to use it on a DX10 GPU), then you'll get a D3D API error when trying to create the shader object from the compiled byte-code.

The MSDN pages for HLSL (such as the links above) show you which targets support each intrinsic function.
Ok, but does that mean that a specific HLSL version / target / shader model provides access to exact the same feature set as the respective higher-level program API? For example, do I have access to the same GPU features from HLSL code compiled against Shader Model 5 / ps_5_0 as I would have when programming XNA / C++ / C# code against the DirectX11 high level API? Or are there any differences between what "simple features" are accessible from within HLSL or XNA functions on the same target?

(always under the condition that the underlying GPU supports the features in question)
HLSL is just used to program GPU's, so they know how to fill a texture, etc.

1-You can't do anything using only HLSL!
2-You write a GPU program called shader in HLSL.
3-You set the correct render target, and textures needed by the shader using DirectX API and C++/C#.
4-You tell the GPU which shader to run using DirectX API and C++/C#.
5-You tell the GPU to execute the shader using DirectX API and C++/C#.

To create more advanced effects you do this multiple times.

Example (shadow mapping) (this is an extreme simplification):

(Application-side code = C++/C# + DirectX API - Executed in the GPU)
(GPU-side code =HLSL shader programs)

Application side:
-Bind the shadow map as the render target.
-Tell the GPU to use the shadow mapping HLSL shader.
-Make the draw calls of the scene geometry.

GPU side:
-The shadow mapping shader calculates the distance from the camera to the geometry vertices and stores it in the render target bound in the application side.

Application side:
-Bind the Back buffer as the render target (back buffer is the texture shown on your screen).
-Bind the shadow map as a shader resource (texture).
-Tell the GPU to use the final HLSL shader.
-Make the draw calls of the scene geometry.

GPU side:
-The shader calculates the color of the screen pixel using the shadow map bound in the application side and the geometry diffuse maps, etc.

ANYWAY: Without C++/C# + DirectX API you can't bind render targets, textures, tell the GPU what to do and when to do it, so HLSL shaders are useless.

Ok, but does that mean that a specific HLSL version / target / shader model provides access to exact the same feature set as the respective higher-level program API? For example, do I have access to the same GPU features from HLSL code compiled against Shader Model 5 / ps_5_0 as I would have when programming XNA / C++ / C# code against the DirectX11 high level API? Or are there any differences between what "simple features" are accessible from within HLSL or XNA functions on the same target?

(always under the condition that the underlying GPU supports the features in question)


HLSL is part of the DirectX API, the two are intertwined. You use HLSL to author your shaders, and you use the API to bind your shaders, set up resources, issue draw calls, etc.

Just so you're clear, XNA is built on top of D3D9 and therefore doesn't have access to anything newer than shader 3.0. The other managed wrappers (SlimDX and SharpDX) fully expose D3D11, so you have access to everything you would in native D3D11 with C++.
Ok, thanks everybody for the explanations. I think I got the idea now smile.png

This topic is closed to new replies.

Advertisement