2017-10-16 17:50:09 +02:00
|
|
|
#include "dxbc_compiler.h"
|
|
|
|
#include "dxbc_module.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
DxbcModule::DxbcModule(DxbcReader& reader)
|
|
|
|
: m_header(reader) {
|
|
|
|
for (uint32_t i = 0; i < m_header.numChunks(); i++) {
|
|
|
|
|
|
|
|
// The chunk tag is stored at the beginning of each chunk
|
|
|
|
auto chunkReader = reader.clone(m_header.chunkOffset(i));
|
|
|
|
auto tag = chunkReader.readTag();
|
|
|
|
|
|
|
|
// The chunk size follows right after the four-character
|
|
|
|
// code. This does not include the eight bytes that are
|
|
|
|
// consumed by the FourCC and chunk length entry.
|
2017-11-01 00:01:40 +01:00
|
|
|
auto chunkLength = chunkReader.readu32();
|
|
|
|
|
|
|
|
chunkReader = chunkReader.clone(8);
|
|
|
|
chunkReader = chunkReader.resize(chunkLength);
|
2017-10-16 17:50:09 +02:00
|
|
|
|
|
|
|
if ((tag == "SHDR") || (tag == "SHEX"))
|
|
|
|
m_shexChunk = new DxbcShex(chunkReader);
|
|
|
|
|
2017-11-01 00:01:40 +01:00
|
|
|
if ((tag == "ISGN"))
|
|
|
|
m_isgnChunk = new DxbcIsgn(chunkReader);
|
|
|
|
|
|
|
|
if ((tag == "OSGN"))
|
|
|
|
m_osgnChunk = new DxbcIsgn(chunkReader);
|
|
|
|
|
|
|
|
// if ((tag == "OSG5"))
|
|
|
|
// m_osgnChunk = new DxbcIsgn(chunkReader);
|
|
|
|
|
2017-10-16 17:50:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DxbcModule::~DxbcModule() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-08 18:14:05 +01:00
|
|
|
Rc<DxvkShader> DxbcModule::compile() const {
|
2017-10-16 17:50:09 +02:00
|
|
|
if (m_shexChunk == nullptr)
|
|
|
|
throw DxvkError("DxbcModule::compile: No SHDR/SHEX chunk");
|
|
|
|
|
2017-12-14 12:53:53 +01:00
|
|
|
DxbcCompiler compiler(
|
2017-12-07 16:29:34 +01:00
|
|
|
m_shexChunk->version(),
|
|
|
|
m_isgnChunk, m_osgnChunk);
|
|
|
|
|
2017-12-13 15:32:54 +01:00
|
|
|
for (auto ins : *m_shexChunk) {
|
|
|
|
const DxbcError error = compiler.processInstruction(ins);
|
|
|
|
|
|
|
|
if (error != DxbcError::sOk) {
|
|
|
|
Logger::err(str::format(
|
|
|
|
"dxbc: Error while processing ",
|
|
|
|
ins.token().opcode(), ": Error ",
|
|
|
|
static_cast<uint32_t>(error)));
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:14:05 +01:00
|
|
|
|
2017-10-16 17:50:09 +02:00
|
|
|
return compiler.finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|