Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9258731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:28:54+00:00 2026-06-18T12:28:54+00:00

people. I have a problem passing a float array to vertex shader (HLSL) through

  • 0

people.

I have a problem passing a float array to vertex shader (HLSL) through constant buffer. I know that each “float” in the array below gets a 16-byte slot all by itself (space equivalent to float4) due to HLSL packing rule:

// C++ struct
struct ForegroundConstants
{
    DirectX::XMMATRIX transform;
    float bounceCpp[64];
};


// Vertex shader constant buffer
cbuffer ForegroundConstantBuffer : register(b0)
{
    matrix transform;
    float bounceHlsl[64];
};

(Unfortunately, the simple solution here does not work, nothing is drawn after I made that change)

While the C++ data gets passed, due to the packing rule they get spaced out such that each “float” in the bounceCpp C++ array gets into a 16-byte space all by itself in bounceHlsl array. This resulted in an warning similar to the following:

ID3D11DeviceContext::DrawIndexed: The size of the Constant Buffer at slot 0 of the Vertex Shader unit is too small (320 bytes provided, 1088 bytes, at least, expected). This is OK, as out-of-bounds reads are defined to return 0. It is also possible the developer knows the missing data will not be used anyway. This is only a problem if the developer actually intended to bind a sufficiently large Constant Buffer for what the shader expects.

The recommendation, as being pointed out here and here, is to rewrite the HLSL constant buffer this way:

cbuffer ForegroundConstantBuffer : register(b0)
{
    matrix transform;
    float4 bounceHlsl[16]; // equivalent to 64 floats.
};

static float temp[64] = (float[64]) bounceHlsl;

main(pos : POSITION) : SV_POSITION
{
    int index = someValueRangeFrom0to63;
    float y = temp[index];

    // Bla bla bla...
}

But that didn’t work (i.e. ID3D11Device1::CreateVertexShader never returns). I’m compiling things against Shader Model 4 Level 9_1, can you spot anything that I have done wrong here?

Thanks in advance! 🙂

Regards,
Ben

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:28:55+00:00Added an answer on June 18, 2026 at 12:28 pm

    One solution, albeit non optimal, is to just declare your float array as

    float4 bounceHlsl[16];
    

    then process the index like

    float x = ((float[4])(bounceHlsl[i/4]))[i%4];
    

    where i is the index you require.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem that other people must have encountered. I am working
Seems to be a problem that many people have, but all the answers I
I have a peculiar problem, which I think that a lot of other people
Problem statement We have one employer that wants to interview N people, and therefore
My problem is that the database fields have been badly designed by previous people
I'm hoping people have some ideas to help solve this problem. I am developing
people. I have slight problem with GD2 text on image. I have everything working
Hello people of stackoverflow. I have a problem. I'm trying to set up my
Hello people i stick on a problem i have a header with no zoom
I have seen several questions with people asking about the same problem but none

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.