Skip to content

Commit 7670b16

Browse files
authored
Add/Update HLK tests for IsSpecialFloat Ops (microsoft#7743)
- update HLK test for 16 bit isinf to specify SM6.9 Closes microsoft#7600 - update HLK test for 16 bit isnan to specify SM6.9 Closes microsoft#7601 - update HLK test for 16 bit isfinite to specify SM6.9 Closes microsoft#7602 - add 16 bit HLK test for isnormal which specifies SM6.9 Closes microsoft#7644 - Move 32 bit HLK test for isnormal to use isnormal instead of isnan Closes microsoft#7664
1 parent 396ff28 commit 7670b16

3 files changed

Lines changed: 287 additions & 232 deletions

File tree

tools/clang/unittests/HLSLExec/ExecutionTest.cpp

Lines changed: 79 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ class ExecutionTest {
337337
TEST_METHOD_PROPERTY(L"DataSource",
338338
L"Table:ShaderOpArithTable.xml#UnaryHalfOpTable")
339339
END_TEST_METHOD()
340+
BEGIN_TEST_METHOD(IsSpecialFloatHalfOpTest)
341+
TEST_METHOD_PROPERTY(
342+
L"DataSource", L"Table:ShaderOpArithTable.xml#IsSpecialFloatHalfOpTable")
343+
END_TEST_METHOD()
340344
BEGIN_TEST_METHOD(BinaryHalfOpTest)
341345
TEST_METHOD_PROPERTY(L"DataSource",
342346
L"Table:ShaderOpArithTable.xml#BinaryHalfOpTable")
@@ -452,7 +456,6 @@ class ExecutionTest {
452456

453457
TEST_METHOD(GraphicsRawBufferLdStI16);
454458
TEST_METHOD(GraphicsRawBufferLdStHalf);
455-
TEST_METHOD(IsNormalTest);
456459

457460
BEGIN_TEST_METHOD(PackUnpackTest)
458461
TEST_METHOD_PROPERTY(L"DataSource",
@@ -6478,6 +6481,81 @@ TEST_F(ExecutionTest, UnaryHalfOpTest) {
64786481
}
64796482
}
64806483

6484+
TEST_F(ExecutionTest, IsSpecialFloatHalfOpTest) {
6485+
WEX::TestExecution::SetVerifyOutput verifySettings(
6486+
WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
6487+
CComPtr<IStream> pStream;
6488+
readHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream, m_support);
6489+
6490+
CComPtr<ID3D12Device> pDevice;
6491+
if (!createDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_9)) {
6492+
return;
6493+
}
6494+
6495+
if (!DoesDeviceSupportNative16bitOps(pDevice)) {
6496+
WEX::Logging::Log::Comment(
6497+
L"Device does not support native 16-bit operations.");
6498+
WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
6499+
return;
6500+
}
6501+
6502+
// Read data from the table
6503+
int tableSize = sizeof(UnaryHalfOpParameters) / sizeof(TableParameter);
6504+
TableParameterHandler handler(UnaryHalfOpParameters, tableSize);
6505+
6506+
CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
6507+
CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
6508+
CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
6509+
6510+
std::vector<uint16_t> *Validation_Input =
6511+
&(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
6512+
std::vector<uint16_t> *Validation_Expected =
6513+
&(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
6514+
6515+
LPCWSTR Validation_Type =
6516+
handler.GetTableParamByName(L"Validation.Type")->m_str;
6517+
double Validation_Tolerance =
6518+
handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
6519+
6520+
size_t count = Validation_Input->size();
6521+
6522+
std::shared_ptr<st::ShaderOpTestResult> test = st::RunShaderOpTest(
6523+
pDevice, m_support, pStream, "UnaryFPOp",
6524+
// this callback is called when the test
6525+
// is creating the resource to run the test
6526+
[&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
6527+
VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
6528+
size_t size = sizeof(SUnaryHalfOp) * count;
6529+
Data.resize(size);
6530+
SUnaryHalfOp *pPrimitives = (SUnaryHalfOp *)Data.data();
6531+
for (size_t i = 0; i < count; ++i) {
6532+
SUnaryHalfOp *p = &pPrimitives[i];
6533+
p->input = (*Validation_Input)[i % Validation_Input->size()];
6534+
}
6535+
// use shader from data table
6536+
pShaderOp->Shaders.at(0).Target = Target.m_psz;
6537+
pShaderOp->Shaders.at(0).Text = Text.m_psz;
6538+
pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
6539+
});
6540+
6541+
MappedData data;
6542+
test->Test->GetReadBackData("SUnaryFPOp", &data);
6543+
6544+
SUnaryHalfOp *pPrimitives = (SUnaryHalfOp *)data.data();
6545+
WEX::TestExecution::DisableVerifyExceptions dve;
6546+
for (unsigned i = 0; i < count; ++i) {
6547+
SUnaryHalfOp *p = &pPrimitives[i];
6548+
uint16_t expected = (*Validation_Expected)[i % Validation_Input->size()];
6549+
LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
6550+
L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
6551+
i, ConvertFloat16ToFloat32(p->input), p->input,
6552+
ConvertFloat16ToFloat32(p->output), p->output,
6553+
ConvertFloat16ToFloat32(expected), expected);
6554+
VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type,
6555+
Validation_Tolerance);
6556+
}
6557+
}
6558+
64816559
TEST_F(ExecutionTest, BinaryHalfOpTest) {
64826560
WEX::TestExecution::SetVerifyOutput verifySettings(
64836561
WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
@@ -12553,91 +12631,6 @@ struct FloatInputUintOutput {
1255312631
unsigned int output;
1255412632
};
1255512633

12556-
TEST_F(ExecutionTest, IsNormalTest) {
12557-
WEX::TestExecution::SetVerifyOutput verifySettings(
12558-
WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
12559-
12560-
CComPtr<ID3D12Device> pDevice;
12561-
VERIFY_IS_TRUE(createDevice(&pDevice, D3D_SHADER_MODEL_6_0,
12562-
false /* skipUnsupported */));
12563-
12564-
// The input is -Zero, Zero, -Denormal, Denormal, -Infinity, Infinity, -NaN,
12565-
// Nan, and then 4 normal float numbers. Only the last 4 floats are normal, so
12566-
// we expect the first 8 results to be 0, and the last 4 to be 1, as defined
12567-
// by IsNormal.
12568-
std::vector<float> Validation_Input_Vec = {
12569-
-0.0, 0.0, -(FLT_MIN / 2), FLT_MIN / 2, -(INFINITY), INFINITY,
12570-
-(NAN), NAN, 530.99f, -530.99f, -122.900f, .122900f};
12571-
std::vector<float> *Validation_Input = &Validation_Input_Vec;
12572-
12573-
std::vector<unsigned int> Validation_Expected_Vec = {0u, 0u, 0u, 0u, 0u, 0u,
12574-
0u, 0u, 1u, 1u, 1u, 1u};
12575-
std::vector<unsigned int> *Validation_Expected = &Validation_Expected_Vec;
12576-
12577-
CComPtr<IStream> pStream;
12578-
readHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream, m_support);
12579-
12580-
std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
12581-
std::make_shared<st::ShaderOpSet>();
12582-
st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
12583-
st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("IsNormal");
12584-
12585-
D3D_SHADER_MODEL sm = D3D_SHADER_MODEL_6_0;
12586-
LogCommentFmt(L"\r\nVerifying isNormal in shader "
12587-
L"model 6.%1u",
12588-
((UINT)sm & 0x0f));
12589-
12590-
size_t count = Validation_Input->size();
12591-
12592-
auto ShaderInitFn = MakeShaderReplacementCallback(
12593-
{L"isSpecialFloat.hlsl", L"-Emain", L"-Tcs_6_0"},
12594-
// Replace the above with what's below when IsSpecialFloat supports
12595-
// doubles
12596-
//{ "@dx.op.isSpecialFloat.f32(i32 8,", "@dx.op.isSpecialFloat.f64(i32
12597-
// 8," }, { "@dx.op.isSpecialFloat.f32(i32 11,",
12598-
//"@dx.op.isSpecialFloat.f64(i32 11," },
12599-
{"@dx.op.isSpecialFloat.f32(i32 8,"},
12600-
{"@dx.op.isSpecialFloat.f32(i32 11,"}, m_support);
12601-
12602-
auto ResourceInitFn = [&](LPCSTR Name, std::vector<BYTE> &Data,
12603-
st::ShaderOp *pShaderOp) {
12604-
UNREFERENCED_PARAMETER(pShaderOp);
12605-
VERIFY_IS_TRUE(0 == _stricmp(Name, "g_TestData"));
12606-
size_t size = sizeof(FloatInputUintOutput) * count;
12607-
Data.resize(size);
12608-
FloatInputUintOutput *pPrimitives = (FloatInputUintOutput *)Data.data();
12609-
for (size_t i = 0; i < count; ++i) {
12610-
FloatInputUintOutput *p = &pPrimitives[i];
12611-
float inputFloat = (*Validation_Input)[i % Validation_Input->size()];
12612-
p->input = inputFloat;
12613-
}
12614-
};
12615-
12616-
// Test Compute shader
12617-
{
12618-
pShaderOp->CS = pShaderOp->GetString("CS60");
12619-
std::shared_ptr<st::ShaderOpTestResult> test =
12620-
st::RunShaderOpTestAfterParse(pDevice, m_support, "IsNormal",
12621-
ResourceInitFn, ShaderInitFn,
12622-
ShaderOpSet);
12623-
12624-
MappedData data;
12625-
test->Test->GetReadBackData("g_TestData", &data);
12626-
12627-
FloatInputUintOutput *pPrimitives = (FloatInputUintOutput *)data.data();
12628-
WEX::TestExecution::DisableVerifyExceptions dve;
12629-
for (unsigned i = 0; i < count; ++i) {
12630-
FloatInputUintOutput *p = &pPrimitives[i];
12631-
unsigned int val =
12632-
(*Validation_Expected)[i % Validation_Expected->size()];
12633-
LogCommentFmt(
12634-
L"element #%u, input = %6.8f, output = %6.8f, expected = %d", i,
12635-
p->input, p->output, val);
12636-
VERIFY_ARE_EQUAL(p->output, val);
12637-
}
12638-
}
12639-
}
12640-
1264112634
#ifndef _HLK_CONF
1264212635
static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest,
1264312636
char **pReadBackDump) {

tools/clang/unittests/HLSLExec/ShaderOpArith.xml

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3717,39 +3717,6 @@ void MSMain(uint GID : SV_GroupIndex,
37173717
</Shader>
37183718
</ShaderOp>
37193719

3720-
<ShaderOp Name="IsNormal" CS="CS60">
3721-
<Resource Name="g_TestData" Dimension="BUFFER" Width="96" InitialResourceState="COPY_DEST" Init="ByName" Flags="ALLOW_UNORDERED_ACCESS" ReadBack="true" TransitionTo="UNORDERED_ACCESS" />
3722-
3723-
<DescriptorHeap Name="ResourceDescriptorHeap" Type="CBV_SRV_UAV">
3724-
<Descriptor Name="g_TestData" NumElements="12" Kind="UAV" StructureByteStride="8"/>
3725-
</DescriptorHeap>
3726-
3727-
<RootValues>
3728-
<RootValue HeapName="ResourceDescriptorHeap" Index="0" />
3729-
</RootValues>
3730-
3731-
<Shader Name="CS60" Target="cs_6_0" EntryPoint="main" Text="@MAIN" Callback="True"/>
3732-
<Shader Name="MAIN" Target="cs_6_0" EntryPoint="main">
3733-
<![CDATA[
3734-
struct TestPoint{
3735-
float input;
3736-
uint output;
3737-
};
3738-
3739-
// Result buffers
3740-
RWStructuredBuffer <TestPoint> g_TestData : register(u0);
3741-
3742-
[RootSignature("RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), DescriptorTable( UAV(u0, numDescriptors=1))")]
3743-
[NumThreads(12, 1, 1)]
3744-
void main(uint ix : SV_GroupIndex)
3745-
{
3746-
g_TestData[ix].output = isnan(g_TestData[ix].input);
3747-
}
3748-
3749-
]]>
3750-
</Shader>
3751-
</ShaderOp>
3752-
37533720
<ShaderOp Name="LongVectorOp" CS="CS">
37543721
<RootSignature>RootFlags(0), UAV(u0), UAV(u1), UAV(u2),
37553722
UAV(u3)</RootSignature>

0 commit comments

Comments
 (0)