Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Call hardware features from HLSL shader code


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Meltac   Members   -  Reputation: 425

Like
0Likes
Like

Posted 24 July 2012 - 08:01 AM

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.

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 30989

Like
2Likes
Like

Posted 24 July 2012 - 08:16 AM

"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.

#3 Meltac   Members   -  Reputation: 425

Like
0Likes
Like

Posted 25 July 2012 - 06:54 AM

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.

Edited by Meltac, 25 July 2012 - 06:55 AM.


#4 Hodgman   Moderators   -  Reputation: 30989

Like
0Likes
Like

Posted 25 July 2012 - 07:57 AM

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 ddx.
or another example, DX11 GPU's added support for ps_5_0, which includes functions like firstbitlow.
If you tried to use ddx or firstbitlow 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.

Edited by Hodgman, 25 July 2012 - 07:58 AM.


#5 Meltac   Members   -  Reputation: 425

Like
0Likes
Like

Posted 25 July 2012 - 08:52 AM

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)

Edited by Meltac, 25 July 2012 - 08:53 AM.


#6 TiagoCosta   Crossbones+   -  Reputation: 2340

Like
0Likes
Like

Posted 25 July 2012 - 09:06 AM

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.

Edited by TiagoCosta, 25 July 2012 - 09:17 AM.


#7 MJP   Moderators   -  Reputation: 11569

Like
0Likes
Like

Posted 25 July 2012 - 12:14 PM

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++.

#8 Meltac   Members   -  Reputation: 425

Like
0Likes
Like

Posted 25 July 2012 - 02:17 PM

Ok, thanks everybody for the explanations. I think I got the idea now Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS