1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-14 09:23:53 +01:00
dxvk/src/dxbc/dxbc_module.cpp
Philip Rebohle 858913ec0c [dxbc] Shader decoder and compiler overhaul (2/2)
Removed the old decoder and the old shader compiler
and added documentation to the new structures.
2017-12-18 00:46:44 +01:00

65 lines
1.6 KiB
C++

#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.
auto chunkLength = chunkReader.readu32();
chunkReader = chunkReader.clone(8);
chunkReader = chunkReader.resize(chunkLength);
if ((tag == "SHDR") || (tag == "SHEX"))
m_shexChunk = new DxbcShex(chunkReader);
if ((tag == "ISGN"))
m_isgnChunk = new DxbcIsgn(chunkReader);
if ((tag == "OSGN"))
m_osgnChunk = new DxbcIsgn(chunkReader);
// if ((tag == "OSG5"))
// m_osgnChunk = new DxbcIsgn(chunkReader);
}
}
DxbcModule::~DxbcModule() {
}
Rc<DxvkShader> DxbcModule::compile() const {
if (m_shexChunk == nullptr)
throw DxvkError("DxbcModule::compile: No SHDR/SHEX chunk");
DxbcCodeSlice slice = m_shexChunk->slice();
DxbcCompiler compiler(
m_shexChunk->version(),
m_isgnChunk, m_osgnChunk);
DxbcDecodeContext decoder;
while (!slice.atEnd()) {
decoder.decodeInstruction(slice);
compiler.processInstruction(
decoder.getInstruction());
}
return compiler.finalize();
}
}