DX11 Can RWTexture2D variables as a parameter for a user-defined function

Recommended Posts

Hi, I am newer of Direct3D 11, and I want to get help from you.

In Direct3D samples, we usually define RWTexture2D variables globally, and use it in functions directly. Is it legal to transfer this variable as a parameter of a user-defined function?

RWTexture2D<float4> texture : regiters(u0);

void setData(RWTexture2D<float4> tex, float2 data)

{    tex[uint2(0, 0)] = data; }

PS_OUTPUT main(PS_INPUT input)

{

    setData(texture, float2(0.0, 0.0));

    PS_OUTPUT output;

    return output;

}

Share this post


Link to post
Share on other sites
17 hours ago, ajmiles said:

There's no reason why not. If the compiler accepts it then it should be fine. Everything gets flattened out anyway, so function calls don't exist in the final compiled version anyway.

It is legal and encouraged, global are bad, just in term of code best practice.

Even without dynamic texture indexing, but you may want to call the same function twice with two different textures, imagine for example "float3 SampleNormal( float2 uv, Texture2D img, SamplerState samp )", you can now factorize the typical normal unpacking like "2*xyz-1" in any shader using more than one normal map ( common situation to add extra tiled details ).

 

With d3d12 and vulkan, we have dynamic indexing of textures, and your code don't even have to be flatten anymore, again, it is more a question of good programming practice to start with !

 

 

Share this post


Link to post
Share on other sites
1 hour ago, galop1n said:

It is legal and encouraged, global are bad, just in term of code best practice.

Even without dynamic texture indexing, but you may want to call the same function twice with two different textures, imagine for example "float3 SampleNormal( float2 uv, Texture2D img, SamplerState samp )", you can now factorize the typical normal unpacking like "2*xyz-1" in any shader using more than one normal map ( common situation to add extra tiled details ).

 

With d3d12 and vulkan, we have dynamic indexing of textures, and your code don't even have to be flatten anymore, again, it is more a question of good programming practice to start with !

 

 

Thank you for your reply.

I have another question, for D3D11, if I declare a RWTexture2D variable without specifying the register in compute shader, for example

RWTexture2D<float4> texture;

when I call 

void CSSetUnorderedAccessViews(
  [in]                 UINT                             StartSlot,
  [in]                 UINT                             NumUAVs,
  [in, optional]       ID3D11UnorderedAccessView *const *ppUnorderedAccessViews,
  [in, optional] const UINT                             *pUAVInitialCounts
);

How I know the “StartSlot” for HLSL texture variable.  Does it has a default slot for non-register variable, like zero?

 

Share this post


Link to post
Share on other sites
37 minutes ago, galop1n said:

If you do not force it in the shader source, the compiler will decide for you, and you need to use "ID3D11ShaderReflection" to find what the slot is.

Thank you. As we all known, unordered access views(UAVs) are available on all shader stages, and the UAVs that are shared across all pipeline stages. For example, a UAV that is bound at slot 0 at the output-merger stage is available at slot 0 to VS/HS/DS/GS/PS. If a RWTexture2D variable are declared the same in vertex shader and pixel shader. Does the compiler ensure to assigned the same slot for the two variables?

The vertex shader and pixel shader all declare a variable as below,

RWTexture2D<float4> texture;

In OpenGL, if two uniform exist in vertex shader and pixel shader respectively, with the same name, they are bound the the same binding value. Does d3d11 is like it?

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Forum Statistics

    • Total Topics
      628740
    • Total Posts
      2984470
  • Similar Content

    • By That_One_Sander
      I need a Unity Developer for a game I've been working on for the past months.
      It's a 2D dungeonCrawler with a typing mechanic along with Item specific attacks and Procedule Generated levels.
      The development is planned to be 4 months long(up to 8 months maximum).
      Although this is a hobby project the person who apply to work on this project will be paid once we(the team) find investors for the game.
      Anyone interested Send an Email to netinhocrisosto@gmail.com with your portifolio or just talk about your expereince with Unity.
       
       
    • By th3luck
      Hello everyone! I have decided to make a crane simulator (first person with view from cabin). Mostly, I aim on realism as I want this simulator to be used by real сrane operators to upgrade their skill. That's why I need an engine to easily work with physics (such as wind, rain, weight of cargo and etc). Have to mention that I don't really care about graphics quality. Maybe, but this has the least priority, after completing the whole project I would need a VR version of it, but for now I am planning just a PC version. 
      Here is main points of my project:
      Physics has the major priority Using tools suitable for a beginner developer Ability to make a VR version of the simulator without rewriting of the whole project My experience in programming is mostly in computer science, so I am familiar with C++ and Python, but only on a level of coding some cool algorithms. That's why I don't really depend on a specific language. 
      What engine and developer tools would you recommend to use? Easy to being with for a low-skilled like me, but suitable for my project.
      Thanks,
      Mike
    • By INTwindwolf
      THE PROJECT

      INT is a 3D Sci-fi RPG with a strong emphasis on story, role playing, and innovative RPG features such as randomized companions. The focus is on the journey through a war-torn world with fast-paced combat against hordes of enemies. The player must accomplish quests like a traditional RPG, complete objectives, and meet lively crew members who will aid in the player's survival. Throughout the game you can side and complete missions through criminal cartels, and the two major combatants, the UCE and ACP, of the Interstellar Civil War.
      Please note that all of our current positions are remote work. You will not be required to travel.
      Talent Needed
       
      Unity Engine Programmer
      Website Administrator
      3D Animator
      We have made great strides in the year 2017! INT has received a comprehensive face-lift compared to the start of the year. We look forward to a productive, fruitful year 2018!
      Revenue-Share
      This is the perfect opportunity to get into the game development industry. Being an Indie team we do not have the creative restrictions often imposed by publishers or other third parties. We are extremely conscientious of our work and continuously uphold a high level of quality throughout our project.
      We are unable to offer wages or per-item payments at this time. However revenue-sharing from crowd-funding is offered to team members who contribute 15-20 hours per week to company projects, as well as maintain constant communication and adhere to deadlines. Currently the crowd-funding campaign is scheduled for the year 2018. Your understanding is dearly appreciated.
       
      Thank you for your time! We look forward to hearing from you!
       
      John Shen
      HR Lead
      Starboard Games LLC
    • By NexusDivision
      Hello people of gamedev.net

      Me and my team have been working on a MMORPG game with Unreal Engine 4 for quite some time now.
      We are seeking beta tester's and have beta key's available to people who sign up on our website.
      Please visit the website https://nexusdivision.com
      Feel free to register on our forums, We can talk about the game and help everyone get a better idea of what type of game it is. 

      Legion is a 3D fantasy MMORPG that has features including massive scale battles, unique characters and monsters, customization of avatars, special equipment and more. Players choose between the starter stats of Warrior, Magician, Archer and character advancement occurs through a mix of questing, PvP, Guild Wars, and hunting, depending upon player preference. In Legion, completely open PvP battles take place between members of the two warring factions.

      We plan to make this game very competitive and exciting 
    • By Matuda
      Hello!
      Trying to create a physics puzzle game in my "free" time.
      So far it's going very steady, but slow.
      Hope to get some feedback from you!



      Area 86 is a physics-based game, that lets you control a robot at a secret place in space.
      From simple item moving to custom imagined solutions with item picking, throwing, combining and activating!
      Explore & examine all possibilities each place has to offer and do your best to get further.
      But remember, each action has consequences and thus could break or make something unexpected.


      Quick overlook of main features:
      Physics-based gameplay with no bugs or whatsoever Tasks that give you more clue on how to do things wrong Controllable robot who can be blamed for all consequences Includes more than 1 level and each level contains less than 12 possible tasks to complete [ not in free version ] Secret places and hidden objects for extra challenge  
      What can you find in the free downloadable version:
      One fully completable level with 6 tasks and 2 hidden special items to discover.
      From the task list, 2 are main tasks which you should complete to get further and then there are 4 other tasks that should challenge your thinking.
      One of the secret items is visible instant, but you need to figure out how to collect it, while the other special item is hiding.
      Another extra feature is visual hints, that should force your thinking of discovering features.

      Download playable version for your system:

          



  • Popular Now