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

PIX: Make shader access tracking pass return whether or not it modified anything #7010

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions lib/DxilPIXPasses/DxilShaderAccessTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,9 @@ bool DxilShaderAccessTracking::runOnModule(Module &M) {
// Done with these guys:
m_GEPOperandAsInstructionDestroyers.clear();

if (OSOverride != nullptr && !Modified) {
*OSOverride << "\nNotModified\n";
}
return Modified;
}
char DxilShaderAccessTracking::ID = 0;
Expand Down
80 changes: 74 additions & 6 deletions tools/clang/unittests/HLSL/PixTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class PixTest : public ::testing::Test {
TEST_METHOD(SignatureModification_VertexIdAlready)
TEST_METHOD(SignatureModification_SomethingElseFirst)

TEST_METHOD(AccessTracking_ModificationReport_Nothing)
TEST_METHOD(AccessTracking_ModificationReport_Read)
TEST_METHOD(AccessTracking_ModificationReport_Write)
TEST_METHOD(AccessTracking_ModificationReport_SM66)

TEST_METHOD(PixStructAnnotation_Lib_DualRaygen)
TEST_METHOD(PixStructAnnotation_Lib_RaygenAllocaStructAlignment)

Expand Down Expand Up @@ -348,6 +353,8 @@ class PixTest : public ::testing::Test {
*ppNewShaderOut = pNewContainer.Detach();
}

void ValidateAccessTrackingMods(const char *hlsl, bool modsExpected);

class ModuleAndHangersOn {
std::unique_ptr<llvm::LLVMContext> llvmContext;
std::unique_ptr<llvm::Module> llvmModule;
Expand Down Expand Up @@ -429,7 +436,7 @@ class PixTest : public ::testing::Test {
const wchar_t *profile = L"as_6_5");
void ValidateAllocaWrite(std::vector<AllocaWrite> const &allocaWrites,
size_t index, const char *name);
CComPtr<IDxcBlob> RunShaderAccessTrackingPass(IDxcBlob *blob);
PassOutput RunShaderAccessTrackingPass(IDxcBlob *blob);
std::string RunDxilPIXAddTidToAmplificationShaderPayloadPass(IDxcBlob *blob);
CComPtr<IDxcBlob> RunDxilPIXMeshShaderOutputPass(IDxcBlob *blob);
CComPtr<IDxcBlob> RunDxilPIXDXRInvocationsLog(IDxcBlob *blob);
Expand Down Expand Up @@ -576,13 +583,14 @@ TEST_F(PixTest, CompileDebugDisasmPDB) {
VERIFY_SUCCEEDED(pCompiler->Disassemble(pPdbBlob, &pDisasm));
}

CComPtr<IDxcBlob> PixTest::RunShaderAccessTrackingPass(IDxcBlob *blob) {
PassOutput PixTest::RunShaderAccessTrackingPass(IDxcBlob *blob) {
CComPtr<IDxcOptimizer> pOptimizer;
VERIFY_SUCCEEDED(
m_dllSupport.CreateInstance(CLSID_DxcOptimizer, &pOptimizer));
std::vector<LPCWSTR> Options;
Options.push_back(L"-opt-mod-passes");
Options.push_back(L"-hlsl-dxil-pix-shader-access-instrumentation,config=");
Options.push_back(L"-hlsl-dxil-pix-shader-access-instrumentation,config=U0:0:"
L"10i0;U0:1:2i0;.0;0;0.");
jeffnn marked this conversation as resolved.
Show resolved Hide resolved

CComPtr<IDxcBlob> pOptimizedModule;
CComPtr<IDxcBlobEncoding> pText;
Expand All @@ -604,7 +612,12 @@ CComPtr<IDxcBlob> PixTest::RunShaderAccessTrackingPass(IDxcBlob *blob) {
CComPtr<IDxcBlob> pNewContainer;
VERIFY_SUCCEEDED(pAssembleResult->GetResult(&pNewContainer));

return pNewContainer;
PassOutput ret;
ret.blob = pNewContainer;
std::string outputText = BlobToUtf8(pText);
ret.lines = Tokenize(outputText.c_str(), "\n");

return ret;
}

CComPtr<IDxcBlob> PixTest::RunDxilPIXMeshShaderOutputPass(IDxcBlob *blob) {
Expand Down Expand Up @@ -816,6 +829,61 @@ TEST_F(PixTest, SignatureModification_SomethingElseFirst) {
VERIFY_ARE_EQUAL(sig.GetElement(2).GetStartRow(), 2);
}

void PixTest::ValidateAccessTrackingMods(const char *hlsl, bool modsExpected) {
auto code = Compile(m_dllSupport, hlsl, L"ps_6_6", {L"-Od"}, L"main");
auto result = RunShaderAccessTrackingPass(code).lines;
bool hasMods = true;
for (auto const &line : result)
if (line.find("NotModified") != std::string::npos)
hasMods = false;
VERIFY_ARE_EQUAL(modsExpected, hasMods);
}

TEST_F(PixTest, AccessTracking_ModificationReport_Nothing) {
const char *hlsl = R"(
float main() : SV_Target
{
return 0;
}
)";
ValidateAccessTrackingMods(hlsl, false);
}

TEST_F(PixTest, AccessTracking_ModificationReport_Read) {
const char *hlsl = R"(
RWByteAddressBuffer g_texture;
float main() : SV_Target
{
return g_texture.Load(0);
}
)";
ValidateAccessTrackingMods(hlsl, true);
}

TEST_F(PixTest, AccessTracking_ModificationReport_Write) {
const char *hlsl = R"(
RWByteAddressBuffer g_texture;
float main() : SV_Target
{
g_texture.Store(0, 0);
return 0;
}
)";
ValidateAccessTrackingMods(hlsl, true);
}

TEST_F(PixTest, AccessTracking_ModificationReport_SM66) {
const char *hlsl = R"(
float main() : SV_Target
{
RWByteAddressBuffer g_texture = ResourceDescriptorHeap[0];
g_texture.Store(0, 0);
return 0;
}
)";
ValidateAccessTrackingMods(hlsl, true);
}

TEST_F(PixTest, AddToASGroupSharedPayload) {

const char *hlsl = R"(
Expand Down Expand Up @@ -2720,7 +2788,7 @@ void MyMiss(inout MyPayload payload)
CComPtr<IDxcBlob> compiled;
VERIFY_SUCCEEDED(pResult->GetResult(&compiled));

auto optimizedContainer = RunShaderAccessTrackingPass(compiled);
auto optimizedContainer = RunShaderAccessTrackingPass(compiled).blob;

const char *pBlobContent =
reinterpret_cast<const char *>(optimizedContainer->GetBufferPointer());
Expand Down Expand Up @@ -2790,7 +2858,7 @@ float4 main(int i : A, float j : B) : SV_TARGET
)x";

auto compiled = Compile(m_dllSupport, dynamicTextureAccess, L"ps_6_6");
auto pOptimizedContainer = RunShaderAccessTrackingPass(compiled);
auto pOptimizedContainer = RunShaderAccessTrackingPass(compiled).blob;

const char *pBlobContent =
reinterpret_cast<const char *>(pOptimizedContainer->GetBufferPointer());
Expand Down
Loading