2017-10-11 23:28:06 +02:00
|
|
|
#pragma once
|
|
|
|
|
2017-10-14 13:44:38 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2017-10-11 23:28:06 +02:00
|
|
|
#include "dxvk_include.h"
|
2017-12-07 09:38:31 +01:00
|
|
|
#include "dxvk_pipelayout.h"
|
2017-10-11 23:28:06 +02:00
|
|
|
|
2017-10-18 09:50:30 +02:00
|
|
|
#include "../spirv/spirv_code_buffer.h"
|
2017-10-11 23:28:06 +02:00
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2018-01-12 14:25:26 +01:00
|
|
|
/**
|
|
|
|
* \brief Shader interface slots
|
|
|
|
*
|
|
|
|
* Stores a bit mask of which shader
|
|
|
|
* interface slots are defined. Used
|
|
|
|
* purely for validation purposes.
|
|
|
|
*/
|
|
|
|
struct DxvkInterfaceSlots {
|
|
|
|
uint32_t inputSlots = 0;
|
|
|
|
uint32_t outputSlots = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-10-11 23:28:06 +02:00
|
|
|
/**
|
2017-12-07 09:38:31 +01:00
|
|
|
* \brief Shader module object
|
2017-10-11 23:28:06 +02:00
|
|
|
*
|
|
|
|
* Manages a Vulkan shader module. This will not
|
2017-12-07 09:38:31 +01:00
|
|
|
* perform any shader compilation. Instead, the
|
|
|
|
* context will create pipeline objects on the
|
2017-10-11 23:28:06 +02:00
|
|
|
* fly when executing draw calls.
|
|
|
|
*/
|
2017-12-07 09:38:31 +01:00
|
|
|
class DxvkShaderModule : public RcObject {
|
2017-10-11 23:28:06 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-12-07 09:38:31 +01:00
|
|
|
DxvkShaderModule(
|
2017-11-20 14:03:00 +01:00
|
|
|
const Rc<vk::DeviceFn>& vkd,
|
2017-10-14 23:52:47 +02:00
|
|
|
VkShaderStageFlagBits stage,
|
2018-02-07 16:44:30 +01:00
|
|
|
const SpirvCodeBuffer& code,
|
|
|
|
const std::string& name);
|
2017-10-11 23:28:06 +02:00
|
|
|
|
2017-12-07 09:38:31 +01:00
|
|
|
~DxvkShaderModule();
|
|
|
|
|
2018-01-10 11:44:40 +01:00
|
|
|
/**
|
|
|
|
* \brief Shader module handle
|
|
|
|
* \returns Shader module handle
|
|
|
|
*/
|
2017-12-07 09:38:31 +01:00
|
|
|
VkShaderModule handle() const {
|
2017-11-20 14:03:00 +01:00
|
|
|
return m_module;
|
2017-11-18 10:42:27 +01:00
|
|
|
}
|
2017-10-11 23:28:06 +02:00
|
|
|
|
2018-01-10 11:44:40 +01:00
|
|
|
/**
|
|
|
|
* \brief Shader stage creation info
|
|
|
|
*
|
|
|
|
* \param [in] specInfo Specialization info
|
|
|
|
* \returns Shader stage create info
|
|
|
|
*/
|
|
|
|
VkPipelineShaderStageCreateInfo stageInfo(
|
|
|
|
const VkSpecializationInfo* specInfo) const;
|
2017-11-20 14:03:00 +01:00
|
|
|
|
2018-02-07 16:44:30 +01:00
|
|
|
/**
|
|
|
|
* \brief The shader's debug name
|
|
|
|
* \returns Debug name
|
|
|
|
*/
|
|
|
|
const std::string& debugName() const {
|
|
|
|
return m_debugName;
|
|
|
|
}
|
|
|
|
|
2017-10-11 23:28:06 +02:00
|
|
|
private:
|
|
|
|
|
2017-11-20 14:03:00 +01:00
|
|
|
Rc<vk::DeviceFn> m_vkd;
|
2017-10-14 23:52:47 +02:00
|
|
|
VkShaderStageFlagBits m_stage;
|
2017-11-20 14:03:00 +01:00
|
|
|
VkShaderModule m_module;
|
2018-02-07 16:44:30 +01:00
|
|
|
std::string m_debugName;
|
2017-10-14 23:52:47 +02:00
|
|
|
|
2017-10-11 23:28:06 +02:00
|
|
|
};
|
|
|
|
|
2017-12-07 09:38:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Shader object
|
|
|
|
*
|
|
|
|
* Stores a SPIR-V shader and information on the
|
|
|
|
* bindings that the shader uses. In order to use
|
|
|
|
* the shader with a pipeline, a shader module
|
|
|
|
* needs to be created from he shader object.
|
|
|
|
*/
|
|
|
|
class DxvkShader : public RcObject {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DxvkShader(
|
|
|
|
VkShaderStageFlagBits stage,
|
|
|
|
uint32_t slotCount,
|
|
|
|
const DxvkResourceSlot* slotInfos,
|
2018-01-12 14:25:26 +01:00
|
|
|
const DxvkInterfaceSlots& iface,
|
2017-12-07 09:38:31 +01:00
|
|
|
const SpirvCodeBuffer& code);
|
2017-12-08 18:14:05 +01:00
|
|
|
|
2017-12-07 09:38:31 +01:00
|
|
|
~DxvkShader();
|
|
|
|
|
2018-04-08 21:49:30 +02:00
|
|
|
/**
|
|
|
|
* \brief Checks whether a capability is enabled
|
|
|
|
*
|
|
|
|
* If the shader contains an \c OpCapability
|
|
|
|
* instruction with the given capability, it
|
|
|
|
* is considered enabled. This may be required
|
|
|
|
* to correctly set up certain pipeline states.
|
|
|
|
* \param [in] cap The capability to check
|
|
|
|
* \returns \c true if \c cap is enabled
|
|
|
|
*/
|
|
|
|
bool hasCapability(spv::Capability cap);
|
|
|
|
|
2017-12-07 09:38:31 +01:00
|
|
|
/**
|
2017-12-08 18:14:05 +01:00
|
|
|
* \brief Adds resource slots definitions to a mapping
|
|
|
|
*
|
|
|
|
* Used to generate the exact descriptor set layout when
|
|
|
|
* compiling a graphics or compute pipeline. Slot indices
|
|
|
|
* have to be mapped to actual binding numbers.
|
2017-12-07 09:38:31 +01:00
|
|
|
*/
|
|
|
|
void defineResourceSlots(
|
|
|
|
DxvkDescriptorSlotMapping& mapping) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Creates a shader module
|
|
|
|
*
|
|
|
|
* Maps the binding slot numbers
|
2017-12-08 18:14:05 +01:00
|
|
|
* \param [in] vkd Vulkan device functions
|
2017-12-07 09:38:31 +01:00
|
|
|
* \param [in] mapping Resource slot mapping
|
|
|
|
* \returns The shader module
|
|
|
|
*/
|
|
|
|
Rc<DxvkShaderModule> createShaderModule(
|
2017-12-08 18:14:05 +01:00
|
|
|
const Rc<vk::DeviceFn>& vkd,
|
2017-12-07 09:38:31 +01:00
|
|
|
const DxvkDescriptorSlotMapping& mapping) const;
|
|
|
|
|
2018-01-12 14:25:26 +01:00
|
|
|
/**
|
|
|
|
* \brief Inter-stage interface slots
|
|
|
|
*
|
|
|
|
* Retrieves the input and output
|
|
|
|
* registers used by the shader.
|
|
|
|
* \returns Shader interface slots
|
|
|
|
*/
|
|
|
|
DxvkInterfaceSlots interfaceSlots() const {
|
|
|
|
return m_interface;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:14:05 +01:00
|
|
|
/**
|
|
|
|
* \brief Dumps SPIR-V shader
|
|
|
|
*
|
|
|
|
* Can be used to store the SPIR-V code in a file.
|
|
|
|
* \param [in] outputStream Stream to write to
|
|
|
|
*/
|
2018-03-23 18:17:16 +01:00
|
|
|
void dump(std::ostream& outputStream) const;
|
2017-12-08 18:14:05 +01:00
|
|
|
|
2017-12-10 12:21:33 +01:00
|
|
|
/**
|
|
|
|
* \brief Reads SPIR-V shader
|
|
|
|
*
|
|
|
|
* Can be used to replace the compiled SPIR-V code.
|
|
|
|
* \param [in] inputStream Stream to read from
|
|
|
|
*/
|
2018-03-23 18:17:16 +01:00
|
|
|
void read(std::istream& inputStream);
|
2017-12-10 12:21:33 +01:00
|
|
|
|
2018-02-07 16:44:30 +01:00
|
|
|
/**
|
|
|
|
* \brief Sets the shader's debug name
|
|
|
|
*
|
|
|
|
* Debug names may be used by the backend in
|
|
|
|
* order to help debug shader compiler issues.
|
|
|
|
* \param [in] name The shader's name
|
|
|
|
*/
|
|
|
|
void setDebugName(const std::string& name) {
|
|
|
|
m_debugName = name;
|
|
|
|
}
|
|
|
|
|
2017-12-07 09:38:31 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
VkShaderStageFlagBits m_stage;
|
|
|
|
SpirvCodeBuffer m_code;
|
|
|
|
|
|
|
|
std::vector<DxvkResourceSlot> m_slots;
|
2018-04-10 12:48:46 +02:00
|
|
|
std::vector<size_t> m_idOffsets;
|
2018-01-12 14:25:26 +01:00
|
|
|
DxvkInterfaceSlots m_interface;
|
2018-02-07 16:44:30 +01:00
|
|
|
std::string m_debugName;
|
2017-12-07 09:38:31 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-10-11 23:28:06 +02:00
|
|
|
}
|