[dxbc] Write shader name to the generated SPIR-V

Might help identifying shaders in debugging tools such as Renderdoc.
This commit is contained in:
Philip Rebohle 2018-04-15 21:00:08 +02:00
parent 08777e2c0e
commit 98b8d41016
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
8 changed files with 57 additions and 7 deletions

View File

@ -68,7 +68,7 @@ namespace dxvk {
std::ios_base::binary | std::ios_base::trunc));
}
m_shader = module.compile(*pDxbcOptions);
m_shader = module.compile(*pDxbcOptions, m_name);
m_shader->setDebugName(m_name);
if (dumpPath.size() != 0) {

View File

@ -9,6 +9,7 @@ namespace dxvk {
constexpr uint32_t PushConstant_InstanceId = 0;
DxbcCompiler::DxbcCompiler(
const std::string& fileName,
const DxbcOptions& options,
const DxbcProgramVersion& version,
const Rc<DxbcIsgn>& isgn,
@ -23,6 +24,12 @@ namespace dxvk {
// initialization phase where the execution mode is set.
m_entryPointId = m_module.allocateId();
// Set the shader name so that we recognize it in renderdoc
m_module.setDebugSource(
spv::SourceLanguageUnknown, 0,
m_module.addDebugString(fileName.c_str()),
"");
// Set the memory model. This is the same for all shaders.
m_module.setMemoryModel(
spv::AddressingModelLogical,

View File

@ -311,6 +311,7 @@ namespace dxvk {
public:
DxbcCompiler(
const std::string& fileName,
const DxbcOptions& options,
const DxbcProgramVersion& version,
const Rc<DxbcIsgn>& isgn,

View File

@ -41,7 +41,9 @@ namespace dxvk {
}
Rc<DxvkShader> DxbcModule::compile(const DxbcOptions& options) const {
Rc<DxvkShader> DxbcModule::compile(
const DxbcOptions& options,
const std::string& fileName) const {
if (m_shexChunk == nullptr)
throw DxvkError("DxbcModule::compile: No SHDR/SHEX chunk");
@ -52,7 +54,8 @@ namespace dxvk {
m_isgnChunk, m_osgnChunk,
analysisInfo);
DxbcCompiler compiler(options,
DxbcCompiler compiler(
fileName, options,
m_shexChunk->version(),
m_isgnChunk, m_osgnChunk,
analysisInfo);

View File

@ -52,13 +52,17 @@ namespace dxvk {
* \brief Compiles DXBC shader to SPIR-V module
*
* \param [in] options DXBC compiler options
* \param [in] fileName File name, will be added to
* the compiled SPIR-V for debugging purposes.
* \returns The compiled shader object
*/
Rc<DxvkShader> compile(const DxbcOptions& options) const;
Rc<DxvkShader> compile(
const DxbcOptions& options,
const std::string& fileName) const;
private:
DxbcHeader m_header;
DxbcHeader m_header;
Rc<DxbcIsgn> m_isgnChunk;
Rc<DxbcIsgn> m_osgnChunk;

View File

@ -116,6 +116,31 @@ namespace dxvk {
}
uint32_t SpirvModule::addDebugString(
const char* string) {
uint32_t resultId = this->allocateId();
m_debugNames.putIns (spv::OpString,
2 + m_debugNames.strLen(string));
m_debugNames.putWord(resultId);
m_debugNames.putStr (string);
return resultId;
}
void SpirvModule::setDebugSource(
spv::SourceLanguage language,
uint32_t version,
uint32_t file,
const char* source) {
m_debugNames.putIns (spv::OpSource,
4 + m_debugNames.strLen(source));
m_debugNames.putWord(language);
m_debugNames.putWord(version);
m_debugNames.putWord(file);
m_debugNames.putStr (source);
}
void SpirvModule::setDebugName(
uint32_t expressionId,
const char* debugName) {

View File

@ -89,6 +89,15 @@ namespace dxvk {
uint32_t entryPointId,
uint32_t vertexCount);
uint32_t addDebugString(
const char* string);
void setDebugSource(
spv::SourceLanguage language,
uint32_t version,
uint32_t file,
const char* source);
void setDebugName(
uint32_t expressionId,
const char* debugName);

View File

@ -28,7 +28,8 @@ int WINAPI WinMain(HINSTANCE hInstance,
}
try {
std::ifstream ifile(str::fromws(argv[1]), std::ios::binary);
std::string ifileName = str::fromws(argv[1]);
std::ifstream ifile(ifileName, std::ios::binary);
ifile.ignore(std::numeric_limits<std::streamsize>::max());
std::streamsize length = ifile.gcount();
ifile.clear();
@ -40,7 +41,7 @@ int WINAPI WinMain(HINSTANCE hInstance,
DxbcReader reader(dxbcCode.data(), dxbcCode.size());
DxbcModule module(reader);
Rc<DxvkShader> shader = module.compile(DxbcOptions());
Rc<DxvkShader> shader = module.compile(DxbcOptions(), ifileName);
std::ofstream ofile(str::fromws(argv[2]), std::ios::binary);
shader->dump(ofile);
return 0;