Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for literal overloads of fmod, length, and normalize #6437

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/DXIL/DxilOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3566,9 +3566,18 @@ Function *OP::GetOpFunc(OpCode opCode, Type *pOverloadType) {
DXASSERT(0 <= (unsigned)opCode && opCode < OpCode::NumOpCodes,
"otherwise caller passed OOB OpCode");
assert(0 <= (unsigned)opCode && opCode < OpCode::NumOpCodes);
DXASSERT(IsOverloadLegal(opCode, pOverloadType),
"otherwise the caller requested illegal operation overload (eg HLSL "
"function with unsupported types for mapped intrinsic function)");

// Remove this assert on illegal overload for now.
// Illegal overloads are generated and eliminated by DXIL op constant
// evaluation for a number of cases where a double overload of an HL intrinsic
// that otherwise does not support double is used for literal values, when
// there is no constant evaluation for the intrinsic in CodeGen.
// Illegal overloads of DXIL intrinsics may survive through to final DXIL,
// but these will be caught by the validator, and this is not a regression.
// DXASSERT(IsOverloadLegal(opCode, pOverloadType),
// "otherwise the caller requested illegal operation overload (eg HLSL "
// "function with unsupported types for mapped intrinsic function)");

OpCodeClass opClass = m_OpCodeProps[(unsigned)opCode].opCodeClass;
Function *&F =
m_OpCodeClassCache[(unsigned)opClass].pOverloads[pOverloadType];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// RUN: %dxc -T vs_6_0 %s -E main | %FileCheck %s
// RUN: %dxc -T vs_6_0 %s -E main -DNO_FOLD | %FileCheck %s -check-prefixes=NO_FOLD

// Ensure fmod is constant evaluated during codegen, or dxil const eval
// TODO: handle fp specials properly!
tex3d marked this conversation as resolved.
Show resolved Hide resolved

RWBuffer<float4> results : register(u0);

[shader("vertex")]
void main(bool b : B) {
uint i = 0;

// Literal float
// 2.5, -2.5, 2.5, -2.5
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 0, i32 undef, float 2.500000e+00, float -2.500000e+00, float 2.500000e+00, float -2.500000e+00, i8 15)
results[i++] = float4(fmod(5.5, 3.0),
fmod(-5.5, 3.0),
fmod(5.5, -3.0),
fmod(-5.5, -3.0));

// Explicit float
// 2.5, -2.5, 2.5, -2.5
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 1, i32 undef, float 2.500000e+00, float -2.500000e+00, float 2.500000e+00, float -2.500000e+00, i8 15)
results[i++] = float4(fmod(5.5f, 3.0f),
fmod(-5.5f, 3.0f),
fmod(5.5f, -3.0f),
fmod(-5.5f, -3.0f));

#ifdef SPECIALS
// Literal float
// 0.0, -0.0, NaN, -NaN
tex3d marked this conversation as resolved.
Show resolved Hide resolved
results[i++] = float4(fmod(0.0, 1.0),
fmod(-0.0, 1.0),
fmod(5.5, 0.0),
fmod(-5.5, 0.0));
// Explicit float
// 0.0, -0.0, NaN, -NaN
results[i++] = float4(fmod(0.0f, 1.0f),
fmod(-0.0f, 1.0f),
fmod(5.5f, 0.0f),
fmod(-5.5f, 0.0f));
#endif // SPECIALS

#ifdef NO_FOLD
// Currently, we rely on constant folding of DXIL ops to get rid of illegal
// double overloads. If this doesn't happen, we expect a validation error.
// Ternary operator can return literal type, while not being foldable due
// non-constant condition.
// NO_FOLD: error: validation errors
// NO_FOLD: error: DXIL intrinsic overload must be valid.
// NO_FOLD: note: at '%{{.+}} = call double @dx.op.unary.f64(i32 22, double %{{.+}})' in block '#0' of function 'main'.
float result = fmod(-5.5, b ? 1.5 : 0.5);
results[i++] = float4(result, 0, 0, 0);
#endif // NO_FOLD
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: %dxc -T vs_6_0 %s -E main | %FileCheck %s
// RUN: %dxc -T vs_6_0 %s -E main -DNO_FOLD | %FileCheck %s -check-prefixes=NO_FOLD

// Ensure length is constant evaluated during codegen, or dxil const eval
// TODO: handle fp specials properly!

RWBuffer<float4> results : register(u0);

[shader("vertex")]
void main(bool b : B) {
uint i = 0;

// Literal float
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 0, i32 undef, float 0x3FE6A09E60000000, float 0x4004C8DC20000000, float 0.000000e+00, float 0.000000e+00, i8 15)
results[i++] = float4(length(0.5.xx),
length(-1.5.xxx),
length(0.0.xxxx),
length(-0.0.xxxx));

// Explicit float
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 1, i32 undef, float 0x3FE6A09E60000000, float 0x4004C8DC20000000, float 0.000000e+00, float 0.000000e+00, i8 15)
results[i++] = float4(length(0.5F.xx),
length(-1.5F.xxx),
length(0.0F.xxxx),
length(-0.0F.xxxx));

#ifdef NO_FOLD
// Currently, we rely on constant folding of DXIL ops to get rid of illegal
// double overloads. If this doesn't happen, we expect a validation error.
// Ternary operator can return literal type, while not being foldable due
// non-constant condition.
// NO_FOLD: error: validation errors
// NO_FOLD: error: DXIL intrinsic overload must be valid.
// NO_FOLD: note: at '%{{.+}} = call double @dx.op.unary.f64(i32 24, double %{{.+}})' in block '#0' of function 'main'.
float result = length((b ? 1.5 : 0.5).xxx);
results[i++] = float4(result, 0, 0, 0);
#endif // NO_FOLD
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: %dxc -T vs_6_0 %s -E main | %FileCheck %s
// RUN: %dxc -T vs_6_0 %s -E main -DNO_FOLD | %FileCheck %s -check-prefixes=NO_FOLD

// Ensure normalize is constant evaluated during codegen, or dxil const eval
// TODO: handle fp specials properly!

RWBuffer<float4> results : register(u0);

[shader("vertex")]
void main(bool b : B) {
uint i = 0;

// Literal float
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 0, i32 undef, float 0x3FE6A09E60000000, float 0xBFE279A740000000, float 0x7FF8000000000000, float 0x7FF8000000000000, i8 15)
results[i++] = float4(normalize(0.5.xx).x,
normalize(-1.5.xxx).x,
normalize(0.0.xxxx).x,
normalize(-0.0.xxxx).x);

// Explicit float
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 1, i32 undef, float 0x3FE6A09E60000000, float 0xBFE279A740000000, float 0x7FF8000000000000, float 0x7FF8000000000000, i8 15)
results[i++] = float4(normalize(0.5F.xx).x,
normalize(-1.5F.xxx).x,
normalize(0.0F.xxxx).x,
normalize(-0.0F.xxxx).x);

#ifdef NO_FOLD
// Currently, we rely on constant folding of DXIL ops to get rid of illegal
// double overloads. If this doesn't happen, we expect a validation error.
// Ternary operator can return literal type, while not being foldable due
// non-constant condition.
// NO_FOLD: error: validation errors
// NO_FOLD: error: DXIL intrinsic overload must be valid.
// NO_FOLD: note: at '%{{.+}} = call double @dx.op.dot3.f64(i32 55, double %{{.+}}, double %{{.+}}, double %{{.+}}, double %{{.+}}, double %{{.+}}, double %{{.+}})' in block '#0' of function 'main'.
float result = normalize((b ? 1.5 : 0.5).xxx).x;
results[i++] = float4(result, 0, 0, 0);
#endif // NO_FOLD
}
Loading