Skip to content

Shader compiler options to save preprocessed and spirv, optimizer upgrade#1051

Open
Fletterio wants to merge 3 commits intomasterfrom
optimizer-improvement
Open

Shader compiler options to save preprocessed and spirv, optimizer upgrade#1051
Fletterio wants to merge 3 commits intomasterfrom
optimizer-improvement

Conversation

@Fletterio
Copy link
Copy Markdown
Contributor

Gives the shader compiler the option of outputting preprocessed and spirv files to a destination file, useful for debugging. Also when passing an optimizer give the option of replacing the default spirv-opt pass entirely (-O0 flag forwarded to DXC) OR to to run after the default optimization passes. Useful for stripping debug info without disabling optimization, for example.

@devshgraphicsprogramming
Copy link
Copy Markdown
Member

@AnastaZIuk this is your territory, bring this to completion

auto newCode = preprocessShader(std::string(code), stage, hlslOptions.preprocessorOptions, dxc_compile_flags, dependencies);
if (newCode.empty()) return nullptr;

if (!options.preprocessedOutputPath.empty())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spvOutputPath is skipped on a cache hit

if (options.readCache)
{
auto found = options.readCache->find_impl(entry, options.preprocessorOptions.includeFinder);
if (found != options.readCache->m_container.end())
{
if (options.writeCache)
{
CCache::SEntry writeEntry = *found;
options.writeCache->insert(std::move(writeEntry));
}
auto shader = found->decompressShader();
if (depfileEnabled && !writeDepfileFromDependencies(found->dependencies))
return nullptr;
return shader;

please cover that

SPreprocessorOptions preprocessorOptions = {};
CCache* readCache = nullptr;
CCache* writeCache = nullptr;
bool optimizerIsExtraPasses = false; // Instead of disabling the default opt passes, run the provided optimization passes at the end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optimizerIsExtraPasses needs to be covered in cache handle

core::smart_refctd_ptr<system::IFile> preprocessedFile;

system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
m_system->deleteFile(options.preprocessedOutputPath);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this deletes the old dump too early, maybe use temp file plus rename

if (spvFile)
{
system::IFile::success_t succ;
spvFile->write(succ, outSpirv->getPointer(), 0, outSpirv->getSize());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think optimize() can return nullptr here, what about some small guard before writing the dump?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants