• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Micha?Ossowski

f32tof16 confusion

8 posts in this topic

Hi,
I try to find out why this intrinsic is always returning zero. Here's my code:

[code]float4 PS(in float4 vPosition : SV_POSITION) : SV_TARGET
{
float o = 1.5f;
uint res = f32tof16(o);
float resf = asfloat(res);
return float4(resf, 1, 1, 1);
}
[/code]

I tried with different values.
The result should be in the lower part of returned value.

Function is compiled with ps_5_0 profile. Render target's format is R32G32B32_FLOAT. Device: nVidia Quadro 1000M, feature level 11.0.

EDIT:
checked with command-line compiler fxc. The result is:
[code]
//
// Generated by Microsoft ® HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /T ps_5_0 /E ps test.hlsl /Od
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_TARGET 0 xyzw 0 TARGET float xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_output o0.xyzw
mov o0.xyzw, l(0,1.000000,1.000000,1.000000)
ret
// Approximately 2 instruction slots used
[/code]
I'm wondering, why the compiler skips the code without any warning... Edited by Alaryn
0

Share this post


Link to post
Share on other sites
You are trying to convert a float to a uint? or dose the uint stand for half float in hlsl?
i think that f32tof16 is menat to be used when you are writing the final colors to SV_TARGET.
even if you use the asfloat instruction, the number has been converted to a uint and there for might lose data.

so something like this :

[code]
float4 PS(in float4 vPosition : SV_POSITION) : SV_TARGET
{
float o = 1.5f;
return float4(f32tof16(o), 1, 1, 1);
}
[/code]
1

Share this post


Link to post
Share on other sites
That's working, thank you, but documentation says that f32tof16 returns uint and I thought, that float16 bits will be stored in the lower part of uint similarly to f16tof32, where it reads from these bits.
0

Share this post


Link to post
Share on other sites
Yeah, i saw that on the documentation.. but since a uint is 32bits aswell, it´s kinda funny on why it would cast it to a uint.
It could be that on the gpu, an uint is 16bits and only floats is 32bits due to performance.

I will see if i find out why it´s doing this. (skipping your instruction in the orginal code)
1

Share this post


Link to post
Share on other sites
Hmm, I switched render target format to R16G16B16_FLOAT and use following shader:

[code]float4 PS(in float4 vPosition : SV_POSITION) : SV_TARGET
{
return float4(f32tof16(1.5), 1.5, 1, 1);
}[/code]

And finally I looked up the output. The red channel was 0x73c0 (incorrect) and the blue channel 0x3e00 (correct 1.5 representation). Edited by Alaryn
0

Share this post


Link to post
Share on other sites
Or you can use f32to16 to pack two halfs into an uint. Like this:
[CODE]float2 toBeQuantised(333.333, 666.666);
uint half1 = f32to16(toBeQuantised.x);
uint half2 = f32to16(toBeQuantised.y);
uint twoHalfs = half1 | (half2 << 16);[/CODE]

But this doesn't make that much sense or use, in addition to what Kauna said :-) Edited by pcmaster
1

Share this post


Link to post
Share on other sites
Thank you all. After some time I realized that I just didn't understand HLSL implicit conversions and that was general problem for me. ;)

For example, if I want to get "raw" float16 value, I must set RT format to R16G16B16_FLOAT (simplest way) or R32G32B32_UINT (in this case, the value is stored in the LSB).
And if want to send the value via semantic (to another shader), I just have to set its type to uint. Then, the f32tof16 intrinsic works as I want it to work.
0

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
Sign in to follow this  
Followers 0