1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-31 05:52:11 +01:00

[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() { Rc<DxvkShader> DxbcCompiler::finalize() {
DxvkSpirvCodeBuffer codeBuffer; SpirvCodeBuffer codeBuffer;
codeBuffer.putHeader(m_counter.numIds()); codeBuffer.putHeader(m_counter.numIds());
codeBuffer.append(m_spvCapabilities.code()); codeBuffer.append(m_spvCapabilities.code());
codeBuffer.append(m_spvEntryPoints.code()); codeBuffer.append(m_spvEntryPoints.code());

View File

@ -1,9 +1,10 @@
#pragma once #pragma once
#include "dxbc_capability.h"
#include "dxbc_chunk_shex.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 { namespace dxvk {
@ -36,12 +37,12 @@ namespace dxvk {
private: private:
DxbcProgramVersion m_version; DxbcProgramVersion m_version;
DxvkSpirvIdCounter m_counter; SpirvIdCounter m_counter;
DxbcCapabilities m_spvCapabilities; SpirvCapabilities m_spvCapabilities;
DxbcEntryPoint m_spvEntryPoints; SpirvEntryPoint m_spvEntryPoints;
DxbcTypeInfo m_spvTypeInfo; SpirvTypeInfo m_spvTypeInfo;
DxvkSpirvCodeBuffer m_spvCode; SpirvCodeBuffer m_spvCode;
void declareCapabilities(); void declareCapabilities();
void declareMemoryModel(); void declareMemoryModel();

View File

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

View File

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

View File

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

View File

@ -5,7 +5,6 @@
#include "dxvk_include.h" #include "dxvk_include.h"
#include "../spirv/spirv_code_buffer.h" #include "../spirv/spirv_code_buffer.h"
#include "../spirv/spirv_id_counter.h"
namespace dxvk { namespace dxvk {
@ -61,7 +60,7 @@ namespace dxvk {
DxvkShader( DxvkShader(
VkShaderStageFlagBits stage, VkShaderStageFlagBits stage,
DxvkSpirvCodeBuffer&& code, SpirvCodeBuffer&& code,
uint32_t numResourceSlots, uint32_t numResourceSlots,
const DxvkResourceSlot* resourceSlots); const DxvkResourceSlot* resourceSlots);
~DxvkShader(); ~DxvkShader();
@ -76,7 +75,7 @@ namespace dxvk {
* \param [in] bindingOffset First binding ID * \param [in] bindingOffset First binding ID
* \returns Modified code buffer * \returns Modified code buffer
*/ */
DxvkSpirvCodeBuffer code( SpirvCodeBuffer code(
uint32_t bindingOffset) const; uint32_t bindingOffset) const;
/** /**
@ -114,7 +113,7 @@ namespace dxvk {
private: private:
VkShaderStageFlagBits m_stage; VkShaderStageFlagBits m_stage;
DxvkSpirvCodeBuffer m_code; SpirvCodeBuffer m_code;
std::vector<DxvkResourceSlot> m_slots; 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 #pragma once
#include <unordered_set> #include "../spirv_code_buffer.h"
#include "dxbc_include.h"
namespace dxvk { namespace dxvk {
@ -12,12 +10,12 @@ namespace dxvk {
* Holds a code buffer solely for the \c OpCapability * Holds a code buffer solely for the \c OpCapability
* instructions in the generated SPIR-V shader module. * instructions in the generated SPIR-V shader module.
*/ */
class DxbcCapabilities { class SpirvCapabilities {
public: public:
DxbcCapabilities(); SpirvCapabilities();
~DxbcCapabilities(); ~SpirvCapabilities();
/** /**
* \brief Code buffer * \brief Code buffer
@ -26,7 +24,7 @@ namespace dxvk {
* \c OpCapability instructions. * \c OpCapability instructions.
* \returns Code buffer * \returns Code buffer
*/ */
DxvkSpirvCodeBuffer code() const; SpirvCodeBuffer code() const;
/** /**
* \brief Enables a capability * \brief Enables a capability
@ -40,7 +38,7 @@ namespace dxvk {
private: 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 { namespace dxvk {
DxbcEntryPoint:: DxbcEntryPoint() { } SpirvEntryPoint:: SpirvEntryPoint() { }
DxbcEntryPoint::~DxbcEntryPoint() { } SpirvEntryPoint::~SpirvEntryPoint() { }
DxvkSpirvCodeBuffer DxbcEntryPoint::code() const { SpirvCodeBuffer SpirvEntryPoint::code() const {
DxvkSpirvCodeBuffer code; SpirvCodeBuffer code;
code.append(m_memoryModel); code.append(m_memoryModel);
code.append(m_entryPoints); code.append(m_entryPoints);
code.append(m_execModeInfo); code.append(m_execModeInfo);
@ -15,7 +15,7 @@ namespace dxvk {
} }
void DxbcEntryPoint::setMemoryModel( void SpirvEntryPoint::setMemoryModel(
spv::AddressingModel addressModel, spv::AddressingModel addressModel,
spv::MemoryModel memoryModel) { spv::MemoryModel memoryModel) {
m_memoryModel.putIns (spv::OpMemoryModel, 3); m_memoryModel.putIns (spv::OpMemoryModel, 3);
@ -24,7 +24,7 @@ namespace dxvk {
} }
void DxbcEntryPoint::addEntryPoint( void SpirvEntryPoint::addEntryPoint(
uint32_t functionId, uint32_t functionId,
spv::ExecutionModel execModel, spv::ExecutionModel execModel,
const char* name, const char* name,
@ -40,7 +40,7 @@ namespace dxvk {
} }
void DxbcEntryPoint::setLocalSize( void SpirvEntryPoint::setLocalSize(
uint32_t functionId, uint32_t functionId,
uint32_t x, uint32_t x,
uint32_t y, uint32_t y,

View File

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

View File

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

View File

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

View File

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

View File

View File

View File

@ -1,5 +1,13 @@
spirv_src = files([ 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, spirv_lib = static_library('spirv', spirv_src,

View File

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

View File

@ -16,13 +16,13 @@ namespace dxvk {
* Stores arbitrary SPIR-V instructions in a * Stores arbitrary SPIR-V instructions in a
* format that can be read by Vulkan drivers. * format that can be read by Vulkan drivers.
*/ */
class DxvkSpirvCodeBuffer { class SpirvCodeBuffer {
public: public:
DxvkSpirvCodeBuffer(); SpirvCodeBuffer();
DxvkSpirvCodeBuffer(std::istream&& stream); SpirvCodeBuffer(std::istream&& stream);
~DxvkSpirvCodeBuffer(); ~SpirvCodeBuffer();
/** /**
* \brief Code data * \brief Code data
@ -47,8 +47,8 @@ namespace dxvk {
* block. The header, if any, will be skipped over. * block. The header, if any, will be skipped over.
* \returns Instruction iterator * \returns Instruction iterator
*/ */
DxvkSpirvInstructionIterator begin() const { SpirvInstructionIterator begin() const {
return DxvkSpirvInstructionIterator(m_code.data(), m_code.size()); return SpirvInstructionIterator(m_code.data(), m_code.size());
} }
/** /**
@ -57,8 +57,8 @@ namespace dxvk {
* Points to the end of the instruction block. * Points to the end of the instruction block.
* \returns Instruction iterator * \returns Instruction iterator
*/ */
DxvkSpirvInstructionIterator end() const { SpirvInstructionIterator end() const {
return DxvkSpirvInstructionIterator(nullptr, 0); return SpirvInstructionIterator(nullptr, 0);
} }
/** /**
@ -69,7 +69,7 @@ namespace dxvk {
* code when doing so in advance is impossible. * code when doing so in advance is impossible.
* \param [in] other Code buffer to append * \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 * \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 * access to the op code, instruction length and
* instruction arguments. * instruction arguments.
*/ */
class DxvkSpirvInstruction { class SpirvInstruction {
public: public:
DxvkSpirvInstruction() { } SpirvInstruction() { }
DxvkSpirvInstruction( SpirvInstruction(
const uint32_t* code, uint32_t size) const uint32_t* code, uint32_t size)
: m_code(code), m_size(size) { } : m_code(code), m_size(size) { }
@ -67,32 +67,32 @@ namespace dxvk {
* Convenient iterator that can be used * Convenient iterator that can be used
* to process raw SPIR-V shader code. * to process raw SPIR-V shader code.
*/ */
class DxvkSpirvInstructionIterator { class SpirvInstructionIterator {
public: public:
DxvkSpirvInstructionIterator() { } SpirvInstructionIterator() { }
DxvkSpirvInstructionIterator(const uint32_t* code, uint32_t size) SpirvInstructionIterator(const uint32_t* code, uint32_t size)
: m_code(size != 0 ? code : nullptr), m_size(size) { : m_code(size != 0 ? code : nullptr), m_size(size) {
if ((size >= 5) && (m_code[0] == spv::MagicNumber)) if ((size >= 5) && (m_code[0] == spv::MagicNumber))
this->advance(5); this->advance(5);
} }
DxvkSpirvInstructionIterator& operator ++ () { SpirvInstructionIterator& operator ++ () {
this->advance(DxvkSpirvInstruction(m_code, m_size).length()); this->advance(SpirvInstruction(m_code, m_size).length());
return *this; return *this;
} }
DxvkSpirvInstruction operator * () const { SpirvInstruction operator * () const {
return DxvkSpirvInstruction(m_code, m_size); 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 return this->m_code == other.m_code
&& this->m_size == other.m_size; && 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 return this->m_code != other.m_code
&& this->m_size != other.m_size; && this->m_size != other.m_size;
} }

View File

@ -54,7 +54,7 @@ public:
computeBufferSlot.type = DxvkResourceType::StorageBuffer; computeBufferSlot.type = DxvkResourceType::StorageBuffer;
computeBufferSlot.slot = 0; 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)); code.store(std::ofstream("comp.2.spv", std::ios::binary));
m_compShader = new DxvkShader( m_compShader = new DxvkShader(