Register Ranges in HLSL?












1















I am currently refactoring a large chunk of old code and have finally dove into the HLSL section where my knowledge is minimal due to being out of practice. I've come across some documentation online that specifies which registers are to be used for which purposes:





  • t – for shader resource views (SRV)

  • s – for samplers

  • u – for unordered access views (UAV)

  • b – for constant buffer views (CBV)




This part is pretty self explanatory. If I want to create a constant buffer, I can just declare as:



cbuffer LightBuffer: register(b0) { };
cbuffer CameraBuffer: register(b1) { };
cbuffer MaterialBuffer: register(b2) { };
cbuffer ViewBuffer: register(b3) { };


However, originating from the world of MIPS Assembly I can't help but wonder if there are finite and restricted ranges on these. For example, temporary registers are restricted to a range of t0 - t7 in MIPS Assembly. In the case of HLSL I haven't been able to find any documentation surrounding this topic as everything seems to point to assembly languages and microprocessors (such as the 8051 if you'd like a random topic to read up on).





Is there a set range for the four register types in HLSL or do I just continue as much as needed in a sequential fashion and let the underlying assembly handle the messy details?





Note



I have answered this question partially, as I am unable to find a range for u currently; however, if someone has a better, more detailed answer than what I've given through testing, then feel free to post it and I will mark that as the correct answer. I will leave this question open until December 1st, 2018 to give others a chance to give a better answer for future readers.










share|improve this question





























    1















    I am currently refactoring a large chunk of old code and have finally dove into the HLSL section where my knowledge is minimal due to being out of practice. I've come across some documentation online that specifies which registers are to be used for which purposes:





    • t – for shader resource views (SRV)

    • s – for samplers

    • u – for unordered access views (UAV)

    • b – for constant buffer views (CBV)




    This part is pretty self explanatory. If I want to create a constant buffer, I can just declare as:



    cbuffer LightBuffer: register(b0) { };
    cbuffer CameraBuffer: register(b1) { };
    cbuffer MaterialBuffer: register(b2) { };
    cbuffer ViewBuffer: register(b3) { };


    However, originating from the world of MIPS Assembly I can't help but wonder if there are finite and restricted ranges on these. For example, temporary registers are restricted to a range of t0 - t7 in MIPS Assembly. In the case of HLSL I haven't been able to find any documentation surrounding this topic as everything seems to point to assembly languages and microprocessors (such as the 8051 if you'd like a random topic to read up on).





    Is there a set range for the four register types in HLSL or do I just continue as much as needed in a sequential fashion and let the underlying assembly handle the messy details?





    Note



    I have answered this question partially, as I am unable to find a range for u currently; however, if someone has a better, more detailed answer than what I've given through testing, then feel free to post it and I will mark that as the correct answer. I will leave this question open until December 1st, 2018 to give others a chance to give a better answer for future readers.










    share|improve this question



























      1












      1








      1


      1






      I am currently refactoring a large chunk of old code and have finally dove into the HLSL section where my knowledge is minimal due to being out of practice. I've come across some documentation online that specifies which registers are to be used for which purposes:





      • t – for shader resource views (SRV)

      • s – for samplers

      • u – for unordered access views (UAV)

      • b – for constant buffer views (CBV)




      This part is pretty self explanatory. If I want to create a constant buffer, I can just declare as:



      cbuffer LightBuffer: register(b0) { };
      cbuffer CameraBuffer: register(b1) { };
      cbuffer MaterialBuffer: register(b2) { };
      cbuffer ViewBuffer: register(b3) { };


      However, originating from the world of MIPS Assembly I can't help but wonder if there are finite and restricted ranges on these. For example, temporary registers are restricted to a range of t0 - t7 in MIPS Assembly. In the case of HLSL I haven't been able to find any documentation surrounding this topic as everything seems to point to assembly languages and microprocessors (such as the 8051 if you'd like a random topic to read up on).





      Is there a set range for the four register types in HLSL or do I just continue as much as needed in a sequential fashion and let the underlying assembly handle the messy details?





      Note



      I have answered this question partially, as I am unable to find a range for u currently; however, if someone has a better, more detailed answer than what I've given through testing, then feel free to post it and I will mark that as the correct answer. I will leave this question open until December 1st, 2018 to give others a chance to give a better answer for future readers.










      share|improve this question
















      I am currently refactoring a large chunk of old code and have finally dove into the HLSL section where my knowledge is minimal due to being out of practice. I've come across some documentation online that specifies which registers are to be used for which purposes:





      • t – for shader resource views (SRV)

      • s – for samplers

      • u – for unordered access views (UAV)

      • b – for constant buffer views (CBV)




      This part is pretty self explanatory. If I want to create a constant buffer, I can just declare as:



      cbuffer LightBuffer: register(b0) { };
      cbuffer CameraBuffer: register(b1) { };
      cbuffer MaterialBuffer: register(b2) { };
      cbuffer ViewBuffer: register(b3) { };


      However, originating from the world of MIPS Assembly I can't help but wonder if there are finite and restricted ranges on these. For example, temporary registers are restricted to a range of t0 - t7 in MIPS Assembly. In the case of HLSL I haven't been able to find any documentation surrounding this topic as everything seems to point to assembly languages and microprocessors (such as the 8051 if you'd like a random topic to read up on).





      Is there a set range for the four register types in HLSL or do I just continue as much as needed in a sequential fashion and let the underlying assembly handle the messy details?





      Note



      I have answered this question partially, as I am unable to find a range for u currently; however, if someone has a better, more detailed answer than what I've given through testing, then feel free to post it and I will mark that as the correct answer. I will leave this question open until December 1st, 2018 to give others a chance to give a better answer for future readers.







      range hlsl






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 16:39







      PerpetualJ

















      asked Nov 16 '18 at 15:20









      PerpetualJPerpetualJ

      780120




      780120
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Resource slot count (for d3d11, indeed d3d12 case expands that) are specified in Resource Limit msdn page.



          The ones which are of interest for you here are :




          • D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT (which is t) = 128

          • D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT (which is s) = 16

          • D3D11_COMMONSHADER_CONSTANT_BUFFER_HW_SLOT_COUNT (which is b) = 15 but one is reserved to eventually store some constant data from shaders (if you have a static const large array for example)


          The u case is different, as it depends on Feature Level (and tbh is a vendor/os version mess) :




          • D3D11_FEATURE_LEVEL_11_1 or greater, this is 64 slots

          • D3D11_FEATURE_LEVEL_11 : It will always be 8 (but some cards/driver eventually support 64, you need at least windows 8 for it (It might also be available in windows 7 with some platform update too). I do not recall a way to test if 64 is supported (many nvidia in their 700 range do for example).

          • D3D11_FEATURE_LEVEL_10_1 : either 0 or 1, there's a way to check is compute is supported


          You need to perform a feature check:



          D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS checkData;

          d3dDevice->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &checkData);

          BOOL computeSupport = checkData.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x


          Please note that for some OS/Driver version I had this flag returning TRUE while not supported (Intel was doing that on win7/8), so in that case the only valid solution was to try to either create a small Raw / Byte Address buffer or a Structured Buffer and check the HRESULT



          As a side note feature feature level 10 or below are for for quite old configurations nowadays, so except for rare scenarios you can probably safely ignore it (I just leave it for information purpose).






          share|improve this answer

































            0














            Since it's usually a long wait time for these types of questions I tested the b register by attempting to create a cbuffer in register b51. This failed as I expected and luckily SharpDX spit out an exception that stated it has a maximum of 14. So for the sake of future readers I am testing all four register types and posting back the ranges I find successful.





            • b has a range of b0 - b13.


            • s has a range of s0 - s15.


            • t has a range of t0 - t127.


            • u has a range of .


            At the current moment, I am unable to find a range for the u register as I have no examples of it in my code, and haven't actually ever used it. If someone comes along that does have an example usage then feel free to test it and update this post for future readers.





            I did find a contradiction to my findings above in the documentation linked in my question; they have an example using a t register above the noted range in this answer:



            Texture2D                     a[10000] : register(t0);
            Texture2D b[10000] : register(t10000);
            ConstantBuffer<myConstants> c[10000] : register(b0);




            Note



            I would like to point out that I am using the SharpDX version of the HLSL compiler and so I am unsure if these ranges vary from compiler to compiler; I heavily doubt that they do, but you can never be too sure until you try to exceed them. GLSL may be the same due to being similar to HLSL, but it could also be very different.






            share|improve this answer

























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53340681%2fregister-ranges-in-hlsl%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Resource slot count (for d3d11, indeed d3d12 case expands that) are specified in Resource Limit msdn page.



              The ones which are of interest for you here are :




              • D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT (which is t) = 128

              • D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT (which is s) = 16

              • D3D11_COMMONSHADER_CONSTANT_BUFFER_HW_SLOT_COUNT (which is b) = 15 but one is reserved to eventually store some constant data from shaders (if you have a static const large array for example)


              The u case is different, as it depends on Feature Level (and tbh is a vendor/os version mess) :




              • D3D11_FEATURE_LEVEL_11_1 or greater, this is 64 slots

              • D3D11_FEATURE_LEVEL_11 : It will always be 8 (but some cards/driver eventually support 64, you need at least windows 8 for it (It might also be available in windows 7 with some platform update too). I do not recall a way to test if 64 is supported (many nvidia in their 700 range do for example).

              • D3D11_FEATURE_LEVEL_10_1 : either 0 or 1, there's a way to check is compute is supported


              You need to perform a feature check:



              D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS checkData;

              d3dDevice->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &checkData);

              BOOL computeSupport = checkData.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x


              Please note that for some OS/Driver version I had this flag returning TRUE while not supported (Intel was doing that on win7/8), so in that case the only valid solution was to try to either create a small Raw / Byte Address buffer or a Structured Buffer and check the HRESULT



              As a side note feature feature level 10 or below are for for quite old configurations nowadays, so except for rare scenarios you can probably safely ignore it (I just leave it for information purpose).






              share|improve this answer






























                1














                Resource slot count (for d3d11, indeed d3d12 case expands that) are specified in Resource Limit msdn page.



                The ones which are of interest for you here are :




                • D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT (which is t) = 128

                • D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT (which is s) = 16

                • D3D11_COMMONSHADER_CONSTANT_BUFFER_HW_SLOT_COUNT (which is b) = 15 but one is reserved to eventually store some constant data from shaders (if you have a static const large array for example)


                The u case is different, as it depends on Feature Level (and tbh is a vendor/os version mess) :




                • D3D11_FEATURE_LEVEL_11_1 or greater, this is 64 slots

                • D3D11_FEATURE_LEVEL_11 : It will always be 8 (but some cards/driver eventually support 64, you need at least windows 8 for it (It might also be available in windows 7 with some platform update too). I do not recall a way to test if 64 is supported (many nvidia in their 700 range do for example).

                • D3D11_FEATURE_LEVEL_10_1 : either 0 or 1, there's a way to check is compute is supported


                You need to perform a feature check:



                D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS checkData;

                d3dDevice->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &checkData);

                BOOL computeSupport = checkData.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x


                Please note that for some OS/Driver version I had this flag returning TRUE while not supported (Intel was doing that on win7/8), so in that case the only valid solution was to try to either create a small Raw / Byte Address buffer or a Structured Buffer and check the HRESULT



                As a side note feature feature level 10 or below are for for quite old configurations nowadays, so except for rare scenarios you can probably safely ignore it (I just leave it for information purpose).






                share|improve this answer




























                  1












                  1








                  1







                  Resource slot count (for d3d11, indeed d3d12 case expands that) are specified in Resource Limit msdn page.



                  The ones which are of interest for you here are :




                  • D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT (which is t) = 128

                  • D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT (which is s) = 16

                  • D3D11_COMMONSHADER_CONSTANT_BUFFER_HW_SLOT_COUNT (which is b) = 15 but one is reserved to eventually store some constant data from shaders (if you have a static const large array for example)


                  The u case is different, as it depends on Feature Level (and tbh is a vendor/os version mess) :




                  • D3D11_FEATURE_LEVEL_11_1 or greater, this is 64 slots

                  • D3D11_FEATURE_LEVEL_11 : It will always be 8 (but some cards/driver eventually support 64, you need at least windows 8 for it (It might also be available in windows 7 with some platform update too). I do not recall a way to test if 64 is supported (many nvidia in their 700 range do for example).

                  • D3D11_FEATURE_LEVEL_10_1 : either 0 or 1, there's a way to check is compute is supported


                  You need to perform a feature check:



                  D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS checkData;

                  d3dDevice->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &checkData);

                  BOOL computeSupport = checkData.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x


                  Please note that for some OS/Driver version I had this flag returning TRUE while not supported (Intel was doing that on win7/8), so in that case the only valid solution was to try to either create a small Raw / Byte Address buffer or a Structured Buffer and check the HRESULT



                  As a side note feature feature level 10 or below are for for quite old configurations nowadays, so except for rare scenarios you can probably safely ignore it (I just leave it for information purpose).






                  share|improve this answer















                  Resource slot count (for d3d11, indeed d3d12 case expands that) are specified in Resource Limit msdn page.



                  The ones which are of interest for you here are :




                  • D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT (which is t) = 128

                  • D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT (which is s) = 16

                  • D3D11_COMMONSHADER_CONSTANT_BUFFER_HW_SLOT_COUNT (which is b) = 15 but one is reserved to eventually store some constant data from shaders (if you have a static const large array for example)


                  The u case is different, as it depends on Feature Level (and tbh is a vendor/os version mess) :




                  • D3D11_FEATURE_LEVEL_11_1 or greater, this is 64 slots

                  • D3D11_FEATURE_LEVEL_11 : It will always be 8 (but some cards/driver eventually support 64, you need at least windows 8 for it (It might also be available in windows 7 with some platform update too). I do not recall a way to test if 64 is supported (many nvidia in their 700 range do for example).

                  • D3D11_FEATURE_LEVEL_10_1 : either 0 or 1, there's a way to check is compute is supported


                  You need to perform a feature check:



                  D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS checkData;

                  d3dDevice->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &checkData);

                  BOOL computeSupport = checkData.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x


                  Please note that for some OS/Driver version I had this flag returning TRUE while not supported (Intel was doing that on win7/8), so in that case the only valid solution was to try to either create a small Raw / Byte Address buffer or a Structured Buffer and check the HRESULT



                  As a side note feature feature level 10 or below are for for quite old configurations nowadays, so except for rare scenarios you can probably safely ignore it (I just leave it for information purpose).







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 29 '18 at 17:44

























                  answered Dec 29 '18 at 12:21









                  catfliercatflier

                  5,65711541




                  5,65711541

























                      0














                      Since it's usually a long wait time for these types of questions I tested the b register by attempting to create a cbuffer in register b51. This failed as I expected and luckily SharpDX spit out an exception that stated it has a maximum of 14. So for the sake of future readers I am testing all four register types and posting back the ranges I find successful.





                      • b has a range of b0 - b13.


                      • s has a range of s0 - s15.


                      • t has a range of t0 - t127.


                      • u has a range of .


                      At the current moment, I am unable to find a range for the u register as I have no examples of it in my code, and haven't actually ever used it. If someone comes along that does have an example usage then feel free to test it and update this post for future readers.





                      I did find a contradiction to my findings above in the documentation linked in my question; they have an example using a t register above the noted range in this answer:



                      Texture2D                     a[10000] : register(t0);
                      Texture2D b[10000] : register(t10000);
                      ConstantBuffer<myConstants> c[10000] : register(b0);




                      Note



                      I would like to point out that I am using the SharpDX version of the HLSL compiler and so I am unsure if these ranges vary from compiler to compiler; I heavily doubt that they do, but you can never be too sure until you try to exceed them. GLSL may be the same due to being similar to HLSL, but it could also be very different.






                      share|improve this answer






























                        0














                        Since it's usually a long wait time for these types of questions I tested the b register by attempting to create a cbuffer in register b51. This failed as I expected and luckily SharpDX spit out an exception that stated it has a maximum of 14. So for the sake of future readers I am testing all four register types and posting back the ranges I find successful.





                        • b has a range of b0 - b13.


                        • s has a range of s0 - s15.


                        • t has a range of t0 - t127.


                        • u has a range of .


                        At the current moment, I am unable to find a range for the u register as I have no examples of it in my code, and haven't actually ever used it. If someone comes along that does have an example usage then feel free to test it and update this post for future readers.





                        I did find a contradiction to my findings above in the documentation linked in my question; they have an example using a t register above the noted range in this answer:



                        Texture2D                     a[10000] : register(t0);
                        Texture2D b[10000] : register(t10000);
                        ConstantBuffer<myConstants> c[10000] : register(b0);




                        Note



                        I would like to point out that I am using the SharpDX version of the HLSL compiler and so I am unsure if these ranges vary from compiler to compiler; I heavily doubt that they do, but you can never be too sure until you try to exceed them. GLSL may be the same due to being similar to HLSL, but it could also be very different.






                        share|improve this answer




























                          0












                          0








                          0







                          Since it's usually a long wait time for these types of questions I tested the b register by attempting to create a cbuffer in register b51. This failed as I expected and luckily SharpDX spit out an exception that stated it has a maximum of 14. So for the sake of future readers I am testing all four register types and posting back the ranges I find successful.





                          • b has a range of b0 - b13.


                          • s has a range of s0 - s15.


                          • t has a range of t0 - t127.


                          • u has a range of .


                          At the current moment, I am unable to find a range for the u register as I have no examples of it in my code, and haven't actually ever used it. If someone comes along that does have an example usage then feel free to test it and update this post for future readers.





                          I did find a contradiction to my findings above in the documentation linked in my question; they have an example using a t register above the noted range in this answer:



                          Texture2D                     a[10000] : register(t0);
                          Texture2D b[10000] : register(t10000);
                          ConstantBuffer<myConstants> c[10000] : register(b0);




                          Note



                          I would like to point out that I am using the SharpDX version of the HLSL compiler and so I am unsure if these ranges vary from compiler to compiler; I heavily doubt that they do, but you can never be too sure until you try to exceed them. GLSL may be the same due to being similar to HLSL, but it could also be very different.






                          share|improve this answer















                          Since it's usually a long wait time for these types of questions I tested the b register by attempting to create a cbuffer in register b51. This failed as I expected and luckily SharpDX spit out an exception that stated it has a maximum of 14. So for the sake of future readers I am testing all four register types and posting back the ranges I find successful.





                          • b has a range of b0 - b13.


                          • s has a range of s0 - s15.


                          • t has a range of t0 - t127.


                          • u has a range of .


                          At the current moment, I am unable to find a range for the u register as I have no examples of it in my code, and haven't actually ever used it. If someone comes along that does have an example usage then feel free to test it and update this post for future readers.





                          I did find a contradiction to my findings above in the documentation linked in my question; they have an example using a t register above the noted range in this answer:



                          Texture2D                     a[10000] : register(t0);
                          Texture2D b[10000] : register(t10000);
                          ConstantBuffer<myConstants> c[10000] : register(b0);




                          Note



                          I would like to point out that I am using the SharpDX version of the HLSL compiler and so I am unsure if these ranges vary from compiler to compiler; I heavily doubt that they do, but you can never be too sure until you try to exceed them. GLSL may be the same due to being similar to HLSL, but it could also be very different.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 16 '18 at 15:36

























                          answered Nov 16 '18 at 15:26









                          PerpetualJPerpetualJ

                          780120




                          780120






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53340681%2fregister-ranges-in-hlsl%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              Tangent Lines Diagram Along Smooth Curve

                              Yusuf al-Mu'taman ibn Hud

                              Zucchini