@@ -3059,7 +3059,40 @@ TEST_F(ExecutionTest, PartialDerivTest) {
30593059 VerifyDerivResults (pPixels, offsetCenter);
30603060}
30613061
3062+ struct Dispatch {
3063+ int width, height, depth;
3064+ };
3065+
3066+ std::shared_ptr<st::ShaderOpTest>
3067+ RunDispatch (ID3D12Device *pDevice, dxc::DxcDllSupport &support,
3068+ st::ShaderOp *pShaderOp, const Dispatch D) {
3069+ char compilerOptions[256 ];
3070+
3071+ std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
3072+ test->SetDxcSupport (&support);
3073+ test->SetInitCallback (nullptr );
3074+ test->SetDevice (pDevice);
3075+
3076+ // format compiler args
3077+ VERIFY_IS_TRUE (sprintf_s (compilerOptions, sizeof (compilerOptions),
3078+ " -D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d " ,
3079+ D.width , D.height , D.depth ));
3080+
3081+ for (st::ShaderOpShader &S : pShaderOp->Shaders )
3082+ S.Arguments = compilerOptions;
3083+
3084+ pShaderOp->DispatchX = D.width ;
3085+ pShaderOp->DispatchY = D.height ;
3086+ pShaderOp->DispatchZ = D.depth ;
3087+
3088+ test->RunShaderOp (pShaderOp);
3089+
3090+ return test;
3091+ }
3092+
30623093TEST_F (ExecutionTest, DerivativesTest) {
3094+ const UINT pixelSize = 4 ; // always float4
3095+
30633096 WEX::TestExecution::SetVerifyOutput verifySettings (WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
30643097 CComPtr<IStream> pStream;
30653098 ReadHlslDataIntoNewStream (L" ShaderOpArith.xml" , &pStream);
@@ -3074,99 +3107,97 @@ TEST_F(ExecutionTest, DerivativesTest) {
30743107
30753108 st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp (" Derivatives" );
30763109
3077- LPCSTR CS = pShaderOp->CS ;
3078-
3079- struct Dispatch {
3080- int x, y, z;
3081- int mx, my, mz;
3082- };
30833110 std::vector<Dispatch> dispatches =
30843111 {
3085- {32 , 32 , 1 , 8 , 8 , 1 },
3086- {64 , 4 , 1 , 64 , 2 , 1 },
3087- {1 , 4 , 64 , 1 , 4 , 32 },
3088- {64 , 1 , 1 , 64 , 1 , 1 },
3089- {1 , 64 , 1 , 1 , 64 , 1 },
3090- {1 , 1 , 64 , 1 , 1 , 64 },
3091- {16 , 16 , 3 , 4 , 4 , 3 },
3092- {32 , 3 , 8 , 8 , 3 , 2 },
3093- {3 , 1 , 64 , 3 , 1 , 32 }
3112+ {40 , 1 , 1 },
3113+ {1000 , 1 , 1 },
3114+ {32 , 32 , 1 },
3115+ {16 , 64 , 1 },
3116+ {4 , 12 , 4 },
3117+ {4 , 64 , 1 },
3118+ {16 , 16 , 3 },
3119+ {32 , 8 , 2 }
30943120 };
30953121
3096- char compilerOptions[256 ];
3097- for (Dispatch &D : dispatches) {
3098-
3099- UINT width = D.x ;
3100- UINT height = D.y ;
3101- UINT depth = D.z ;
3102-
3103- UINT mwidth = D.mx ;
3104- UINT mheight = D.my ;
3105- UINT mdepth = D.mz ;
3106- UINT pixelSize = 4 ; // always float4
3122+ std::vector<Dispatch> meshDispatches =
3123+ {
3124+ {60 , 1 , 1 },
3125+ {128 , 1 , 1 },
3126+ {8 , 8 , 1 },
3127+ {32 , 8 , 1 },
3128+ {8 , 16 , 4 },
3129+ {8 , 64 , 1 },
3130+ {8 , 8 , 3 },
3131+ };
31073132
3108- // format compiler args
3109- VERIFY_IS_TRUE (sprintf_s (compilerOptions, sizeof (compilerOptions),
3110- " -D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
3111- " -D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d" ,
3112- width, height, depth, mwidth, mheight, mdepth));
3133+ std::vector<Dispatch> badDispatches =
3134+ {
3135+ {16 , 3 , 1 },
3136+ {2 , 16 , 1 },
3137+ {33 , 1 , 1 }
3138+ };
31133139
3114- for (st::ShaderOpShader &S : pShaderOp->Shaders )
3115- S. Arguments = compilerOptions ;
3140+ pShaderOp->UseWarpDevice = GetTestParamUseWARP ( true );
3141+ LPCSTR CS = pShaderOp-> CS ;
31163142
3117- pShaderOp->DispatchX = width;
3118- pShaderOp->DispatchY = height;
3119- pShaderOp->DispatchZ = depth;
3143+ MappedData data;
31203144
3145+ for (Dispatch &D : dispatches) {
31213146 // Test Compute Shader
3122- pShaderOp->CS = CS;
3123- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse (pDevice, m_support, " Derivatives" , nullptr , ShaderOpSet);
3124- MappedData data;
3147+ std::shared_ptr<st::ShaderOpTest> test = RunDispatch (pDevice, m_support, pShaderOp, D);
31253148
3126- test->Test ->GetReadBackData (" U0" , &data);
3127- const float *pPixels = (float *)data.data ();
3149+ test->GetReadBackData (" U0" , &data);
3150+
3151+ float *pPixels = (float *)data.data ();;
31283152
3129- // To find roughly the center for compute, divide the pixel count in half,
3130- // truncate to next lowest power of 16 (4x4), which is the repeating period
3131- // and then add 10 to reach the point the test expects
3132- UINT centerIndex = (((UINT64)(width * height * depth)/2 ) & ~0xF ) + 10 ;
3153+ UINT centerIndex = 0 ;
3154+ if (D.height == 1 ) {
3155+ centerIndex = (((UINT64)(D.width * D.height * D.depth ) / 2 ) & ~0xF ) + 10 ;
3156+ } else {
3157+ // To find roughly the center for compute, divide the height and width in half,
3158+ // truncate to the previous multiple of 4 to get to the start of the repeating pattern
3159+ // and then add 2 rows to get to the second row of quads and 2 to get to the first texel
3160+ // of the second row of that quad row
3161+ UINT centerRow = ((D.height /2UL ) & ~0x3 ) + 2 ;
3162+ UINT centerCol = ((D.width /2UL ) & ~0x3 ) + 2 ;
3163+ centerIndex = centerRow * D.width + centerCol;
3164+ }
31333165 UINT offsetCenter = centerIndex * pixelSize;
31343166 LogCommentFmt (L" Verifying derivatives in compute shader results" );
31353167 VerifyDerivResults (pPixels, offsetCenter);
3168+ }
31363169
3137- if (DoesDeviceSupportMeshAmpDerivatives (pDevice)) {
3138- // Disable CS so mesh goes forward
3139- pShaderOp->CS = nullptr ;
3140- test = RunShaderOpTestAfterParse (pDevice, m_support, " Derivatives" , nullptr , ShaderOpSet);
3141- test->Test ->GetReadBackData (" U1" , &data);
3142- pPixels = (float *)data.data ();
3143- centerIndex = (((UINT64)(mwidth * mheight * mdepth)/2 ) & ~0xF ) + 10 ;
3144- offsetCenter = centerIndex * pixelSize;
3170+ if (DoesDeviceSupportMeshAmpDerivatives (pDevice)) {
3171+ // Disable CS so mesh goes forward
3172+ pShaderOp->CS = nullptr ;
3173+
3174+ for (Dispatch &D : meshDispatches) {
3175+ std::shared_ptr<st::ShaderOpTest> test = RunDispatch (pDevice, m_support, pShaderOp, D);
3176+
3177+ test->GetReadBackData (" U1" , &data);
3178+ const float *pPixels = (float *)data.data ();
3179+ UINT centerIndex = (((UINT64)(D.width * D.height * D.depth )/2 ) & ~0xF ) + 10 ;
3180+ UINT offsetCenter = centerIndex * pixelSize;
31453181 LogCommentFmt (L" Verifying derivatives in mesh shader results" );
31463182 VerifyDerivResults (pPixels, offsetCenter);
31473183
3148- test->Test -> GetReadBackData (" U2" , &data);
3184+ test->GetReadBackData (" U2" , &data);
31493185 pPixels = (float *)data.data ();
31503186 LogCommentFmt (L" Verifying derivatives in amplification shader results" );
31513187 VerifyDerivResults (pPixels, offsetCenter);
31523188 }
31533189 }
31543190
3155- // Final test with not divisible by 4 dispatch size just to make sure it runs
3156- for (st::ShaderOpShader &S : pShaderOp->Shaders )
3157- S.Arguments = " -D DISPATCHX=3 -D DISPATCHY=3 -D DISPATCHZ=3 "
3158- " -D MESHDISPATCHX=3 -D MESHDISPATCHY=3 -D MESHDISPATCHZ=3" ;
3159-
3160- pShaderOp->DispatchX = 3 ;
3161- pShaderOp->DispatchY = 3 ;
3162- pShaderOp->DispatchZ = 3 ;
3191+ // Final tests with invalid dispatch size just to make sure they run
3192+ for (Dispatch &D : badDispatches) {
3193+ // Test Compute Shader
3194+ pShaderOp->CS = CS;
3195+ std::shared_ptr<st::ShaderOpTest> test = RunDispatch (pDevice, m_support, pShaderOp, D);
31633196
3164- // Test Compute Shader
3165- pShaderOp->CS = CS;
3166- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse (pDevice, m_support, " Derivatives" , nullptr , ShaderOpSet);
3167- if (DoesDeviceSupportMeshAmpDerivatives (pDevice)) {
3168- pShaderOp->CS = nullptr ;
3169- test = RunShaderOpTestAfterParse (pDevice, m_support, " Derivatives" , nullptr , ShaderOpSet);
3197+ if (DoesDeviceSupportMeshAmpDerivatives (pDevice)) {
3198+ pShaderOp->CS = nullptr ;
3199+ test = RunDispatch (pDevice, m_support, pShaderOp, D);
3200+ }
31703201 }
31713202}
31723203
0 commit comments