Skip to content

Unintentional conversion to double precision #2432

Closed
@JohnGierach

Description

@JohnGierach

I have run into a problem where the following example code is converting all of the intermediate variables going into "sum" are converted to double precision.

float sum = (samples.x ? 1.0 : 0.0)
+ (samples.y ? 1.0 : 0.0)
+ (samples.z ? 1.0 : 0.0)
+ (samples.w ? 1.0 : 0.0);

Historically the fxc compiler was more forgiving and would keep such values as floating point precision.

This behavior will unintentionally make shaders use double precision which will be slower and may lack support from all hardware vendors.

When I changed the code to:

float sum = (samples.x ? 1.0f : 0.0f)
+ (samples.y ? 1.0f : 0.0f)
+ (samples.z ? 1.0f : 0.0f)
+ (samples.w ? 1.0f : 0.0f);

I was able to run the application on the desired hardware.

Ideally the dxc compiler would be smart enough to keep this data in floating point format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug, regression, crash

    Type

    No type

    Projects

    Status

    Triaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions