Jump to content

  • Log In with Google      Sign In   
  • Create Account


Compression in HLSL


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
4 replies to this topic

#1 smallGame   Members   -  Reputation: 208

Like
0Likes
Like

Posted 21 June 2013 - 07:52 PM

Hi,

 

I want to put 4 values of 256 bits in a float and read these 4 values in HLSL. Do you know if it is possible, in c++ I see several way to do that by using union or reinterpret_cast. But both are not avaible in HLSL:

 

To be clear I wrote a simple example :

// 4 values in c++
char v1 = 1, v2 = 2, v3 = 3, v4 = 4;
// Store them in C++
int store = (v1 << 0) | (v2 << 8) | (v3 << 16) | (v4 << 24);
// Put them in a float
float valueStored = *reinterpret_cast<float*>(&store);

// Now I want to use these values
// Oh no I cannot use reinterpret_cast!! :( in HLSL
int uncompress = *reinterpret_cast<int*>(&valueStored);

// Read the value
char o1, o2, o3, o4;
o1 = (char) uncompress & 0xFF;
o2 = (char)(uncompress >> 8) & 0xFF;
o3 = (char)(uncompress >> 16) & 0xFF;
o4 = (char)(uncompress >> 24) & 0xFF;

I want to use a float and not an int because I want to send a float4 to the GPU, with 3 floats and 1 float with 4 values.

 

Thanks for your help,

 

cheers,


Edited by smallGame, 22 June 2013 - 12:32 PM.


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 28614

Like
0Likes
Like

Posted 21 June 2013 - 09:41 PM

Which version of HLSL (shader model 2/3/4/5) are you targeting?

#3 smallGame   Members   -  Reputation: 208

Like
0Likes
Like

Posted 21 June 2013 - 09:51 PM

Hi Hodgman,

 

I am using shader model 4 and 5, I don't have any restriction...

 

I saw you are helping a lot of people on this forum, so I guess I ll have a solution quite soon :) . I am really wondering why talented people like you spend so much time to help people stuck like me :).

 

Thanks,



#4 Hodgman   Moderators   -  Reputation: 28614

Like
8Likes
Like

Posted 21 June 2013 - 10:58 PM

SM4/5 has asint/asuint, which is the same as a reinterpret_cast to int/uint. From there, you can shift and mask as usual.
 

I am really wondering why talented people like you spend so much time to help people stuck like me

When I see a question that I can't answer, I wait for someone else to answer it and then I've learned something. That way I don't just learn what I'm looking for right now, but also what a dozen other people are looking for.
When I see a question that I can answer, by putting the answer into words myself, it forces me to make sure that I really do understand the question and reinforces my own learning.
I have become a much better programmer by reading these forums for years biggrin.png

Edited by Hodgman, 21 June 2013 - 10:59 PM.


#5 smallGame   Members   -  Reputation: 208

Like
0Likes
Like

Posted 26 June 2013 - 03:31 PM

Hi,

 

Thanks for your help ! Everything is working perfectly ! So it was an easy question I miss-read the doc ;)
 

see you


Edited by smallGame, 27 June 2013 - 06:04 AM.





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