[spirv] Moved SPIR-V-specific stuff to separate directory

This commit is contained in:
Philip Rebohle 2017-10-18 10:36:47 +02:00
parent 72a87093c5
commit 1bf05d3687
27 changed files with 164 additions and 161 deletions

View File

@ -1,25 +0,0 @@
#include "dxbc_capability.h"
namespace dxvk {
DxbcCapabilities:: DxbcCapabilities() { }
DxbcCapabilities::~DxbcCapabilities() { }
DxvkSpirvCodeBuffer DxbcCapabilities::code() const {
DxvkSpirvCodeBuffer code;
for (auto cap : m_caps) {
code.putIns (spv::OpCapability, 2);
code.putWord(cap);
}
return code;
}
void DxbcCapabilities::enable(spv::Capability cap) {
m_caps.insert(cap);
}
}

View File

@ -21,7 +21,7 @@ namespace dxvk {
Rc<DxvkShader> DxbcCompiler::finalize() {
DxvkSpirvCodeBuffer codeBuffer;
SpirvCodeBuffer codeBuffer;
codeBuffer.putHeader(m_counter.numIds());
codeBuffer.append(m_spvCapabilities.code());
codeBuffer.append(m_spvEntryPoints.code());

View File

@ -1,9 +1,10 @@
#pragma once
#include "dxbc_capability.h"
#include "dxbc_chunk_shex.h"
#include "dxbc_entrypoint.h"
#include "dxbc_typeinfo.h"
#include "../spirv/gen/spirv_gen_capability.h"
#include "../spirv/gen/spirv_gen_entrypoint.h"
#include "../spirv/gen/spirv_gen_typeinfo.h"
namespace dxvk {
@ -36,12 +37,12 @@ namespace dxvk {
private:
DxbcProgramVersion m_version;
DxvkSpirvIdCounter m_counter;
SpirvIdCounter m_counter;
DxbcCapabilities m_spvCapabilities;
DxbcEntryPoint m_spvEntryPoints;
DxbcTypeInfo m_spvTypeInfo;
DxvkSpirvCodeBuffer m_spvCode;
SpirvCapabilities m_spvCapabilities;
SpirvEntryPoint m_spvEntryPoints;
SpirvTypeInfo m_spvTypeInfo;
SpirvCodeBuffer m_spvCode;
void declareCapabilities();
void declareMemoryModel();

View File

@ -1,14 +1,10 @@
dxbc_src = files([
'dxbc_annotation.cpp',
'dxbc_capability.cpp',
'dxbc_chunk_shex.cpp',
'dxbc_common.cpp',
'dxbc_compiler.cpp',
'dxbc_entrypoint.cpp',
'dxbc_header.cpp',
'dxbc_module.cpp',
'dxbc_reader.cpp',
'dxbc_typeinfo.cpp',
])
dxbc_lib = static_library('dxbc', dxbc_src,

View File

@ -39,7 +39,7 @@ namespace dxvk {
throw DxvkError("DxvkComputePipeline::DxvkComputePipeline: Failed to create pipeline layout");
}
DxvkSpirvCodeBuffer code = shader->code(0);
SpirvCodeBuffer code = shader->code(0);
VkShaderModuleCreateInfo minfo;
minfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;

View File

@ -4,7 +4,7 @@ namespace dxvk {
DxvkShader::DxvkShader(
VkShaderStageFlagBits stage,
DxvkSpirvCodeBuffer&& code,
SpirvCodeBuffer&& code,
uint32_t numResourceSlots,
const DxvkResourceSlot* resourceSlots)
: m_stage (stage),
@ -21,7 +21,7 @@ namespace dxvk {
}
DxvkSpirvCodeBuffer DxvkShader::code(
SpirvCodeBuffer DxvkShader::code(
uint32_t bindingOffset) const {
// TODO implement properly
if (bindingOffset != 0)

View File

@ -5,7 +5,6 @@
#include "dxvk_include.h"
#include "../spirv/spirv_code_buffer.h"
#include "../spirv/spirv_id_counter.h"
namespace dxvk {
@ -61,7 +60,7 @@ namespace dxvk {
DxvkShader(
VkShaderStageFlagBits stage,
DxvkSpirvCodeBuffer&& code,
SpirvCodeBuffer&& code,
uint32_t numResourceSlots,
const DxvkResourceSlot* resourceSlots);
~DxvkShader();
@ -76,7 +75,7 @@ namespace dxvk {
* \param [in] bindingOffset First binding ID
* \returns Modified code buffer
*/
DxvkSpirvCodeBuffer code(
SpirvCodeBuffer code(
uint32_t bindingOffset) const;
/**
@ -114,7 +113,7 @@ namespace dxvk {
private:
VkShaderStageFlagBits m_stage;
DxvkSpirvCodeBuffer m_code;
SpirvCodeBuffer m_code;
std::vector<DxvkResourceSlot> m_slots;

View File

@ -0,0 +1,26 @@
#include "spirv_gen_capability.h"
namespace dxvk {
SpirvCapabilities:: SpirvCapabilities() { }
SpirvCapabilities::~SpirvCapabilities() { }
SpirvCodeBuffer SpirvCapabilities::code() const {
return m_code;
}
void SpirvCapabilities::enable(spv::Capability cap) {
// Scan the generated instructions to check
// whether we already enabled the capability.
for (auto ins : m_code) {
if (ins.opCode() == spv::OpCapability && ins.arg(1) == cap)
return;
}
m_code.putIns (spv::OpCapability, 2);
m_code.putWord(cap);
}
}

View File

@ -1,8 +1,6 @@
#pragma once
#include <unordered_set>
#include "dxbc_include.h"
#include "../spirv_code_buffer.h"
namespace dxvk {
@ -12,12 +10,12 @@ namespace dxvk {
* Holds a code buffer solely for the \c OpCapability
* instructions in the generated SPIR-V shader module.
*/
class DxbcCapabilities {
class SpirvCapabilities {
public:
DxbcCapabilities();
~DxbcCapabilities();
SpirvCapabilities();
~SpirvCapabilities();
/**
* \brief Code buffer
@ -26,7 +24,7 @@ namespace dxvk {
* \c OpCapability instructions.
* \returns Code buffer
*/
DxvkSpirvCodeBuffer code() const;
SpirvCodeBuffer code() const;
/**
* \brief Enables a capability
@ -40,7 +38,7 @@ namespace dxvk {
private:
std::unordered_set<spv::Capability> m_caps;
SpirvCodeBuffer m_code;
};

View File

View File

View File

View File

View File

@ -1,13 +1,13 @@
#include "dxbc_entrypoint.h"
#include "spirv_gen_entrypoint.h"
namespace dxvk {
DxbcEntryPoint:: DxbcEntryPoint() { }
DxbcEntryPoint::~DxbcEntryPoint() { }
SpirvEntryPoint:: SpirvEntryPoint() { }
SpirvEntryPoint::~SpirvEntryPoint() { }
DxvkSpirvCodeBuffer DxbcEntryPoint::code() const {
DxvkSpirvCodeBuffer code;
SpirvCodeBuffer SpirvEntryPoint::code() const {
SpirvCodeBuffer code;
code.append(m_memoryModel);
code.append(m_entryPoints);
code.append(m_execModeInfo);
@ -15,7 +15,7 @@ namespace dxvk {
}
void DxbcEntryPoint::setMemoryModel(
void SpirvEntryPoint::setMemoryModel(
spv::AddressingModel addressModel,
spv::MemoryModel memoryModel) {
m_memoryModel.putIns (spv::OpMemoryModel, 3);
@ -24,7 +24,7 @@ namespace dxvk {
}
void DxbcEntryPoint::addEntryPoint(
void SpirvEntryPoint::addEntryPoint(
uint32_t functionId,
spv::ExecutionModel execModel,
const char* name,
@ -40,7 +40,7 @@ namespace dxvk {
}
void DxbcEntryPoint::setLocalSize(
void SpirvEntryPoint::setLocalSize(
uint32_t functionId,
uint32_t x,
uint32_t y,

View File

@ -1,6 +1,6 @@
#pragma once
#include "dxbc_include.h"
#include "../spirv_code_buffer.h"
namespace dxvk {
@ -11,18 +11,18 @@ namespace dxvk {
* point of the generated shader module,
* including execution mode info.
*/
class DxbcEntryPoint {
class SpirvEntryPoint {
public:
DxbcEntryPoint();
~DxbcEntryPoint();
SpirvEntryPoint();
~SpirvEntryPoint();
/**
* \brief Generates SPIR-V code
* \returns SPIR-V code buffer
*/
DxvkSpirvCodeBuffer code() const;
SpirvCodeBuffer code() const;
/**
* \brief Sets memory model
@ -73,9 +73,9 @@ namespace dxvk {
private:
DxvkSpirvCodeBuffer m_memoryModel;
DxvkSpirvCodeBuffer m_entryPoints;
DxvkSpirvCodeBuffer m_execModeInfo;
SpirvCodeBuffer m_memoryModel;
SpirvCodeBuffer m_entryPoints;
SpirvCodeBuffer m_execModeInfo;
};

View File

@ -1,6 +1,6 @@
#pragma once
#include "spirv_include.h"
#include "../spirv_include.h"
namespace dxvk {
@ -11,7 +11,7 @@ namespace dxvk {
* to be used to allocate unique IDs during code
* generation.
*/
class DxvkSpirvIdCounter {
class SpirvIdCounter {
public:

View File

@ -1,32 +1,32 @@
#include "dxbc_typeinfo.h"
#include <array>
#include "spirv_gen_typeinfo.h"
namespace dxvk {
DxbcTypeInfo:: DxbcTypeInfo() { }
DxbcTypeInfo::~DxbcTypeInfo() { }
SpirvTypeInfo:: SpirvTypeInfo() { }
SpirvTypeInfo::~SpirvTypeInfo() { }
DxvkSpirvCodeBuffer DxbcTypeInfo::code() const {
SpirvCodeBuffer SpirvTypeInfo::code() const {
return m_code;
}
uint32_t DxbcTypeInfo::typeVoid(
DxvkSpirvIdCounter& ids) {
uint32_t SpirvTypeInfo::typeVoid(SpirvIdCounter& ids) {
return this->getTypeId(ids,
spv::OpTypeVoid, 0, nullptr);
}
uint32_t DxbcTypeInfo::typeBool(
DxvkSpirvIdCounter& ids) {
uint32_t SpirvTypeInfo::typeBool(SpirvIdCounter& ids) {
return this->getTypeId(ids,
spv::OpTypeBool, 0, nullptr);
}
uint32_t DxbcTypeInfo::typeInt(
DxvkSpirvIdCounter& ids,
uint32_t SpirvTypeInfo::typeInt(
SpirvIdCounter& ids,
uint32_t width,
uint32_t isSigned) {
std::array<uint32_t, 2> args = {{ width, isSigned }};
@ -35,16 +35,16 @@ namespace dxvk {
}
uint32_t DxbcTypeInfo::typeFloat(
DxvkSpirvIdCounter& ids,
uint32_t SpirvTypeInfo::typeFloat(
SpirvIdCounter& ids,
uint32_t width) {
return this->getTypeId(ids,
spv::OpTypeFloat, 1, &width);
}
uint32_t DxbcTypeInfo::typeVector(
DxvkSpirvIdCounter& ids,
uint32_t SpirvTypeInfo::typeVector(
SpirvIdCounter& ids,
uint32_t componentType,
uint32_t componentCount) {
std::array<uint32_t, 2> args = {{ componentType, componentCount }};
@ -53,8 +53,8 @@ namespace dxvk {
}
uint32_t DxbcTypeInfo::typeMatrix(
DxvkSpirvIdCounter& ids,
uint32_t SpirvTypeInfo::typeMatrix(
SpirvIdCounter& ids,
uint32_t colType,
uint32_t colCount) {
std::array<uint32_t, 2> args = {{ colType, colCount }};
@ -63,8 +63,8 @@ namespace dxvk {
}
uint32_t DxbcTypeInfo::typeArray(
DxvkSpirvIdCounter& ids,
uint32_t SpirvTypeInfo::typeArray(
SpirvIdCounter& ids,
uint32_t elementType,
uint32_t elementCount) {
std::array<uint32_t, 2> args = {{ elementType, elementCount }};
@ -73,16 +73,16 @@ namespace dxvk {
}
uint32_t DxbcTypeInfo::typeRuntimeArray(
DxvkSpirvIdCounter& ids,
uint32_t SpirvTypeInfo::typeRuntimeArray(
SpirvIdCounter& ids,
uint32_t elementType) {
return this->getTypeId(ids,
spv::OpTypeRuntimeArray, 1, &elementType);
}
uint32_t DxbcTypeInfo::typePointer(
DxvkSpirvIdCounter& ids,
uint32_t SpirvTypeInfo::typePointer(
SpirvIdCounter& ids,
spv::StorageClass storageClass,
uint32_t type) {
std::array<uint32_t, 2> args = {{ storageClass, type }};
@ -91,8 +91,8 @@ namespace dxvk {
}
uint32_t DxbcTypeInfo::typeFunction(
DxvkSpirvIdCounter& ids,
uint32_t SpirvTypeInfo::typeFunction(
SpirvIdCounter& ids,
uint32_t returnType,
uint32_t argCount,
const uint32_t* argTypes) {
@ -108,8 +108,8 @@ namespace dxvk {
}
uint32_t DxbcTypeInfo::typeStruct(
DxvkSpirvIdCounter& ids,
uint32_t SpirvTypeInfo::typeStruct(
SpirvIdCounter& ids,
uint32_t memberCount,
const uint32_t* memberTypes) {
return this->getTypeId(ids,
@ -119,11 +119,11 @@ namespace dxvk {
}
uint32_t DxbcTypeInfo::getTypeId(
DxvkSpirvIdCounter& ids,
spv::Op op,
uint32_t argCount,
const uint32_t* args) {
uint32_t SpirvTypeInfo::getTypeId(
SpirvIdCounter& ids,
spv::Op op,
uint32_t argCount,
const uint32_t* args) {
// Since the type info is stored in the code buffer,
// we can use the code buffer to look up type IDs as
// well. Result IDs are always stored as argument 1.

View File

@ -1,8 +1,8 @@
#pragma once
#include <initializer_list>
#include "../spirv_code_buffer.h"
#include "dxbc_include.h"
#include "spirv_gen_id.h"
namespace dxvk {
@ -12,74 +12,74 @@ namespace dxvk {
* Stores SPIR-V type definition so that
* each type will only be declared once.
*/
class DxbcTypeInfo {
class SpirvTypeInfo {
public:
DxbcTypeInfo();
~DxbcTypeInfo();
SpirvTypeInfo();
~SpirvTypeInfo();
DxvkSpirvCodeBuffer code() const;
SpirvCodeBuffer code() const;
uint32_t typeVoid(
DxvkSpirvIdCounter& ids);
SpirvIdCounter& ids);
uint32_t typeBool(
DxvkSpirvIdCounter& ids);
SpirvIdCounter& ids);
uint32_t typeInt(
DxvkSpirvIdCounter& ids,
SpirvIdCounter& ids,
uint32_t width,
uint32_t isSigned);
uint32_t typeFloat(
DxvkSpirvIdCounter& ids,
SpirvIdCounter& ids,
uint32_t width);
uint32_t typeVector(
DxvkSpirvIdCounter& ids,
SpirvIdCounter& ids,
uint32_t componentType,
uint32_t componentCount);
uint32_t typeMatrix(
DxvkSpirvIdCounter& ids,
SpirvIdCounter& ids,
uint32_t colType,
uint32_t colCount);
uint32_t typeArray(
DxvkSpirvIdCounter& ids,
SpirvIdCounter& ids,
uint32_t elementType,
uint32_t elementCount);
uint32_t typeRuntimeArray(
DxvkSpirvIdCounter& ids,
SpirvIdCounter& ids,
uint32_t elementType);
uint32_t typePointer(
DxvkSpirvIdCounter& ids,
SpirvIdCounter& ids,
spv::StorageClass storageClass,
uint32_t type);
uint32_t typeFunction(
DxvkSpirvIdCounter& ids,
SpirvIdCounter& ids,
uint32_t returnType,
uint32_t argCount,
const uint32_t* argTypes);
uint32_t typeStruct(
DxvkSpirvIdCounter& ids,
SpirvIdCounter& ids,
uint32_t memberCount,
const uint32_t* memberTypes);
private:
DxvkSpirvCodeBuffer m_code;
SpirvCodeBuffer m_code;
uint32_t getTypeId(
DxvkSpirvIdCounter& ids,
spv::Op op,
uint32_t argCount,
const uint32_t* args);
SpirvIdCounter& ids,
spv::Op op,
uint32_t argCount,
const uint32_t* args);
};

View File

View File

View File

@ -1,5 +1,13 @@
spirv_src = files([
'spirv_code_buffer.cpp'
'spirv_code_buffer.cpp',
'gen/spirv_gen_capability.cpp',
'gen/spirv_gen_constant.cpp',
'gen/spirv_gen_debuginfo.cpp',
'gen/spirv_gen_decoration.cpp',
'gen/spirv_gen_entrypoint.cpp',
'gen/spirv_gen_typeinfo.cpp',
'gen/spirv_gen_variable.cpp',
])
spirv_lib = static_library('spirv', spirv_src,

View File

@ -5,11 +5,11 @@
namespace dxvk {
DxvkSpirvCodeBuffer:: DxvkSpirvCodeBuffer() { }
DxvkSpirvCodeBuffer::~DxvkSpirvCodeBuffer() { }
SpirvCodeBuffer:: SpirvCodeBuffer() { }
SpirvCodeBuffer::~SpirvCodeBuffer() { }
DxvkSpirvCodeBuffer::DxvkSpirvCodeBuffer(std::istream&& stream) {
SpirvCodeBuffer::SpirvCodeBuffer(std::istream&& stream) {
stream.ignore(std::numeric_limits<std::streamsize>::max());
std::streamsize length = stream.gcount();
stream.clear();
@ -25,7 +25,7 @@ namespace dxvk {
}
void DxvkSpirvCodeBuffer::append(const DxvkSpirvCodeBuffer& other) {
void SpirvCodeBuffer::append(const SpirvCodeBuffer& other) {
if (other.size() != 0) {
const size_t size = m_code.size();
m_code.resize(size + other.m_code.size());
@ -38,30 +38,30 @@ namespace dxvk {
}
void DxvkSpirvCodeBuffer::putWord(uint32_t word) {
void SpirvCodeBuffer::putWord(uint32_t word) {
m_code.push_back(word);
}
void DxvkSpirvCodeBuffer::putIns(spv::Op opCode, uint16_t wordCount) {
void SpirvCodeBuffer::putIns(spv::Op opCode, uint16_t wordCount) {
this->putWord(
(static_cast<uint32_t>(opCode) << 0)
| (static_cast<uint32_t>(wordCount) << 16));
}
void DxvkSpirvCodeBuffer::putInt32(uint32_t word) {
void SpirvCodeBuffer::putInt32(uint32_t word) {
this->putWord(word);
}
void DxvkSpirvCodeBuffer::putInt64(uint64_t value) {
void SpirvCodeBuffer::putInt64(uint64_t value) {
this->putWord(value >> 0);
this->putWord(value >> 32);
}
void DxvkSpirvCodeBuffer::putFloat32(float value) {
void SpirvCodeBuffer::putFloat32(float value) {
uint32_t tmp;
static_assert(sizeof(tmp) == sizeof(value));
std::memcpy(&tmp, &value, sizeof(value));
@ -69,7 +69,7 @@ namespace dxvk {
}
void DxvkSpirvCodeBuffer::putFloat64(double value) {
void SpirvCodeBuffer::putFloat64(double value) {
uint64_t tmp;
static_assert(sizeof(tmp) == sizeof(value));
std::memcpy(&tmp, &value, sizeof(value));
@ -77,7 +77,7 @@ namespace dxvk {
}
void DxvkSpirvCodeBuffer::putStr(const char* str) {
void SpirvCodeBuffer::putStr(const char* str) {
uint32_t word = 0;
uint32_t nbit = 0;
@ -96,7 +96,7 @@ namespace dxvk {
}
void DxvkSpirvCodeBuffer::putHeader(uint32_t boundIds) {
void SpirvCodeBuffer::putHeader(uint32_t boundIds) {
this->putWord(spv::MagicNumber);
this->putWord(spv::Version);
this->putWord(0); // Generator
@ -105,13 +105,13 @@ namespace dxvk {
}
uint32_t DxvkSpirvCodeBuffer::strLen(const char* str) {
uint32_t SpirvCodeBuffer::strLen(const char* str) {
// Null-termination plus padding
return (std::strlen(str) + 4) / 4;
}
void DxvkSpirvCodeBuffer::store(std::ostream&& stream) const {
void SpirvCodeBuffer::store(std::ostream&& stream) const {
stream.write(
reinterpret_cast<const char*>(m_code.data()),
sizeof(uint32_t) * m_code.size());

View File

@ -16,13 +16,13 @@ namespace dxvk {
* Stores arbitrary SPIR-V instructions in a
* format that can be read by Vulkan drivers.
*/
class DxvkSpirvCodeBuffer {
class SpirvCodeBuffer {
public:
DxvkSpirvCodeBuffer();
DxvkSpirvCodeBuffer(std::istream&& stream);
~DxvkSpirvCodeBuffer();
SpirvCodeBuffer();
SpirvCodeBuffer(std::istream&& stream);
~SpirvCodeBuffer();
/**
* \brief Code data
@ -47,8 +47,8 @@ namespace dxvk {
* block. The header, if any, will be skipped over.
* \returns Instruction iterator
*/
DxvkSpirvInstructionIterator begin() const {
return DxvkSpirvInstructionIterator(m_code.data(), m_code.size());
SpirvInstructionIterator begin() const {
return SpirvInstructionIterator(m_code.data(), m_code.size());
}
/**
@ -57,8 +57,8 @@ namespace dxvk {
* Points to the end of the instruction block.
* \returns Instruction iterator
*/
DxvkSpirvInstructionIterator end() const {
return DxvkSpirvInstructionIterator(nullptr, 0);
SpirvInstructionIterator end() const {
return SpirvInstructionIterator(nullptr, 0);
}
/**
@ -69,7 +69,7 @@ namespace dxvk {
* code when doing so in advance is impossible.
* \param [in] other Code buffer to append
*/
void append(const DxvkSpirvCodeBuffer& other);
void append(const SpirvCodeBuffer& other);
/**
* \brief Appends an 32-bit word to the buffer

View File

@ -13,12 +13,12 @@ namespace dxvk {
* access to the op code, instruction length and
* instruction arguments.
*/
class DxvkSpirvInstruction {
class SpirvInstruction {
public:
DxvkSpirvInstruction() { }
DxvkSpirvInstruction(
SpirvInstruction() { }
SpirvInstruction(
const uint32_t* code, uint32_t size)
: m_code(code), m_size(size) { }
@ -67,32 +67,32 @@ namespace dxvk {
* Convenient iterator that can be used
* to process raw SPIR-V shader code.
*/
class DxvkSpirvInstructionIterator {
class SpirvInstructionIterator {
public:
DxvkSpirvInstructionIterator() { }
DxvkSpirvInstructionIterator(const uint32_t* code, uint32_t size)
SpirvInstructionIterator() { }
SpirvInstructionIterator(const uint32_t* code, uint32_t size)
: m_code(size != 0 ? code : nullptr), m_size(size) {
if ((size >= 5) && (m_code[0] == spv::MagicNumber))
this->advance(5);
}
DxvkSpirvInstructionIterator& operator ++ () {
this->advance(DxvkSpirvInstruction(m_code, m_size).length());
SpirvInstructionIterator& operator ++ () {
this->advance(SpirvInstruction(m_code, m_size).length());
return *this;
}
DxvkSpirvInstruction operator * () const {
return DxvkSpirvInstruction(m_code, m_size);
SpirvInstruction operator * () const {
return SpirvInstruction(m_code, m_size);
}
bool operator == (const DxvkSpirvInstructionIterator& other) const {
bool operator == (const SpirvInstructionIterator& other) const {
return this->m_code == other.m_code
&& this->m_size == other.m_size;
}
bool operator != (const DxvkSpirvInstructionIterator& other) const {
bool operator != (const SpirvInstructionIterator& other) const {
return this->m_code != other.m_code
&& this->m_size != other.m_size;
}

View File

@ -54,7 +54,7 @@ public:
computeBufferSlot.type = DxvkResourceType::StorageBuffer;
computeBufferSlot.slot = 0;
DxvkSpirvCodeBuffer code(std::ifstream("comp.spv", std::ios::binary));
SpirvCodeBuffer code(std::ifstream("comp.spv", std::ios::binary));
code.store(std::ofstream("comp.2.spv", std::ios::binary));
m_compShader = new DxvkShader(