*
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
|
||||
add_subdirectory(RenderFramework/Vulkan)
|
||||
|
||||
add_library(RenderFramework STATIC)
|
||||
|
||||
target_sources(RenderFramework
|
||||
PRIVATE
|
||||
RenderFramework/Archive.cpp
|
||||
RenderFramework/Archive.h
|
||||
RenderFramework/Asset.h
|
||||
RenderFramework/AssetDatabase.cpp
|
||||
RenderFramework/AssetDatabase.h
|
||||
RenderFramework/AssetFile.h
|
||||
RenderFramework/AssetImporter.h
|
||||
RenderFramework/AssetManager.cpp
|
||||
RenderFramework/AssetManager.h
|
||||
RenderFramework/AssetMetadata.cpp
|
||||
RenderFramework/AssetMetadata.h
|
||||
RenderFramework/Bounds.h
|
||||
RenderFramework/Camera.cpp
|
||||
RenderFramework/Camera.h
|
||||
RenderFramework/Component.cpp
|
||||
RenderFramework/Component.h
|
||||
RenderFramework/FatalError.h
|
||||
RenderFramework/File.h
|
||||
RenderFramework/Filesystem.h
|
||||
RenderFramework/ForwardDeclarations.h
|
||||
RenderFramework/ForwardListItem.h
|
||||
RenderFramework/GameObject.cpp
|
||||
RenderFramework/GameObject.h
|
||||
RenderFramework/Gizmos.cpp
|
||||
RenderFramework/Gizmos.h
|
||||
RenderFramework/GizmoVertex.h
|
||||
RenderFramework/Guid.h
|
||||
RenderFramework/InputArchive.h
|
||||
RenderFramework/LEngine.cpp
|
||||
RenderFramework/LEngine.h
|
||||
RenderFramework/Material.cpp
|
||||
RenderFramework/Material.h
|
||||
RenderFramework/Mathf.h
|
||||
RenderFramework/Mesh.cpp
|
||||
RenderFramework/Mesh.h
|
||||
RenderFramework/MeshGenerator.cpp
|
||||
RenderFramework/MeshGenerator.h
|
||||
RenderFramework/MeshRenderer.cpp
|
||||
RenderFramework/MeshRenderer.h
|
||||
RenderFramework/ModelImporter.h
|
||||
RenderFramework/Object.cpp
|
||||
RenderFramework/Object.h
|
||||
RenderFramework/ObjectsFactory.cpp
|
||||
RenderFramework/ObjectsFactory.h
|
||||
RenderFramework/ObjMeshLoader.h
|
||||
RenderFramework/OutputArchive.h
|
||||
RenderFramework/Renderer.cpp
|
||||
RenderFramework/Renderer.h
|
||||
RenderFramework/RenderOutput.h
|
||||
RenderFramework/RenderTargetOutput.cpp
|
||||
RenderFramework/RenderTargetOutput.h
|
||||
RenderFramework/Scene.cpp
|
||||
RenderFramework/Scene.h
|
||||
RenderFramework/SceneRenderer.cpp
|
||||
RenderFramework/SceneRenderer.h
|
||||
RenderFramework/Shader.cpp
|
||||
RenderFramework/Shader.h
|
||||
RenderFramework/ShaderInclude.h
|
||||
RenderFramework/ShaderParametersBlock.h
|
||||
RenderFramework/Submesh.h
|
||||
RenderFramework/SwapChainOutput.h
|
||||
RenderFramework/Texture.h
|
||||
RenderFramework/TextureImporter.h
|
||||
RenderFramework/Transform.h
|
||||
RenderFramework/Vertex.h
|
||||
RenderFramework/WindowRenderOutput.cpp
|
||||
RenderFramework/WindowRenderOutput.h
|
||||
)
|
||||
|
||||
target_link_libraries(RenderFramework
|
||||
PUBLIC
|
||||
VulkanWrapper
|
||||
LMath
|
||||
)
|
||||
|
||||
target_include_directories(RenderFramework
|
||||
PUBLIC
|
||||
./
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "Archive.h"
|
||||
|
||||
|
||||
|
||||
Archive& Archive::operator << (AssetFileLink& value) {
|
||||
serialize(&value, sizeof(value)); return *this;
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
#ifndef Archive_h__
|
||||
#define Archive_h__
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include "Asset.h"
|
||||
#include <lmath/lmath.h>
|
||||
#include <type_traits>
|
||||
#include "Object.h"
|
||||
#include <cstdint>
|
||||
#define POD_SERIALIZE(_type) Archive& operator << (_type& value) { serialize(&value, sizeof(value)); return *this; }
|
||||
|
||||
class Object;
|
||||
class Archive {
|
||||
public:
|
||||
typedef uint64_t size_type;
|
||||
std::function<void(std::shared_ptr<Object>)> SaveReferenceCallback;
|
||||
std::function<std::shared_ptr<Object>(const AssetFileLink&)> LoadReferenceCallback;
|
||||
|
||||
Archive():SaveReferenceCallback(nullptr){
|
||||
|
||||
}
|
||||
virtual ~Archive() {}
|
||||
virtual bool is_loading() const = 0;
|
||||
virtual void serialize(void* data, size_t size) = 0;
|
||||
|
||||
virtual size_type get_offset() const = 0;
|
||||
virtual void set_offset(size_type offset) = 0;
|
||||
|
||||
virtual void flush() {}
|
||||
|
||||
POD_SERIALIZE(uint8_t);
|
||||
POD_SERIALIZE(uint16_t);
|
||||
POD_SERIALIZE(uint32_t);
|
||||
POD_SERIALIZE(uint64_t);
|
||||
POD_SERIALIZE(int8_t);
|
||||
POD_SERIALIZE(int16_t);
|
||||
POD_SERIALIZE(int32_t);
|
||||
POD_SERIALIZE(int64_t);
|
||||
POD_SERIALIZE(float);
|
||||
POD_SERIALIZE(double);
|
||||
POD_SERIALIZE(lm::float2);
|
||||
POD_SERIALIZE(lm::float3);
|
||||
POD_SERIALIZE(lm::float4);
|
||||
POD_SERIALIZE(lm::double2);
|
||||
POD_SERIALIZE(lm::double3);
|
||||
POD_SERIALIZE(lm::double4);
|
||||
|
||||
POD_SERIALIZE(lm::Quaternion_f);
|
||||
|
||||
Archive& operator << (std::string& value) {
|
||||
uint32_t string_len = 0;
|
||||
if (is_loading()) {
|
||||
serialize(&string_len, sizeof(string_len));
|
||||
value.resize(string_len);
|
||||
serialize(&value[0], string_len);
|
||||
} else {
|
||||
string_len = value.size();
|
||||
serialize(&string_len, sizeof(string_len));
|
||||
serialize(&value[0], string_len);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Archive& operator << (std::wstring& value) {
|
||||
uint32_t string_len = 0;
|
||||
if (is_loading()) {
|
||||
serialize(&string_len, sizeof(string_len));
|
||||
value.resize(string_len);
|
||||
serialize(&value[0], string_len * sizeof(std::wstring::value_type));
|
||||
} else {
|
||||
string_len = value.size();
|
||||
serialize(&string_len, sizeof(string_len));
|
||||
serialize(&value[0], string_len * sizeof(std::wstring::value_type));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T, typename = typename std::enable_if<std::is_base_of<Object, T>::value>::type>
|
||||
Archive& operator << (std::shared_ptr<T>& value) {
|
||||
if (is_loading()) {
|
||||
AssetFileLink link;
|
||||
(*this) << link;
|
||||
if(link.localId == -1)
|
||||
{
|
||||
value = nullptr;
|
||||
}else
|
||||
{
|
||||
auto pos = get_offset();
|
||||
value = LoadReferenceCallback == nullptr ? nullptr : std::dynamic_pointer_cast<T>(LoadReferenceCallback(link));
|
||||
set_offset(pos);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (SaveReferenceCallback != nullptr) {
|
||||
SaveReferenceCallback(value);
|
||||
}
|
||||
AssetFileLink link = value == nullptr ? AssetFileLink() : value->GetFileLink();
|
||||
(*this) << link;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
Archive& operator << (AssetFileLink& value);
|
||||
};
|
||||
#endif // Archive_h__
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef Asset_h__
|
||||
#define Asset_h__
|
||||
|
||||
#include <Windows.h>
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include "Guid.h"
|
||||
|
||||
class AssetFileLink {
|
||||
public:
|
||||
using LocalFileID = std::uint32_t;
|
||||
static constexpr LocalFileID InvalidID = -1;
|
||||
|
||||
Guid fileGuid;
|
||||
LocalFileID localId;
|
||||
|
||||
AssetFileLink():localId(InvalidID){}
|
||||
|
||||
AssetFileLink(const AssetFileLink& link) :fileGuid(link.fileGuid), localId(link.localId) {}
|
||||
|
||||
AssetFileLink(Guid _fileGuid, LocalFileID _localId) :fileGuid(_fileGuid), localId(_localId) {}
|
||||
|
||||
AssetFileLink& operator=(const AssetFileLink& link) {
|
||||
fileGuid = link.fileGuid;
|
||||
localId = link.localId;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const AssetFileLink& link) const {
|
||||
return (fileGuid == link.fileGuid) && (localId == link.localId);
|
||||
}
|
||||
|
||||
bool operator!=(const AssetFileLink& link) const {
|
||||
return (fileGuid != link.fileGuid) || (localId != link.localId);
|
||||
}
|
||||
|
||||
bool IsValid() const{
|
||||
return (localId != InvalidID) && !fileGuid.IsZero();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // Asset_h__
|
||||
@@ -0,0 +1,110 @@
|
||||
#include "AssetDatabase.h"
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include "ModelImporter.h"
|
||||
#include "TextureImporter.h"
|
||||
#include <algorithm>
|
||||
|
||||
AssetDatabase::AssetDatabase()
|
||||
{
|
||||
_importers.push_back(std::make_shared<ModelImporter>());
|
||||
//_importers.push_back(std::make_shared<TextureImporter>());
|
||||
}
|
||||
|
||||
void AssetDatabase::setRootPath(const std::wstring& path)
|
||||
{
|
||||
_rootAssetsPath = path;
|
||||
}
|
||||
|
||||
std::wstring AssetDatabase::getFullAssetPath(const std::string& localPathStr) {
|
||||
std::filesystem::path rootPath(_rootAssetsPath);
|
||||
std::filesystem::path localPath(localPathStr);
|
||||
auto fullPath = rootPath / localPath;
|
||||
auto result = fullPath.wstring();
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring AssetDatabase::asset_to_meta_path(const std::wstring& asset_path)
|
||||
{
|
||||
std::filesystem::path src(asset_path);
|
||||
return src.parent_path().append(src.filename().wstring() + L".meta").wstring();
|
||||
}
|
||||
|
||||
void AssetDatabase::register_importer(std::shared_ptr<AssetImporter> importer)
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Object>> AssetDatabase::load_all_objects(std::shared_ptr<AssetFile> asset)
|
||||
{
|
||||
std::vector<std::shared_ptr<Object>> result;
|
||||
auto table = asset->objectsTable;
|
||||
for (auto& obj : table.objects)
|
||||
{
|
||||
result.push_back(LoadObject(AssetFileLink(asset->guid(), obj.localId)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<AssetImporter> AssetDatabase::find_importer(const std::wstring& asset_path) const
|
||||
{
|
||||
auto importer = std::find_if(_importers.begin(), _importers.end(), [asset_path](std::shared_ptr<AssetImporter> im) { return im->can_import(asset_path); });
|
||||
if (importer != _importers.end())
|
||||
{
|
||||
return *importer;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Guid AssetDatabase::file_to_guid(const std::wstring& path) const
|
||||
{
|
||||
return AssetMetadata(path).get_guid();
|
||||
}
|
||||
|
||||
std::shared_ptr<AssetFile> AssetDatabase::open_asset_file(const std::wstring& path)
|
||||
{
|
||||
return std::make_shared<AssetFile>(file_to_guid(path), path);
|
||||
}
|
||||
|
||||
std::shared_ptr<Object> AssetDatabase::LoadReference(const AssetFileLink& link)
|
||||
{
|
||||
return LoadObject(link);
|
||||
}
|
||||
|
||||
|
||||
std::wstring guid_to_path(Guid guid)
|
||||
{//TODO: fix hardcode
|
||||
return LR"(C:\Users\Sergey\Desktop\Assets\test.asset)";
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<AssetFile> AssetDatabase::OpenArchive(Guid guid)
|
||||
{ //TODO: fix hardcode
|
||||
if (open_archives.empty())
|
||||
{
|
||||
auto a = std::make_shared<AssetFile>(guid, guid_to_path(guid));
|
||||
a->input->LoadReferenceCallback = std::bind(&AssetDatabase::LoadReference, this, std::placeholders::_1);
|
||||
open_archives.push_back(a);
|
||||
}
|
||||
return open_archives[0];
|
||||
}
|
||||
|
||||
std::shared_ptr<Object> AssetDatabase::LoadObject(AssetFileLink link)
|
||||
{
|
||||
auto f = Object::Find(link);
|
||||
if (f != nullptr) { return f; }
|
||||
|
||||
auto archive = OpenArchive(link.fileGuid);
|
||||
archive->SeekToFile(link.localId);
|
||||
|
||||
std::wstring type_name;
|
||||
(*archive->input) << type_name;
|
||||
|
||||
auto obj = ObjectsFactory::instance().create_object(type_name);
|
||||
obj->SetLink(link);
|
||||
|
||||
obj->serialize(*archive->input);
|
||||
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef AssetDatabase_h__
|
||||
#define AssetDatabase_h__
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "AssetMetadata.h"
|
||||
#include "AssetImporter.h"
|
||||
#include "AssetFile.h"
|
||||
|
||||
|
||||
class AssetDatabase{
|
||||
public:
|
||||
static AssetDatabase& get() {
|
||||
static AssetDatabase instance;
|
||||
return instance;
|
||||
}
|
||||
static std::wstring asset_to_meta_path(const std::wstring& asset_path);
|
||||
Guid file_to_guid(const std::wstring& path) const;
|
||||
std::shared_ptr<AssetFile> open_asset_file(const std::wstring& path);
|
||||
void setRootPath(const std::wstring& path);
|
||||
static void register_importer(std::shared_ptr<AssetImporter> importer);
|
||||
std::shared_ptr<AssetImporter> find_importer(const std::wstring& asset_path) const;
|
||||
|
||||
std::shared_ptr<Object> LoadReference(const AssetFileLink& link);
|
||||
std::shared_ptr<AssetFile> OpenArchive(Guid guid);
|
||||
std::shared_ptr<Object> LoadObject(AssetFileLink link);
|
||||
|
||||
std::vector<std::shared_ptr<Object>> load_all_objects(std::shared_ptr<AssetFile> asset);
|
||||
|
||||
std::wstring getFullAssetPath(const std::string& localPath);
|
||||
private:
|
||||
std::vector<std::shared_ptr<AssetFile>> open_archives;
|
||||
AssetDatabase();
|
||||
std::vector<std::shared_ptr<AssetImporter>> _importers;
|
||||
std::wstring _rootAssetsPath;
|
||||
};
|
||||
#endif // AssetDatabase_h__
|
||||
@@ -0,0 +1,226 @@
|
||||
#ifndef AssetFile_h__
|
||||
#define AssetFile_h__
|
||||
|
||||
#include "InputArchive.h"
|
||||
#include "OutputArchive.h"
|
||||
#include "Asset.h"
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
|
||||
namespace fs = std::experimental::filesystem::v1;
|
||||
|
||||
class AssetObjectDescriptor : public Object {
|
||||
public:
|
||||
uint64_t localId;
|
||||
int64_t offset;
|
||||
uint64_t length;
|
||||
AssetObjectDescriptor():localId(0), offset(0), length(0)
|
||||
{
|
||||
|
||||
}
|
||||
AssetObjectDescriptor(uint64_t _localId, int64_t _offset, uint64_t _length):localId(_localId), offset(_offset), length(_length){
|
||||
|
||||
}
|
||||
virtual void serialize(Archive& archive) override {
|
||||
archive << localId << offset << length;
|
||||
}
|
||||
virtual std::wstring get_type_name() const override {
|
||||
return L"AssetObjectDescriptor";
|
||||
}
|
||||
};
|
||||
|
||||
class AssetObjectsTable : public Object{
|
||||
public:
|
||||
uint64_t lastId;
|
||||
std::vector<AssetObjectDescriptor> objects;
|
||||
|
||||
AssetObjectsTable():lastId(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool GetFileDescriptor(uint64_t localId, AssetObjectDescriptor& desc){
|
||||
for (auto& o : objects) {
|
||||
if (o.localId == localId) {
|
||||
desc = o;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Contains(uint64_t localId) const {
|
||||
for (auto& o : objects) {
|
||||
if (o.localId == localId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void serialize(Archive& archive) override {
|
||||
archive << lastId;
|
||||
if(archive.is_loading()){
|
||||
uint64_t objectsCount = 0;
|
||||
archive << objectsCount;
|
||||
objects.clear();
|
||||
for(uint64_t i = 0; i < objectsCount; ++i){
|
||||
AssetObjectDescriptor d;
|
||||
d.serialize(archive);
|
||||
objects.push_back(d);
|
||||
}
|
||||
}else{
|
||||
uint64_t objectsCount = objects.size();
|
||||
archive << objectsCount;
|
||||
for (auto& o : objects){
|
||||
o.serialize(archive);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual std::wstring get_type_name() const override {
|
||||
return L"AssetObjectsTable";
|
||||
}
|
||||
};
|
||||
|
||||
inline std::shared_ptr<OutputArchive> CreateMemoryOutArchive(){
|
||||
return std::make_shared<OutputArchive>(std::make_shared<std::stringstream>(std::ios::in | std::ios::out | std::ios::binary));
|
||||
}
|
||||
|
||||
class AssetFile {
|
||||
public:
|
||||
typedef uint64_t table_offset_t;
|
||||
AssetObjectsTable objectsTable;
|
||||
std::shared_ptr<InputArchive> input;
|
||||
std::shared_ptr<OutputArchive> output;
|
||||
std::shared_ptr<std::fstream> stream;
|
||||
|
||||
AssetFile(Guid fileGuid, const std::wstring& path):_fileGuid(fileGuid), _path(path){
|
||||
OpenFile(false);
|
||||
|
||||
if(stream->is_open()){
|
||||
stream->seekg(0, std::ios::end);
|
||||
if((int)stream->tellg() == 0){
|
||||
std::cout << "Empty asset created!" << std::endl;
|
||||
SaveFooter();
|
||||
}
|
||||
ReadFooter();
|
||||
}
|
||||
//input = std::make_shared<InputArchive>(path);
|
||||
}
|
||||
|
||||
void OpenFile(bool trunc){
|
||||
input = nullptr;
|
||||
output = nullptr;
|
||||
stream = std::make_shared<std::fstream>(_path, (trunc ? std::ios::trunc : std::ios::app) | std::ios::in | std::ios::out | std::ios::binary);
|
||||
if (stream->is_open()) {
|
||||
input = std::make_shared<InputArchive>(stream);
|
||||
output = std::make_shared<OutputArchive>(stream);
|
||||
}
|
||||
}
|
||||
|
||||
void CloseFile()
|
||||
{
|
||||
input = nullptr;
|
||||
output = nullptr;
|
||||
if(stream != nullptr && stream->is_open()){
|
||||
stream->close();
|
||||
}
|
||||
stream = nullptr;
|
||||
}
|
||||
|
||||
void Save(){
|
||||
auto tmpOut = CreateMemoryOutArchive();
|
||||
//save objects
|
||||
int64_t objectOffset = 0;
|
||||
for(auto& v : objectsTable.objects){
|
||||
auto object = Object::Find(AssetFileLink(_fileGuid, v.localId));
|
||||
|
||||
v.offset = objectOffset;
|
||||
|
||||
auto startOffset = objectOffset = tmpOut->GetStream()->tellp();
|
||||
//save all loaded objects, copy not loaded
|
||||
if(object != nullptr){
|
||||
auto typeName = object->get_type_name();
|
||||
(*tmpOut) << typeName;
|
||||
object->serialize(*tmpOut);
|
||||
}else{
|
||||
stream->seekg(v.offset, std::ios::beg);
|
||||
std::vector<uint8_t> objectBytes(v.length);
|
||||
stream->read((char*)&objectBytes[0], objectBytes.size());
|
||||
tmpOut->GetStream()->write((char*)&objectBytes[0], objectBytes.size());
|
||||
}
|
||||
objectOffset = tmpOut->GetStream()->tellp();
|
||||
v.length = objectOffset - startOffset;
|
||||
}
|
||||
|
||||
CloseFile();
|
||||
OpenFile(true);
|
||||
|
||||
auto content = std::static_pointer_cast<std::stringstream>(tmpOut->GetStream())->str();
|
||||
stream->write(&content[0], content.size());
|
||||
stream->seekg(0, std::ios::end);
|
||||
//save footer
|
||||
SaveFooter();
|
||||
}
|
||||
|
||||
bool SeekToFile(uint64_t fileId) {
|
||||
AssetObjectDescriptor desc;
|
||||
if (objectsTable.GetFileDescriptor(fileId, desc)) {
|
||||
if (desc.offset >= 0) {
|
||||
stream->seekg(desc.offset, std::ios::beg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ReadFooter()
|
||||
{
|
||||
std::cout << "Read footer" << std::endl;
|
||||
//read table offset
|
||||
auto off = -((std::streamoff)sizeof(table_offset_t));
|
||||
stream->seekg(off, std::ios::end);
|
||||
table_offset_t offset = 0;
|
||||
(*input) << offset;
|
||||
|
||||
auto table_file_offset = off - (std::streamoff)offset;
|
||||
stream->seekg(table_file_offset, std::ios::end);
|
||||
objectsTable.serialize(*input);
|
||||
}
|
||||
|
||||
void SaveFooter(){
|
||||
std::cout << "Save footer" << std::endl;
|
||||
stream->seekg(0, std::ios::end);
|
||||
auto tmpArchive = CreateMemoryOutArchive();
|
||||
objectsTable.serialize(*tmpArchive);
|
||||
auto data = std::static_pointer_cast<std::stringstream>(tmpArchive->GetStream())->str();
|
||||
table_offset_t size = data.size();
|
||||
stream->write(&data[0], size);
|
||||
(*output) << size;
|
||||
|
||||
output->flush();
|
||||
}
|
||||
|
||||
void AddObject(std::shared_ptr<Object> obj){
|
||||
if (obj->GetFileLink().IsValid()) {
|
||||
if (obj->GetFileLink().fileGuid == _fileGuid) {
|
||||
std::wcout << "Object " << obj->get_name() << " is already in current asset. Can't add twice" << std::endl;
|
||||
} else {
|
||||
std::wcout << "Object " << obj->get_name() << " is already in another asset. Can't add." << std::endl;
|
||||
}
|
||||
} else {
|
||||
obj->SetLink(AssetFileLink(_fileGuid, objectsTable.lastId++));
|
||||
objectsTable.objects.push_back(AssetObjectDescriptor(obj->GetFileLink().localId, 0, 0));
|
||||
}
|
||||
}
|
||||
const Guid& guid() const
|
||||
{
|
||||
return _fileGuid;
|
||||
}
|
||||
private:
|
||||
Guid _fileGuid;
|
||||
std::wstring _path;
|
||||
};
|
||||
|
||||
#endif // AssetFile_h__
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
class AssetImporter {
|
||||
public:
|
||||
virtual void import(std::wstring asset_path) = 0;
|
||||
virtual bool can_import(const std::wstring& path) const = 0;
|
||||
virtual bool set_parameters(std::wstring params) = 0;
|
||||
virtual std::wstring get_parameters() const = 0;
|
||||
virtual std::wstring name() = 0;
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "AssetManager.h"
|
||||
#include "LEngine.h"
|
||||
#include "Texture.h"
|
||||
|
||||
std::shared_ptr<AssetManager> AssetManager::_instance = nullptr;
|
||||
|
||||
TexturePtr AssetManager::LoadTexture(const std::wstring& path) const
|
||||
{
|
||||
return {};
|
||||
/*
|
||||
auto renderer = LEngine::Instance()->GetRenderer();
|
||||
auto device = renderer->GetDevice();
|
||||
|
||||
ID3D12ResourcePtr resource;
|
||||
|
||||
std::unique_ptr<uint8_t[]> data;
|
||||
std::vector<D3D12_SUBRESOURCE_DATA> srData;
|
||||
DirectX::LoadDDSTextureFromFile(device.Get(), GetFullAssetPath(path).c_str(), &resource, data, srData);
|
||||
|
||||
//auto cmdList = renderer->BeginCommandList();
|
||||
|
||||
|
||||
//create upload heap
|
||||
D3D12_RESOURCE_DESC desc;
|
||||
desc = resource->GetDesc();
|
||||
|
||||
UINT64 textureUploadBufferSize;
|
||||
device->GetCopyableFootprints(&desc, 0, srData.size(), 0, nullptr, nullptr, nullptr, &textureUploadBufferSize);
|
||||
|
||||
// now we create an upload heap to upload our texture to the GPU
|
||||
ID3D12ResourcePtr textureBufferUploadHeap;
|
||||
auto hr = device->CreateCommittedResource(
|
||||
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), // upload heap
|
||||
D3D12_HEAP_FLAG_NONE, // no flags
|
||||
&CD3DX12_RESOURCE_DESC::Buffer(textureUploadBufferSize), // resource description for a buffer (storing the image data in this heap just to copy to the default heap)
|
||||
D3D12_RESOURCE_STATE_GENERIC_READ, // We will copy the contents from this heap to the default heap above
|
||||
nullptr,
|
||||
IID_PPV_ARGS(&textureBufferUploadHeap));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
FatalError(L"Failed to create upload heap");
|
||||
}
|
||||
textureBufferUploadHeap->SetName(L"Texture Buffer Upload Resource Heap");
|
||||
|
||||
auto commandList = renderer->BeginCommandList();
|
||||
//copy subresource
|
||||
UpdateSubresources(commandList.Get(), resource.Get(), textureBufferUploadHeap.Get(), 0, 0, srData.size(), &srData[0]);
|
||||
commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(resource.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
|
||||
|
||||
|
||||
renderer->EndCommandList();
|
||||
renderer->WaitCommandsQueue();
|
||||
|
||||
//create shader resource view
|
||||
auto srvMemory = renderer->getSrvDescriptorsAllocator()->alloc();
|
||||
|
||||
D3D12_RESOURCE_DESC texDesc;
|
||||
texDesc = resource->GetDesc();
|
||||
|
||||
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
|
||||
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
||||
srvDesc.Format = texDesc.Format;
|
||||
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
||||
srvDesc.Texture2D.MipLevels = texDesc.MipLevels;
|
||||
device->CreateShaderResourceView(resource.Get(), &srvDesc, srvMemory);
|
||||
|
||||
|
||||
auto result = std::make_shared<Texture>(resource, srvMemory);
|
||||
|
||||
//DirectX::CreateTexture(renderer->GetDevice(), image.GetImages(), image.GetImageCount(), metadata, &resource);
|
||||
return result;*/
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "Texture.h"
|
||||
#include "ForwardDeclarations.h"
|
||||
|
||||
class AssetManager {
|
||||
public:
|
||||
static std::shared_ptr<AssetManager> Instance() {
|
||||
if (_instance == nullptr) {
|
||||
_instance = std::make_shared<AssetManager>();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
void SetAssetsFolder(const std::wstring& folder) {
|
||||
_assetsFolder = folder;
|
||||
}
|
||||
|
||||
std::wstring GetFullAssetPath(const std::wstring& relativePath) const
|
||||
{
|
||||
return _assetsFolder + relativePath;
|
||||
}
|
||||
TexturePtr LoadTexture(const std::wstring& path) const;
|
||||
private:
|
||||
static std::shared_ptr<AssetManager> _instance;
|
||||
std::wstring _assetsFolder;
|
||||
};
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "AssetMetadata.h"
|
||||
#include <fstream>
|
||||
#include <combaseapi.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "AssetDatabase.h"
|
||||
#include <Windows.h>
|
||||
#include <wrl.h>
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
AssetMetadata::AssetMetadata(const std::wstring& asset_path) : _asset_path(asset_path) {
|
||||
_meta_path = AssetDatabase::asset_to_meta_path(_asset_path);
|
||||
|
||||
if (std::filesystem::exists(std::filesystem::path(_meta_path))) {
|
||||
Load();
|
||||
} else {
|
||||
create();
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
void AssetMetadata::create() {
|
||||
CoCreateGuid((GUID*)&_guid);
|
||||
_modification_time = std::filesystem::last_write_time(std::filesystem::path(_asset_path)).time_since_epoch().count();
|
||||
_importer = AssetDatabase::get().find_importer(_asset_path);
|
||||
}
|
||||
|
||||
void AssetMetadata::Load() {
|
||||
std::wifstream file(_meta_path);
|
||||
|
||||
std::wstring v;
|
||||
std::getline(file, v);
|
||||
|
||||
std::wstring guid_str;
|
||||
std::getline(file, guid_str);
|
||||
_guid = str_to_guid(guid_str);
|
||||
|
||||
std::wstring time_str;
|
||||
std::getline(file, time_str);
|
||||
_modification_time = std::stoull(time_str);
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void AssetMetadata::Save() {
|
||||
std::wofstream file;
|
||||
file.open(_meta_path, std::ios::trunc);
|
||||
file << version << std::endl;
|
||||
file << guid_to_str(_guid) << std::endl;
|
||||
file << _modification_time << std::endl;
|
||||
//file << _importer->name();
|
||||
file.close();
|
||||
}
|
||||
|
||||
Guid AssetMetadata::str_to_guid(const std::wstring& guid) {
|
||||
Guid iid;
|
||||
IIDFromString(guid.c_str(), (GUID*)&iid);
|
||||
return iid;
|
||||
}
|
||||
|
||||
std::wstring AssetMetadata::guid_to_str(const Guid& guid) {
|
||||
LPOLESTR guid_str = nullptr;
|
||||
StringFromIID(*((const GUID*)&guid), &guid_str);
|
||||
|
||||
//Microsoft::WRL::Wrappers::HStringReference
|
||||
|
||||
std::wstring result(guid_str);
|
||||
CoTaskMemFree(guid_str);
|
||||
return result;
|
||||
}
|
||||
|
||||
const Guid& AssetMetadata::get_guid() const {
|
||||
return _guid;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef AssetMetadata_h__
|
||||
#define AssetMetadata_h__
|
||||
|
||||
#include <filesystem>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include "Guid.h"
|
||||
#include "AssetImporter.h"
|
||||
|
||||
class AssetMetadata {
|
||||
public:
|
||||
typedef uint64_t file_time_t;
|
||||
const std::wstring version = L"1.0";
|
||||
|
||||
AssetMetadata(const std::wstring& asset_path);
|
||||
void Save();
|
||||
void Load();
|
||||
static std::wstring guid_to_str(const Guid& guid);
|
||||
static Guid str_to_guid(const std::wstring& guid);
|
||||
const Guid& get_guid() const;
|
||||
private:
|
||||
std::shared_ptr<AssetImporter> _importer;
|
||||
void create();
|
||||
std::wstring _asset_path;
|
||||
std::wstring _meta_path;
|
||||
file_time_t _modification_time;
|
||||
Guid _guid;
|
||||
};
|
||||
#endif // AssetMetadata_h__
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef Bounds_h__
|
||||
#define Bounds_h__
|
||||
|
||||
#include <lmath/lmath.h>
|
||||
using namespace lm;
|
||||
|
||||
class Bounds {
|
||||
public:
|
||||
Bounds()
|
||||
:_center(0.0f,0.0f,0.0f), _size(0.0f,0.0f,0.0f) {
|
||||
|
||||
}
|
||||
Bounds(float3 center, float3 size)
|
||||
:_center(center), _size(size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float3 GetSize() {
|
||||
return _size;
|
||||
}
|
||||
float3 GetCenter() {
|
||||
return _center;
|
||||
}
|
||||
void SetSize(const float3& size) {
|
||||
_size = size;
|
||||
}
|
||||
void SetCenter(const float3& center) {
|
||||
_center = center;
|
||||
}
|
||||
void Scale(float value) {
|
||||
_size *= value;
|
||||
}
|
||||
float3 Minimum() const {
|
||||
return _size * -0.5f + _center;
|
||||
}
|
||||
float3 Maximum() const {
|
||||
return _size * 0.5f + _center;
|
||||
}
|
||||
private:
|
||||
float3 _center;
|
||||
float3 _size;
|
||||
};
|
||||
#endif // Bounds_h__
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "Camera.h"
|
||||
#include "Transform.h"
|
||||
#include "Mathf.h"
|
||||
#include "Archive.h"
|
||||
|
||||
float4x4 Camera::worldToCameraMatrix() {
|
||||
auto world = transform()->GetGlobalTransform();
|
||||
|
||||
//TODO: why not affine ?
|
||||
world = inverse(world, false);
|
||||
|
||||
// auto test = lookatlh(transform()->GetGlobalPosition(), float3(0, 1, 1), float3(0, 1, 0));
|
||||
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Camera::serialize(Archive& archive) {
|
||||
Component::serialize(archive);
|
||||
archive << nearClipPlane << farClipPlane << fov << aspect;
|
||||
}
|
||||
|
||||
void Camera::UpdateProjectionMatrix() {
|
||||
_projection = matrix4x4Perspective(fov * Mathf::DegToRad(), aspect, nearClipPlane, farClipPlane);
|
||||
}
|
||||
|
||||
float4x4 Camera::projectionMatrix() {
|
||||
UpdateProjectionMatrix();
|
||||
return _projection;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef Camera_h__
|
||||
#define Camera_h__
|
||||
|
||||
#include "ObjectsFactory.h"
|
||||
#include <lmath/lmath.h>
|
||||
#include "Component.h"
|
||||
using namespace lm;
|
||||
|
||||
LOBJECT(Camera, Component)
|
||||
public:
|
||||
float nearClipPlane = 0.03f;
|
||||
float farClipPlane = 100.0f;
|
||||
float fov = 45.0f;
|
||||
float aspect = 1.333333333f;
|
||||
|
||||
virtual void serialize(Archive& archive) override;
|
||||
|
||||
float4x4 worldToCameraMatrix();
|
||||
float4x4 projectionMatrix();
|
||||
void test() {
|
||||
construct();
|
||||
}
|
||||
private:
|
||||
float4x4 _projection;
|
||||
void UpdateProjectionMatrix();
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Camera> CameraPtr;
|
||||
#endif // Camera_h__
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "Component.h"
|
||||
#include "GameObject.h"
|
||||
|
||||
TransformPtr Component::transform() {
|
||||
return gameObject->transform;
|
||||
}
|
||||
|
||||
void Component::serialize(Archive& archive) {
|
||||
auto ptr = std::static_pointer_cast<Object>(gameObject);
|
||||
archive << ptr;
|
||||
|
||||
if (archive.is_loading()) {
|
||||
gameObject = std::static_pointer_cast<GameObject>(ptr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef Component_h__
|
||||
#define Component_h__
|
||||
|
||||
#include <memory>
|
||||
#include "ObjectsFactory.h"
|
||||
|
||||
LOBJECT(Component, Object)
|
||||
public:
|
||||
GameObjectPtr gameObject;
|
||||
TransformPtr transform();
|
||||
virtual void tick(float deltaTime) {}
|
||||
Component(){}
|
||||
|
||||
void serialize(Archive& archive) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // Component_h__
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef FatalError_h__
|
||||
#define FatalError_h__
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
inline void FatalError(const TCHAR* message) {
|
||||
int b1 = 12750;
|
||||
int b2 = 4750;
|
||||
int len = 80;
|
||||
|
||||
for(int i = 0; i < 2; ++i) {
|
||||
Beep(b1, len);
|
||||
Beep(b2, len);
|
||||
}
|
||||
|
||||
MessageBox(NULL, message, TEXT("Error"), MB_OK);
|
||||
exit(0);
|
||||
}
|
||||
#endif // FatalError_h__
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef File_h__
|
||||
#define File_h__
|
||||
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
uint32_t FileSize(const std::wstring& path) {
|
||||
std::ifstream file(path, std::ios_base::binary);
|
||||
if (!file.good()) {
|
||||
return 0;
|
||||
}
|
||||
std::streampos current_position = file.tellg();
|
||||
file.seekg(0, std::ios::end);
|
||||
std::streampos ending_position = file.tellg();
|
||||
file.seekg(current_position);
|
||||
file.close();
|
||||
return (uint32_t)(ending_position - current_position);
|
||||
}
|
||||
|
||||
uint32_t FileSize(const std::string& path) {
|
||||
std::ifstream file(path, std::ios_base::binary);
|
||||
if (!file.good()) {
|
||||
return 0;
|
||||
}
|
||||
std::streampos current_position = file.tellg();
|
||||
file.seekg(0, std::ios::end);
|
||||
std::streampos ending_position = file.tellg();
|
||||
file.seekg(current_position);
|
||||
file.close();
|
||||
return (uint32_t)(ending_position - current_position);
|
||||
}
|
||||
|
||||
void FileReadAllText(const std::wstring& path, std::string& result) {
|
||||
auto size = FileSize(path);
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::ifstream file(path, std::ios::in);
|
||||
result.reserve(size);
|
||||
result.assign(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
|
||||
file.close();
|
||||
}
|
||||
|
||||
void FileReadAllBytes(const std::wstring& path, std::vector<char>& result) {
|
||||
auto size = FileSize(path);
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::ifstream file(path, std::ios::in | std::ios::binary);
|
||||
result.reserve(size);
|
||||
result.assign(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
|
||||
file.close();
|
||||
}
|
||||
|
||||
void FileReadAllBytes(const std::string& path, std::vector<char>& result) {
|
||||
auto size = FileSize(path);
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::ifstream file(path, std::ios::in | std::ios::binary);
|
||||
result.reserve(size);
|
||||
result.assign(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
#endif // File_h__
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef Filesystem_h__
|
||||
#define Filesystem_h__
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class Filesystem {
|
||||
public:
|
||||
//static std::shared_ptr<Filesystem> Create(const std::string& assetsFolder);
|
||||
|
||||
private:
|
||||
//Filesystem();
|
||||
};
|
||||
#endif // Filesystem_h__
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <lmath/lmath.h>
|
||||
|
||||
class GameObject;
|
||||
typedef std::shared_ptr<GameObject> GameObjectPtr;
|
||||
|
||||
class Component;
|
||||
typedef std::shared_ptr<Component> ComponentPtr;
|
||||
|
||||
class Scene;
|
||||
typedef std::shared_ptr<Scene> ScenePtr;
|
||||
|
||||
class Transform;
|
||||
typedef std::shared_ptr<Transform> TransformPtr;
|
||||
|
||||
class Shader;
|
||||
typedef std::shared_ptr<Shader> ShaderPtr;
|
||||
|
||||
class Mesh;
|
||||
typedef std::shared_ptr<Mesh> MeshPtr;
|
||||
|
||||
class Material;
|
||||
typedef std::shared_ptr<Material> MaterialPtr;
|
||||
|
||||
class Mouse;
|
||||
typedef std::shared_ptr<Mouse> MousePtr;
|
||||
|
||||
class Keyboard;
|
||||
typedef std::shared_ptr<Keyboard> KeyboardPtr;
|
||||
|
||||
class Texture;
|
||||
typedef std::shared_ptr<Texture> TexturePtr;
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef ForwardListItem_h__
|
||||
#define ForwardListItem_h__
|
||||
|
||||
class ForwardListItem{
|
||||
public:
|
||||
ForwardListItem* next;
|
||||
};
|
||||
#endif // ForwardListItem_h__
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
#include "Transform.h"
|
||||
#include "LEngine.h"
|
||||
#include "Component.h"
|
||||
#include "GameObject.h"
|
||||
|
||||
void GameObject::tick(float deltaTime) {
|
||||
for (auto c : components) {
|
||||
c->tick(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void GameObject::construct2() {
|
||||
Object::construct();
|
||||
auto this_ptr = std::static_pointer_cast<GameObject>(shared_from_this());
|
||||
LEngine::Instance()->GetActiveScene()->objects.push_back(this_ptr);
|
||||
this_ptr->transform = this_ptr->AddComponent<Transform>();
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
#ifndef GameObject___h__
|
||||
#define GameObject___h__
|
||||
|
||||
#include "ForwardDeclarations.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <typeinfo>
|
||||
#include "ObjectsFactory.h"
|
||||
#include "OutputArchive.h"
|
||||
#include "Transform.h"
|
||||
|
||||
LOBJECT(GameObject, Object)
|
||||
public:
|
||||
TransformPtr transform;
|
||||
|
||||
void tick(float deltaTime);
|
||||
|
||||
virtual void serialize(Archive& archive) override {
|
||||
Object::serialize(archive);
|
||||
|
||||
if (archive.is_loading()) {
|
||||
components.clear();
|
||||
transform = nullptr;
|
||||
}
|
||||
|
||||
Archive::size_type cnt = components.size();
|
||||
archive << cnt;
|
||||
|
||||
if (archive.is_loading()) {
|
||||
for (Archive::size_type i = 0; i < cnt; ++i) {
|
||||
std::shared_ptr<Object> obj;
|
||||
archive << obj;
|
||||
components.push_back(std::static_pointer_cast<Component>(obj));
|
||||
|
||||
auto tp = std::dynamic_pointer_cast<Transform>(obj);
|
||||
if (tp != nullptr) {
|
||||
transform = tp;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (auto component : components) {
|
||||
auto ptr = std::static_pointer_cast<Object>(component);
|
||||
archive << ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<GameObject> as_game_object() {
|
||||
return std::static_pointer_cast<GameObject>(shared_from_this());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::shared_ptr<T> AddComponent() {
|
||||
auto component = T::create();
|
||||
component->gameObject = as_game_object();
|
||||
components.push_back(component);
|
||||
return component;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::shared_ptr<T> GetComponent() {
|
||||
for (auto c : components) {
|
||||
auto tmp = std::dynamic_pointer_cast<T>(c);
|
||||
if (tmp != nullptr) {
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::vector<std::shared_ptr<T>> GetComponents() {
|
||||
std::vector<std::shared_ptr<T>> result;
|
||||
for (auto c : components) {
|
||||
auto tmp = std::dynamic_pointer_cast<T>(c);
|
||||
if (tmp != nullptr) {
|
||||
result.push_back(tmp);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void construct() override {
|
||||
construct2();
|
||||
}
|
||||
void construct2();
|
||||
|
||||
private:
|
||||
GameObject() {}
|
||||
std::vector<ComponentPtr> components;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // GameObject___h__
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef GizmoVertex_h__
|
||||
#define GizmoVertex_h__
|
||||
|
||||
#include <lmath/lmath.h>
|
||||
|
||||
using namespace lm;
|
||||
|
||||
struct GizmoVertex {
|
||||
float4 position;
|
||||
float4 color;
|
||||
|
||||
GizmoVertex(float4 _position, float4 _color)
|
||||
:position(_position), color(_color)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GizmoVertex(float3 _position, float4 _color)
|
||||
:position(_position.x(), _position.y(), _position.z(), 1.0f), color(_color)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
#endif // GizmoVertex_h__
|
||||
@@ -0,0 +1,130 @@
|
||||
#include "Gizmos.h"
|
||||
#include "GameObject.h"
|
||||
#include "LEngine.h"
|
||||
#include "LEngine.h"
|
||||
|
||||
Gizmos::Gizmos()
|
||||
:_color(0.0f, 1.0f, 0.0f, 1.0f)
|
||||
{
|
||||
_matrix = float4x4::identity();
|
||||
}
|
||||
void Gizmos::SetMatrix(const float4x4& matrix) {
|
||||
_matrix = matrix;
|
||||
}
|
||||
float4x4 Gizmos::GetMatrix() {
|
||||
return _matrix;
|
||||
}
|
||||
void Gizmos::DrawBounds(const Bounds& bounds) {
|
||||
auto b = bounds;
|
||||
b.Scale(1.01f);
|
||||
auto bMin = b.Minimum();
|
||||
auto bMax = b.Maximum();
|
||||
|
||||
DrawLine(float3(bMin.x(), bMax.y(), bMax.z()), float3(bMax.x(), bMax.y(), bMax.z()));
|
||||
DrawLine(float3(bMin.x(), bMax.y(), bMin.z()), float3(bMax.x(), bMax.y(), bMin.z()));
|
||||
DrawLine(float3(bMin.x(), bMax.y(), bMax.z()), float3(bMin.x(), bMax.y(), bMin.z()));
|
||||
DrawLine(float3(bMax.x(), bMax.y(), bMax.z()), float3(bMax.x(), bMax.y(), bMin.z()));
|
||||
|
||||
DrawLine(float3(bMin.x(), bMin.y(), bMax.z()), float3(bMax.x(), bMin.y(), bMax.z()));
|
||||
DrawLine(float3(bMin.x(), bMin.y(), bMin.z()), float3(bMax.x(), bMin.y(), bMin.z()));
|
||||
DrawLine(float3(bMin.x(), bMin.y(), bMax.z()), float3(bMin.x(), bMin.y(), bMin.z()));
|
||||
DrawLine(float3(bMax.x(), bMin.y(), bMax.z()), float3(bMax.x(), bMin.y(), bMin.z()));
|
||||
|
||||
DrawLine(float3(bMin.x(), bMin.y(), bMin.z()), float3(bMin.x(), bMax.y(), bMin.z()));
|
||||
DrawLine(float3(bMax.x(), bMin.y(), bMin.z()), float3(bMax.x(), bMax.y(), bMin.z()));
|
||||
|
||||
DrawLine(float3(bMin.x(), bMin.y(), bMax.z()), float3(bMin.x(), bMax.y(), bMax.z()));
|
||||
DrawLine(float3(bMax.x(), bMin.y(), bMax.z()), float3(bMax.x(), bMax.y(), bMax.z()));
|
||||
|
||||
}
|
||||
void Gizmos::Init() {
|
||||
/*_backMaterial = Material::Create(Shader::Create(L"shaders/gizmos.fx"), "gizmo_back");
|
||||
|
||||
_frontMaterial = Material::Create(_backMaterial->GetShader(), "gizmo_front");
|
||||
|
||||
_backMaterial->GetParametersBlock().SetValue("alphaMul", 0.2f);
|
||||
_frontMaterial->GetParametersBlock().SetValue("alphaMul", 1.0f);
|
||||
|
||||
D3D11_INPUT_ELEMENT_DESC ied[] = {
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
|
||||
auto vs = _backMaterial->GetShader()->GetShader(ShaderType::Vs);
|
||||
auto device = LEngine::Instance()->GetRenderer()->GetDevice();
|
||||
auto hr = device->CreateInputLayout(ied, 2, vs->blob->GetBufferPointer(), vs->blob->GetBufferSize(), &_inputLayout);
|
||||
|
||||
D3D11_DEPTH_STENCIL_DESC desc;
|
||||
d3d11_helper::DefaultDepthStencilDesc(desc);
|
||||
hr = device->CreateDepthStencilState(&desc, &_frontLineDepthState);
|
||||
desc.DepthFunc = D3D11_COMPARISON_GREATER;
|
||||
hr = device->CreateDepthStencilState(&desc, &_backLineDepthState);*/
|
||||
}
|
||||
void Gizmos::DrawLine(const float3& from, const float3& to) {
|
||||
/*_vertices.push_back(GizmoVertex(lm::mul(_matrix, from), _color));
|
||||
_vertices.push_back(GizmoVertex(lm::mul(_matrix, to), _color));*/
|
||||
}
|
||||
void Gizmos::DrawAll(CameraPtr camera) {
|
||||
/*auto renderer = LEngine::Instance()->GetRenderer();
|
||||
|
||||
renderer->GetImmediateContext()->OMSetDepthStencilState(_frontLineDepthState, 0);
|
||||
DrawImpl(camera, _frontMaterial);
|
||||
renderer->GetImmediateContext()->OMSetDepthStencilState(_backLineDepthState, 0);
|
||||
DrawImpl(camera, _backMaterial);
|
||||
renderer->GetImmediateContext()->OMSetDepthStencilState(_frontLineDepthState, 0);*/
|
||||
}
|
||||
void Gizmos::DrawImpl(CameraPtr camera, MaterialPtr material) {
|
||||
/*if (_vertices.size() < 2) {
|
||||
return;
|
||||
}
|
||||
//set system variables
|
||||
auto& params = material->GetParametersBlock();
|
||||
float4x4 matrix = float4x4::identity();
|
||||
params.SetValue("mWorld", matrix);
|
||||
params.SetValue("mView", camera->worldToCameraMatrix());
|
||||
params.SetValue("mProjection", camera->projectionMatrix());
|
||||
|
||||
auto renderer = LEngine::Instance()->GetRenderer();
|
||||
|
||||
material->Apply(renderer->GetImmediateContext());
|
||||
|
||||
ID3D11Buffer* vb[1] = { _vertexBuffer };
|
||||
UINT stride = sizeof(GizmoVertex);
|
||||
UINT offset = 0;
|
||||
|
||||
renderer->GetImmediateContext()->IASetInputLayout(_inputLayout);
|
||||
renderer->GetImmediateContext()->IASetVertexBuffers(0, 1, vb, &stride, &offset);
|
||||
renderer->GetImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
|
||||
renderer->GetImmediateContext()->Draw(_vertices.size(), 0);*/
|
||||
}
|
||||
void Gizmos::Clear() {
|
||||
/*_vertices.clear();
|
||||
_matrix = float4x4::identity();*/
|
||||
}
|
||||
void Gizmos::PrepareRender() {
|
||||
/*_vertexBuffer = nullptr;
|
||||
|
||||
if (_vertices.size() < 2) {
|
||||
return;
|
||||
}
|
||||
//vertex buffer
|
||||
D3D11_BUFFER_DESC desc = { 0 };
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.ByteWidth = sizeof(_vertices[0])* _vertices.size();
|
||||
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA data;
|
||||
data.pSysMem = &_vertices[0];
|
||||
data.SysMemPitch = 0;
|
||||
|
||||
_vertexBuffer = nullptr;
|
||||
LEngine::Instance()->GetRenderer()->GetDevice()->CreateBuffer(&desc, &data, &_vertexBuffer);*/
|
||||
}
|
||||
float4 Gizmos::GetColor() {
|
||||
return _color;
|
||||
}
|
||||
void Gizmos::SetColor(float4 color) {
|
||||
_color = color;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "GizmoVertex.h"
|
||||
#include <vector>
|
||||
#include "Material.h"
|
||||
#include "Shader.h"
|
||||
#include <lmath/lmath.h>
|
||||
#include "Camera.h"
|
||||
#include "Bounds.h"
|
||||
|
||||
using namespace lm;
|
||||
|
||||
class Gizmos {
|
||||
public:
|
||||
Gizmos();
|
||||
void Init();
|
||||
void DrawLine(const float3& from, const float3& to);
|
||||
void DrawBounds(const Bounds& bounds);
|
||||
void DrawAll(CameraPtr camera);
|
||||
void Clear();
|
||||
void PrepareRender();
|
||||
float4 GetColor();
|
||||
void SetColor(float4 color);
|
||||
void SetMatrix(const float4x4& matrix);
|
||||
float4x4 GetMatrix();
|
||||
private:
|
||||
void DrawImpl(CameraPtr camera, MaterialPtr material);
|
||||
//ID3D11InputLayoutPtr _inputLayout;
|
||||
//ID3D11BufferPtr _vertexBuffer;
|
||||
//ID3D11DepthStencilStatePtr _backLineDepthState;
|
||||
//ID3D11DepthStencilStatePtr _frontLineDepthState;
|
||||
MaterialPtr _backMaterial;
|
||||
MaterialPtr _frontMaterial;
|
||||
float4 _color;
|
||||
float4x4 _matrix;
|
||||
std::vector<GizmoVertex> _vertices;
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef Guid_h__
|
||||
#define Guid_h__
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
struct Guid {
|
||||
union {
|
||||
std::array<uint8_t, 16> data;
|
||||
std::array<uint32_t, 4> datai;
|
||||
};
|
||||
|
||||
Guid() :datai{ 0,0,0,0 } {
|
||||
|
||||
}
|
||||
Guid(uint32_t i0, uint32_t i1, uint32_t i2, uint32_t i3) : datai{ i0,i1,i2,i3 } {
|
||||
|
||||
}
|
||||
Guid(const std::array<uint32_t, 4>& data_i) : datai(data_i) {
|
||||
|
||||
}
|
||||
Guid(const std::array<uint8_t, 16>& data) : data(data) {
|
||||
|
||||
}
|
||||
Guid(const Guid& guid) : data(guid.data) {
|
||||
|
||||
}
|
||||
Guid& operator =(const Guid& right) {
|
||||
data = right.data;
|
||||
return *this;
|
||||
}
|
||||
bool operator ==(const Guid& right) const {
|
||||
return std::equal(data.begin(), data.end(), right.data.begin());
|
||||
}
|
||||
bool operator !=(const Guid& right) const {
|
||||
return !std::equal(data.begin(), data.end(), right.data.begin());
|
||||
}
|
||||
bool IsZero() const {
|
||||
return (datai[0] == 0) && (datai[1] == 0) && (datai[2] == 0) && (datai[3] == 0);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // Guid_h__
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef InputArchive_h__
|
||||
#define InputArchive_h__
|
||||
|
||||
|
||||
#include "Archive.h"
|
||||
#include "Object.h"
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
class InputArchive : public Archive {
|
||||
public:
|
||||
InputArchive(std::shared_ptr<std::istream> stream)
|
||||
:_stream(stream) {
|
||||
}
|
||||
|
||||
virtual bool is_loading() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void serialize(void* data, size_t size) override {
|
||||
|
||||
_stream->read(reinterpret_cast<char*>(data), size);
|
||||
if(!_stream)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
size_type get_offset() const override
|
||||
{
|
||||
return _stream->tellg();
|
||||
}
|
||||
|
||||
void set_offset(size_type offset) override {
|
||||
_stream->seekg(offset, std::ios::beg);
|
||||
}
|
||||
|
||||
~InputArchive() {}
|
||||
|
||||
std::shared_ptr<std::istream> GetStream(){
|
||||
return _stream;
|
||||
}
|
||||
private:
|
||||
std::shared_ptr<std::istream> _stream;
|
||||
};
|
||||
|
||||
#endif // InputArchive_h__
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "LEngine.h"
|
||||
#include "AssetManager.h"
|
||||
|
||||
std::shared_ptr<LEngine> LEngine::_instance = nullptr;
|
||||
|
||||
std::shared_ptr<LEngine> LEngine::Instance() {
|
||||
if (_instance == nullptr) {
|
||||
_instance = std::shared_ptr<LEngine>(new LEngine());
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
ScenePtr LEngine::GetActiveScene() {
|
||||
return _activeScene;
|
||||
}
|
||||
|
||||
void LEngine::Init(const std::wstring& assetsPath) {
|
||||
AssetManager::Instance()->SetAssetsFolder(assetsPath);
|
||||
_renderer->Init();
|
||||
}
|
||||
|
||||
void LEngine::LoadScene(const std::string& path) {
|
||||
_activeScene = nullptr;
|
||||
_activeScene = std::make_shared<Scene>();
|
||||
_activeScene->SetName("New scene");
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef Application_h__
|
||||
#define Application_h__
|
||||
|
||||
#include "Scene.h"
|
||||
#include "ForwardDeclarations.h"
|
||||
#include <string>
|
||||
#include "Renderer.h"
|
||||
#include "RenderOutput.h"
|
||||
|
||||
class LEngine {
|
||||
public:
|
||||
static std::shared_ptr<LEngine> Instance();
|
||||
friend class Scene;
|
||||
ScenePtr GetActiveScene();
|
||||
void LoadScene(const std::string& path);
|
||||
void Init(const std::wstring& assetsPath);
|
||||
RendererPtr& GetRenderer() {
|
||||
return _renderer;
|
||||
}
|
||||
void AddOutput(RenderOutputPtr output) {
|
||||
_outputs.push_back(output);
|
||||
}
|
||||
std::vector<RenderOutputPtr> GetOutputs() {
|
||||
return _outputs;
|
||||
}
|
||||
private:
|
||||
LEngine()
|
||||
{
|
||||
_renderer = std::make_shared<Renderer>();
|
||||
}
|
||||
RendererPtr _renderer;
|
||||
ScenePtr _activeScene;
|
||||
static std::shared_ptr<LEngine> _instance;
|
||||
std::vector<RenderOutputPtr> _outputs;
|
||||
};
|
||||
|
||||
#endif // Application_h__
|
||||
@@ -0,0 +1,197 @@
|
||||
#include "Material.h"
|
||||
#include <d3d11.h>
|
||||
#include <stdint.h>
|
||||
//#include <NativeLINQ/NativeLINQ.h>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include "FatalError.h"
|
||||
|
||||
void Material::SetShader(ShaderPtr _shader) {
|
||||
shader = _shader;
|
||||
RebuildBuffers();
|
||||
}
|
||||
|
||||
std::string Material::DiffuseMapName() {
|
||||
return "_DiffuseMap";
|
||||
}
|
||||
std::string Material::NormalMapName() {
|
||||
return "_NormalMap";
|
||||
}
|
||||
std::string Material::DiffuseColorName() {
|
||||
return "_DiffuseColor";
|
||||
}
|
||||
MaterialPtr Material::Create(std::string name) {
|
||||
return std::shared_ptr<Material>(new Material(name));
|
||||
}
|
||||
|
||||
MaterialPtr Material::Create(ShaderPtr shader, std::string name) {
|
||||
auto material = Create(name);
|
||||
material->SetShader(shader);
|
||||
return material;
|
||||
}
|
||||
|
||||
void Material::Apply() {
|
||||
for(int i = 0; i < (int)ShaderType::Count; ++i) {
|
||||
auto s = shader->GetShader((ShaderType)i);
|
||||
if(s != nullptr) {
|
||||
|
||||
//apply shaders
|
||||
//s->Apply(context);
|
||||
|
||||
auto& p = shaderParameters[i];
|
||||
//update and apply buffers
|
||||
for (auto& bufferCtx : p.buffers) {
|
||||
|
||||
D3D12_RANGE range;
|
||||
range.Begin = range.End = 0;
|
||||
|
||||
uint8_t* data = nullptr;
|
||||
|
||||
// auto hr = bufferCtx.buffer->Map(0, &range, (void**)&data);
|
||||
// assert(hr == S_OK);
|
||||
|
||||
//write all variables
|
||||
for (auto& variable : bufferCtx.variables) {
|
||||
auto param = parameters.GetParameterByName(variable.name);
|
||||
if (param != nullptr) {
|
||||
memcpy(data + variable.offset, param->GetPointer(), variable.size);
|
||||
}
|
||||
}
|
||||
|
||||
range.End = bufferCtx.size;
|
||||
// bufferCtx.buffer->Unmap(0, &range);
|
||||
// assert(hr == S_OK);
|
||||
/*context->Unmap(bufferCtx.buffer, 0);
|
||||
ID3D11Buffer* buffers[1] = { bufferCtx.buffer };
|
||||
|
||||
switch ((ShaderType)i)
|
||||
{
|
||||
case ShaderType::Vs:
|
||||
context->VSSetConstantBuffers(bufferCtx.bindPoint, 1, buffers);
|
||||
break;
|
||||
case ShaderType::Ps:
|
||||
context->PSSetConstantBuffers(bufferCtx.bindPoint, 1, buffers);
|
||||
break;
|
||||
default:
|
||||
assert(false && "not implemented");
|
||||
}*/
|
||||
|
||||
//sr.pData
|
||||
|
||||
}
|
||||
|
||||
//apply shader resources
|
||||
/*for (auto& resourceCtx : p.resources) {
|
||||
auto param = parameters.GetParameterByName(resourceCtx.name);
|
||||
if (param != nullptr) {
|
||||
auto resourceParam = std::dynamic_pointer_cast<ShaderResourceParameter>(param);
|
||||
|
||||
ID3D11ShaderResourceView* resources[1] = { resourceParam->value };
|
||||
|
||||
switch ((ShaderType)i)
|
||||
{
|
||||
case ShaderType::Vs:
|
||||
context->VSSetShaderResources(resourceCtx.bindPoint, 1, resources);
|
||||
break;
|
||||
case ShaderType::Ps:
|
||||
context->PSSetShaderResources(resourceCtx.bindPoint, 1, resources);
|
||||
break;
|
||||
default:
|
||||
assert(false && "not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Material::RebuildShaderParameters(ShaderParametersContext& params, ComPtr<ID3D12ShaderReflection> reflection) {
|
||||
|
||||
|
||||
D3D12_SHADER_DESC d;
|
||||
reflection->GetDesc(&d);
|
||||
|
||||
params.Clear();
|
||||
|
||||
//get resource variables
|
||||
for(uint32_t i = 0; i < d.BoundResources; ++i) {
|
||||
D3D12_SHADER_INPUT_BIND_DESC bindDesc;
|
||||
reflection->GetResourceBindingDesc(i, &bindDesc);
|
||||
|
||||
ShaderResourceVariable var;
|
||||
var.bindPoint = bindDesc.BindPoint;
|
||||
var.name = bindDesc.Name;
|
||||
var.type = bindDesc.Type;
|
||||
params.resources.push_back(var);
|
||||
}
|
||||
|
||||
|
||||
//get constant buffers
|
||||
for(uint32_t i = 0; i < d.ConstantBuffers; ++i) {
|
||||
ShaderBufferContext ctx;
|
||||
ID3D12ShaderReflectionConstantBuffer* cb = reflection->GetConstantBufferByIndex(i);
|
||||
|
||||
auto device = shader->GetDevice();
|
||||
D3D12_SHADER_BUFFER_DESC bufferDesc;
|
||||
cb->GetDesc(&bufferDesc);
|
||||
|
||||
ctx.name = bufferDesc.Name;
|
||||
|
||||
D3D11_BUFFER_DESC cbDesc;
|
||||
cbDesc.ByteWidth = bufferDesc.Size;
|
||||
cbDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
cbDesc.MiscFlags = 0;
|
||||
cbDesc.StructureByteStride = 0;
|
||||
|
||||
|
||||
// auto hr = device->CreateCommittedResource(
|
||||
// &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), // this heap will be used to upload the constant buffer data
|
||||
// D3D12_HEAP_FLAG_NONE, // no flags
|
||||
// &CD3DX12_RESOURCE_DESC::Buffer(1024 * 64), // Must be a multiple of 64KB for single-textures and constant buffers. TODO: handle size overflow o_O Maybe.
|
||||
// D3D12_RESOURCE_STATE_GENERIC_READ,
|
||||
// nullptr,
|
||||
// IID_PPV_ARGS(&ctx.buffer));
|
||||
|
||||
// ctx.buffer->SetName(L"Constant Buffer Upload Resource Heap");
|
||||
|
||||
|
||||
//device->CreateBuffer(&cbDesc, nullptr, &ctx.buffer);
|
||||
|
||||
for(uint32_t j = 0; j < bufferDesc.Variables; ++j) {
|
||||
auto variable = cb->GetVariableByIndex(j);
|
||||
D3D12_SHADER_VARIABLE_DESC varDesc;
|
||||
variable->GetDesc(&varDesc);
|
||||
ctx.variables.push_back(ShaderBufferVariable(varDesc.Name, varDesc.StartOffset, varDesc.Size));
|
||||
}
|
||||
|
||||
//find buffer's bind point
|
||||
|
||||
// auto res = Where(params.resources, [ctx](ShaderResourceVariable srv) {return srv.name == ctx.name && srv.type == D3D_SIT_CBUFFER; })->ToVector();
|
||||
// ctx.bindPoint = res[0].bindPoint;
|
||||
// ctx.type = res[0].type;
|
||||
// ctx.size = cbDesc.ByteWidth;
|
||||
// params.buffers.push_back(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
void Material::RebuildBuffers() {
|
||||
ComPtr<ID3D12ShaderReflection> reflection;
|
||||
for(int i = 0; i < (int)ShaderType::Count; ++i) {
|
||||
auto vs = shader->GetShader((ShaderType)i);
|
||||
if(vs != nullptr) {
|
||||
reflection = nullptr;
|
||||
D3DReflect(vs->blob->GetBufferPointer(), vs->blob->GetBufferSize(), __uuidof(reflection), (void**)&reflection);
|
||||
RebuildShaderParameters(shaderParameters[i], reflection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Material::SetParametersBlock(ShaderParametersBlock& block) {
|
||||
parameters = block;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#ifndef Material_h__
|
||||
#define Material_h__
|
||||
|
||||
#include "Shader.h"
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include "ForwardDeclarations.h"
|
||||
#include "ShaderParametersBlock.h"
|
||||
#include "Object.h"
|
||||
|
||||
#include <wrl.h>
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
class Material : public Object {
|
||||
public:
|
||||
std::wstring class_name() const {
|
||||
return L"Material";
|
||||
}
|
||||
void SetShader(ShaderPtr _shader);
|
||||
ShaderPtr GetShader() {
|
||||
return shader;
|
||||
}
|
||||
void SetParametersBlock(ShaderParametersBlock& block);
|
||||
ShaderParametersBlock& GetParametersBlock() {
|
||||
return parameters;
|
||||
}
|
||||
void Apply();
|
||||
static MaterialPtr Create(std::string name);
|
||||
static MaterialPtr Create(ShaderPtr shader, std::string name);
|
||||
static std::string DiffuseMapName();
|
||||
static std::string NormalMapName();
|
||||
static std::string DiffuseColorName();
|
||||
ShaderParametersContext& GetCompiledParameters(ShaderType shader_type)
|
||||
{
|
||||
return shaderParameters[(uint32_t)shader_type];
|
||||
}
|
||||
private:
|
||||
|
||||
Material(std::string name)
|
||||
:_name(name)
|
||||
{
|
||||
|
||||
}
|
||||
std::string _name;
|
||||
ShaderPtr shader;
|
||||
ShaderParametersContext shaderParameters[(uint32_t)ShaderType::Count];
|
||||
ShaderParametersBlock parameters;
|
||||
|
||||
|
||||
void RebuildBuffers();
|
||||
void RebuildShaderParameters(ShaderParametersContext& params, ComPtr<ID3D12ShaderReflection> reflection);
|
||||
};
|
||||
|
||||
|
||||
#endif // Material_h__
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
class Mathf {
|
||||
public:
|
||||
static float Pi() {
|
||||
return 3.1415926535897932384626f;
|
||||
}
|
||||
static float RadToDeg() {
|
||||
return 180.0f / Pi();
|
||||
}
|
||||
static float DegToRad() {
|
||||
return Pi() / 180.0f;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,148 @@
|
||||
#include "Mesh.h"
|
||||
#include "LEngine.h"
|
||||
#include <string.h>
|
||||
|
||||
// Mesh::Mesh(ID3D12DevicePtr dev) {
|
||||
// _device = dev;
|
||||
// SetSubmeshCount(1);
|
||||
// }
|
||||
|
||||
MeshPtr Mesh::Create() {
|
||||
return nullptr;//std::shared_ptr<Mesh>(new Mesh(LEngine::Instance()->GetRenderer()->GetDevice()));
|
||||
}
|
||||
|
||||
// ID3D12ResourcePtr Mesh::GetVertexBuffer() {
|
||||
// return _vertexBuffer;
|
||||
// }
|
||||
|
||||
// ID3D12DevicePtr Mesh::GetDevice() {
|
||||
// return _device;
|
||||
// }
|
||||
|
||||
MeshPtr Mesh::Create(MeshProcessFunction initFunction) {
|
||||
auto mesh = Create();
|
||||
if (initFunction != nullptr) {
|
||||
initFunction(mesh);
|
||||
mesh->RecalculateBounds();
|
||||
}
|
||||
return mesh;
|
||||
}
|
||||
|
||||
Bounds Mesh::GetBounds() const {
|
||||
return _bounds;
|
||||
}
|
||||
|
||||
std::vector<Vertex> Mesh::GetVertices() {
|
||||
std::vector<Vertex> result;
|
||||
/*if (_vertexBuffer == nullptr) {
|
||||
return result;
|
||||
}
|
||||
|
||||
D3D11_BUFFER_DESC desc;
|
||||
_vertexBuffer->GetDesc(&desc);
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
desc.Usage = D3D11_USAGE_STAGING;
|
||||
desc.BindFlags = 0;
|
||||
ID3D11BufferPtr stagingBuffer;
|
||||
_device->CreateBuffer(&desc, nullptr, &stagingBuffer);
|
||||
ID3D11DeviceContextPtr ctx;
|
||||
_device->GetImmediateContext(&ctx);
|
||||
|
||||
ctx->CopyResource(stagingBuffer, _vertexBuffer);
|
||||
D3D11_MAPPED_SUBRESOURCE sr;
|
||||
ctx->Map(stagingBuffer, 0, D3D11_MAP_READ, 0, &sr);
|
||||
result.resize(desc.ByteWidth / sizeof(Vertex));
|
||||
memcpy_s(&result[0], desc.ByteWidth, sr.pData, desc.ByteWidth);
|
||||
ctx->Unmap(stagingBuffer, 0);*/
|
||||
return result;
|
||||
}
|
||||
|
||||
D3D12_VERTEX_BUFFER_VIEW Mesh::GetVertexBufferView(){
|
||||
D3D12_VERTEX_BUFFER_VIEW result;
|
||||
// result.BufferLocation = _vertexBuffer->GetGPUVirtualAddress();
|
||||
result.SizeInBytes = _vertexCount * sizeof(Vertex);
|
||||
result.StrideInBytes = sizeof(Vertex);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Mesh::SetVertices(const std::vector<Vertex>& vertices) {
|
||||
auto bytesCount = sizeof(vertices[0])* vertices.size();
|
||||
_vertexCount = vertices.size();
|
||||
|
||||
|
||||
//create vertex buffer
|
||||
// _device->CreateCommittedResource(
|
||||
// &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
|
||||
// D3D12_HEAP_FLAG_NONE,
|
||||
// &CD3DX12_RESOURCE_DESC::Buffer(bytesCount),
|
||||
// D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
// nullptr,
|
||||
// IID_PPV_ARGS(&_vertexBuffer));
|
||||
|
||||
|
||||
//create upload buffer
|
||||
ComPtr<ID3D12Resource> vBufferUploadHeap;
|
||||
// _device->CreateCommittedResource(
|
||||
// &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
|
||||
// D3D12_HEAP_FLAG_NONE,
|
||||
// &CD3DX12_RESOURCE_DESC::Buffer(bytesCount),
|
||||
// D3D12_RESOURCE_STATE_GENERIC_READ,
|
||||
// nullptr,
|
||||
// IID_PPV_ARGS(&vBufferUploadHeap));
|
||||
// vBufferUploadHeap->SetName(L"Vertex Buffer Upload Resource Heap");
|
||||
|
||||
|
||||
D3D12_SUBRESOURCE_DATA vertexData = {};
|
||||
vertexData.pData = reinterpret_cast<const BYTE*>(&vertices[0]); // pointer to our vertex array
|
||||
vertexData.RowPitch = bytesCount; // size of all our triangle vertex data
|
||||
vertexData.SlicePitch = bytesCount; // also the size of our triangle vertex data
|
||||
|
||||
|
||||
auto renderer = LEngine::Instance()->GetRenderer();
|
||||
// auto cl = renderer->BeginCommandList();
|
||||
// UpdateSubresources(cl.Get(), _vertexBuffer.Get(), vBufferUploadHeap.Get(), 0, 0, 1, &vertexData);
|
||||
// cl->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(_vertexBuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER));
|
||||
renderer->EndCommandList();
|
||||
renderer->WaitCommandsQueue();
|
||||
}
|
||||
|
||||
void Mesh::SetIndices(const Submesh::index_array_t& indices, MeshTopology topology, uint32_t submeshId) {
|
||||
if (submeshId >= GetSubmeshCount()) {
|
||||
return;
|
||||
}
|
||||
_submeshes[submeshId]->Set(indices, topology);
|
||||
}
|
||||
|
||||
uint32_t Mesh::GetSubmeshCount() const {
|
||||
return _submeshes.size();
|
||||
}
|
||||
void Mesh::SetSubmeshCount(uint32_t count) {
|
||||
auto oldSize = _submeshes.size();
|
||||
_submeshes.resize(count);
|
||||
for (auto i = oldSize; i < count; ++i) {
|
||||
_submeshes[i] = std::make_shared<Submesh>();
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<SubmeshPtr>& Mesh::GetSubmeshes() {
|
||||
return _submeshes;
|
||||
}
|
||||
|
||||
void Mesh::RecalculateBounds() {
|
||||
/*auto vertices = GetVertices();
|
||||
if (vertices.size() == 0) {
|
||||
_bounds.SetSize(float3(0, 0, 0));
|
||||
_bounds.SetCenter(float3(0, 0, 0));
|
||||
}
|
||||
|
||||
float3 minPoint = vertices[0].position.xyz;
|
||||
float3 maxPoint = vertices[0].position.xyz;
|
||||
|
||||
for (size_t i = 1; i < vertices.size(); ++i) {
|
||||
minPoint = lm::min(minPoint, vertices[i].position.xyz);
|
||||
maxPoint = lm::max(maxPoint, vertices[i].position.xyz);
|
||||
}
|
||||
|
||||
_bounds.SetCenter((minPoint + maxPoint) * 0.5f);
|
||||
_bounds.SetSize(maxPoint - minPoint);*/
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef Mesh_h__
|
||||
#define Mesh_h__
|
||||
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include "ForwardDeclarations.h"
|
||||
#include "Vertex.h"
|
||||
#include "Submesh.h"
|
||||
#include "Bounds.h"
|
||||
#include "Object.h"
|
||||
|
||||
#include <wrl.h>
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
typedef std::function<void(MeshPtr)> MeshProcessFunction;
|
||||
|
||||
class Mesh : public Object {
|
||||
public:
|
||||
Mesh():_vertexCount(0)
|
||||
{
|
||||
|
||||
}
|
||||
std::vector<Vertex> GetVertices();
|
||||
void SetVertices(const std::vector<Vertex>& vertices);
|
||||
void SetIndices(const Submesh::index_array_t& indices, MeshTopology topology, uint32_t submeshId);
|
||||
void RecalculateBounds();
|
||||
// ID3D12ResourcePtr GetVertexBuffer();
|
||||
// ID3D12DevicePtr GetDevice();
|
||||
static MeshPtr Create();
|
||||
static MeshPtr Create(MeshProcessFunction initFunction);
|
||||
uint32_t GetSubmeshCount() const;
|
||||
void SetSubmeshCount(uint32_t count);
|
||||
const std::vector<SubmeshPtr>& GetSubmeshes();
|
||||
Bounds GetBounds() const;
|
||||
D3D12_VERTEX_BUFFER_VIEW GetVertexBufferView();
|
||||
private:
|
||||
size_t _vertexCount;
|
||||
Bounds _bounds;
|
||||
// Mesh(ID3D12DevicePtr dev);
|
||||
// ID3D12ResourcePtr _vertexBuffer;
|
||||
// ID3D12DevicePtr _device;
|
||||
std::vector<SubmeshPtr> _submeshes;
|
||||
};
|
||||
|
||||
|
||||
#endif // Mesh_h__
|
||||
@@ -0,0 +1,80 @@
|
||||
#include "MeshGenerator.h"
|
||||
#include <vector>
|
||||
|
||||
void MeshGenerator::Cube(MeshPtr mesh, bool splitFaces){
|
||||
if (mesh == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<uint32_t> indices;
|
||||
|
||||
float3 corners[8];
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
int id = i * 4 + j;
|
||||
corners[id].x() = ((j == 0) || (j == 3)) ? -0.5f : 0.5f;
|
||||
corners[id].y() = -((float)(j >> 1) - 0.5f);
|
||||
corners[id].z() =(float)i - 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
int vid[] = { 0,1,2,3, 5,4,7,6, 1,5,6,2, 4,0,3,7, 4,5,1,0, 3,2,6,7 };
|
||||
for (int i = 0; i < 24; ++i) {
|
||||
Vertex v;
|
||||
v.position.x() = corners[vid[i]].x();
|
||||
v.position.y() = corners[vid[i]].y();
|
||||
v.position.z() = corners[vid[i]].z();
|
||||
vertices.push_back(v);
|
||||
}
|
||||
|
||||
float3 normals[6] = { float3(0.0f,0.0f,-1.0f), float3(0.0f,0.0f,1.0f), float3(1.0f,0.0f,0.0f), float3(-1.0f,0.0f,0.0f), float3(0.0f,1.0f,0.0f), float3(0.0f,-1.0f,0.0f) };
|
||||
int indicesBase[] = { 0,1,3,1,2,3 };
|
||||
float2 uvBase[] = { float2(0.0f,0.0f), float2(1.0f,0.0f), float2(1.0f,1.0f), float2(0.0f,1.0f) };
|
||||
|
||||
mesh->SetSubmeshCount(splitFaces ? 6 : 1);
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
vertices[i * 4 + j].normal = normals[i];
|
||||
vertices[i * 4 + j].uv0 = uvBase[j];
|
||||
}
|
||||
|
||||
for (int j = 0; j < 6; ++j) {
|
||||
indices.push_back(indicesBase[j] + i * 4);
|
||||
}
|
||||
|
||||
if (splitFaces) {
|
||||
mesh->SetIndices(indices, MeshTopology::TriangleList, i);
|
||||
indices.resize(0);
|
||||
}
|
||||
}
|
||||
|
||||
mesh->SetVertices(vertices);
|
||||
|
||||
if (!splitFaces) {
|
||||
mesh->SetIndices(indices, MeshTopology::TriangleList, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshGenerator::Plane(MeshPtr mesh) {
|
||||
if (mesh == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
float3 normal(0.0f, 1.0f, 0.0f);
|
||||
float extend = 0.5f;
|
||||
|
||||
std::vector<Vertex> vertices = {
|
||||
Vertex(float4(-extend, 0.0f, extend, 1.0f), normal, float2(0.0f,0.0f)),
|
||||
Vertex(float4(extend, 0.0f, extend, 1.0f), normal, float2(1.0f,0.0f)),
|
||||
Vertex(float4(extend, 0.0f, -extend, 1.0f), normal, float2(1.0f,1.0f)),
|
||||
Vertex(float4(-extend, 0.0f, -extend, 1.0f), normal, float2(0.0f,1.0f)),
|
||||
};
|
||||
|
||||
std::vector<uint32_t> indices = { 0,1,3,1,2,3 };
|
||||
|
||||
mesh->SetSubmeshCount(1);
|
||||
mesh->SetVertices(vertices);
|
||||
mesh->SetIndices(indices, MeshTopology::TriangleList, 0);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef MeshGenerator_h__
|
||||
#define MeshGenerator_h__
|
||||
|
||||
#include "Mesh.h"
|
||||
#include "ForwardDeclarations.h"
|
||||
|
||||
class MeshGenerator
|
||||
{
|
||||
public:
|
||||
static void Cube(MeshPtr mesh, bool splitFaces);
|
||||
|
||||
static void Plane(MeshPtr mesh);
|
||||
};
|
||||
#endif // MeshGenerator_h__
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "MeshRenderer.h"
|
||||
#include <cassert>
|
||||
|
||||
void MeshRenderer::SyncMaterialSlots() {
|
||||
if (mesh == nullptr) {
|
||||
_materials.resize(0);
|
||||
}
|
||||
else {
|
||||
_materials.resize(mesh->GetSubmeshCount());
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<MeshRenderer> MeshRenderer::SetMesh(MeshPtr m) {
|
||||
mesh = m;
|
||||
SyncMaterialSlots();
|
||||
UpdateInputLayouts();
|
||||
return std::static_pointer_cast<MeshRenderer>(shared_from_this());
|
||||
}
|
||||
|
||||
MeshPtr MeshRenderer::GetMesh() {
|
||||
return mesh;
|
||||
}
|
||||
|
||||
void MeshRenderer::SetMaterial(MaterialPtr material, int id){
|
||||
SyncMaterialSlots();
|
||||
_materials[id] = material;
|
||||
UpdateInputLayouts();
|
||||
}
|
||||
|
||||
void MeshRenderer::UpdateInputLayouts(){
|
||||
|
||||
if (mesh == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_materials.size() == 0 || _materials[0] == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
//D3D12_APPEND_ALIGNED_ELEMENT
|
||||
_inputElements.clear();
|
||||
_inputElements.push_back({ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 });
|
||||
_inputElements.push_back({ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 });
|
||||
_inputElements.push_back({ "UV", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 });
|
||||
_inputElements.push_back({ "UV", 1, DXGI_FORMAT_R32G32_FLOAT, 0, 36, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 });
|
||||
|
||||
|
||||
_inputLayoutDesc.NumElements = _inputElements.size();
|
||||
_inputLayoutDesc.pInputElementDescs = &_inputElements[0];
|
||||
|
||||
//auto vs = _materials[0]->GetShader()->GetShader(ShaderType::Vs);
|
||||
//auto hr = mesh->GetDevice()->CreateInputLayout(ied, 4, vs->blob->GetBufferPointer(), vs->blob->GetBufferSize(), &_inputLayout);
|
||||
//assert(hr == S_OK);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef MeshRenderer_h__
|
||||
#define MeshRenderer_h__
|
||||
|
||||
#include "ObjectsFactory.h"
|
||||
#include "Mesh.h"
|
||||
#include "Material.h"
|
||||
#include <vector>
|
||||
#include "ForwardDeclarations.h"
|
||||
#include <memory>
|
||||
|
||||
|
||||
LOBJECT(MeshRenderer, Component)
|
||||
public:
|
||||
std::shared_ptr<MeshRenderer> SetMesh(MeshPtr m);
|
||||
MeshPtr GetMesh();
|
||||
void SetMaterial(MaterialPtr material, int id);
|
||||
std::vector<MaterialPtr> GetMaterials() {
|
||||
return _materials;
|
||||
}
|
||||
D3D12_INPUT_LAYOUT_DESC GetInputLayout() {
|
||||
return _inputLayoutDesc;
|
||||
}
|
||||
private:
|
||||
void UpdateInputLayouts();
|
||||
void SyncMaterialSlots();
|
||||
MeshPtr mesh;
|
||||
std::vector<MaterialPtr> _materials;
|
||||
std::vector<D3D12_INPUT_ELEMENT_DESC> _inputElements;
|
||||
D3D12_INPUT_LAYOUT_DESC _inputLayoutDesc;
|
||||
};
|
||||
#endif // MeshRenderer_h__
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetImporter.h"
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "ObjMeshLoader.h"
|
||||
#include "AssetDatabase.h"
|
||||
|
||||
class ModelImporter : public AssetImporter {
|
||||
public:
|
||||
virtual bool can_import(const std::wstring& path) const override {
|
||||
std::filesystem::path src_path(path);
|
||||
return src_path.extension() == ".obj";
|
||||
}
|
||||
|
||||
virtual std::wstring name() override {
|
||||
return L"ModelImporter";
|
||||
}
|
||||
|
||||
virtual bool set_parameters(std::wstring params) override {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual std::wstring get_parameters() const override {
|
||||
return L"";
|
||||
}
|
||||
|
||||
virtual void import(std::wstring asset_path) override {
|
||||
ObjMeshLoader loader;
|
||||
loader.Load(asset_path);
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,416 @@
|
||||
#pragma once
|
||||
|
||||
#include "Mesh.h"
|
||||
#include "GameObject.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <lmath/lmath.h>
|
||||
#include <stack>
|
||||
#include <sstream>
|
||||
#include <array>
|
||||
#include <tuple>
|
||||
#include <map>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
|
||||
#include "MeshRenderer.h"
|
||||
using namespace lm;
|
||||
|
||||
|
||||
struct ObjVertex {
|
||||
int32_t vid;
|
||||
int32_t tid;
|
||||
int32_t nid;
|
||||
};
|
||||
|
||||
struct ObjFace {
|
||||
int32_t sid;
|
||||
int32_t mid;
|
||||
std::array<ObjVertex, 3> vertices;
|
||||
};
|
||||
|
||||
class ObjGroup {
|
||||
public:
|
||||
ObjGroup(std::string objName)
|
||||
:name(objName), smoothGroupsEnabled(true), activeSmoothGroup(0)
|
||||
{
|
||||
|
||||
}
|
||||
void AddFace(int32_t matId, const ObjVertex& v0, const ObjVertex& v1, const ObjVertex& v2) {
|
||||
ObjFace f;
|
||||
f.vertices[0] = v0;
|
||||
f.vertices[1] = v1;
|
||||
f.vertices[2] = v2;
|
||||
f.mid = matId;
|
||||
f.sid = activeSmoothGroup;
|
||||
faces.push_back(f);
|
||||
|
||||
if (std::find(materials.begin(), materials.end(), matId) == materials.end()) {
|
||||
materials.push_back(matId);
|
||||
}
|
||||
}
|
||||
std::vector<uint32_t> materials;
|
||||
std::string name;
|
||||
std::vector<ObjFace> faces;
|
||||
int32_t activeSmoothGroup;
|
||||
bool smoothGroupsEnabled;
|
||||
};
|
||||
|
||||
class ObjMeshLoader {
|
||||
public:
|
||||
friend class ObjGroup;
|
||||
ObjMeshLoader() : _activeMatId(-1){
|
||||
|
||||
}
|
||||
|
||||
std::string read_file(std::wstring path)
|
||||
{
|
||||
FILE* file = nullptr;
|
||||
auto err = _wfopen_s(&file, path.c_str(), L"rb");
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
auto file_size = ftell(file);
|
||||
|
||||
std::string str;
|
||||
str.resize(file_size);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
auto done = fread_s(&str[0], file_size, 1, file_size, file);
|
||||
fclose(file);
|
||||
return str;
|
||||
}
|
||||
std::vector<GameObjectPtr> Load(const std::wstring& path) {
|
||||
std::vector<GameObjectPtr> result;
|
||||
|
||||
/*if (!file1.good()) {
|
||||
return result;
|
||||
}*/
|
||||
|
||||
auto str = read_file(path);
|
||||
|
||||
|
||||
std::stringstream buffer(str);
|
||||
std::vector<char> line_buffer;
|
||||
line_buffer.resize(8192);
|
||||
|
||||
|
||||
std::string previous_line;
|
||||
std::string line;
|
||||
//while (buffer.getline(&line_buffer[0], line_buffer.size())) {
|
||||
while (std::getline(buffer, line)) {
|
||||
|
||||
//std::string line(&line_buffer[0]);
|
||||
if (line.size() < 3) {
|
||||
continue;
|
||||
}
|
||||
switch(line[0]){
|
||||
case 'v':
|
||||
switch (line[1]) {
|
||||
case ' ': {
|
||||
float3 v;
|
||||
sscanf_s(&line[2], "%f%f%f", &v.x(), &v.y(), &v.z());
|
||||
_vertices.push_back(v);
|
||||
break;
|
||||
}
|
||||
case 'n': {
|
||||
float3 n;
|
||||
sscanf_s(&line[2], "%f%f%f", &n.x(), &n.y(), &n.z());
|
||||
_normals.push_back(n);
|
||||
break;
|
||||
}
|
||||
case 't':
|
||||
float3 t;
|
||||
sscanf_s(&line[2], "%f%f%f", &t.x(), &t.y(), &t.z());
|
||||
_texcoords.push_back(t);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'f': {
|
||||
bool is_open = false;
|
||||
size_t start = 2;
|
||||
int slash_pos_0 = 0;
|
||||
int slash_pos_1 = 0;
|
||||
|
||||
if(line[line.size() - 1] == '\r')
|
||||
{
|
||||
line[line.size() - 1] = ' ';
|
||||
}else
|
||||
{
|
||||
line += " ";
|
||||
}
|
||||
|
||||
std::vector<ObjVertex> fVertices;
|
||||
for (size_t i = 2; i < line.size(); ++i) {
|
||||
if (line[i] == ' ') {
|
||||
if (is_open) { //finalize chunk
|
||||
is_open = false;
|
||||
ObjVertex v;
|
||||
if (slash_pos_0 == -1) {
|
||||
auto pos2 = (int)buffer.tellg();
|
||||
sscanf_s(&line[start], "%d", &v.vid);
|
||||
v.tid = v.nid = -1;
|
||||
} else if (slash_pos_1 == -1) {
|
||||
sscanf_s(&line[start], "%d/%d", &v.vid, &v.tid);
|
||||
v.nid = -1;
|
||||
} else {
|
||||
if (slash_pos_1 - slash_pos_0 == 1) {
|
||||
sscanf_s(&line[start], "%d//%d", &v.vid, &v.nid);
|
||||
v.tid = -1;
|
||||
} else {
|
||||
sscanf_s(&line[start], "%d/%d/%d", &v.vid, &v.tid, &v.nid);
|
||||
}
|
||||
}
|
||||
fVertices.push_back(v);
|
||||
}
|
||||
} else {
|
||||
if (!is_open) {
|
||||
start = i;
|
||||
slash_pos_0 = -1;
|
||||
slash_pos_1 = -1;
|
||||
is_open = true;
|
||||
} else {
|
||||
if (line[i] == '/') {
|
||||
if (slash_pos_0 == -1) {
|
||||
slash_pos_0 = i;
|
||||
} else {
|
||||
slash_pos_1 = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//emit triangles (split if quads)
|
||||
if (fVertices.size() == 3) {
|
||||
_groups[_groups.size() - 1].AddFace(_activeMatId, fVertices[0], fVertices[1], fVertices[2]);
|
||||
} else if (fVertices.size() == 4) {
|
||||
_groups[_groups.size() - 1].AddFace(_activeMatId, fVertices[0], fVertices[1], fVertices[2]);
|
||||
_groups[_groups.size() - 1].AddFace(_activeMatId, fVertices[0], fVertices[2], fVertices[3]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'g': {
|
||||
auto name = line.substr(2);
|
||||
_groups.push_back(ObjGroup(name));
|
||||
break;
|
||||
}
|
||||
case 's':
|
||||
if (line.find("off") != std::string::npos) {
|
||||
_groups[_groups.size() - 1].smoothGroupsEnabled = false;
|
||||
} else {
|
||||
sscanf_s(&line[2], "%d", &_groups[_groups.size() - 1].activeSmoothGroup);
|
||||
}
|
||||
break;
|
||||
case 'm': {
|
||||
std::stringstream ss(line);
|
||||
std::string key, value;
|
||||
ss >> key;
|
||||
ss >> value;
|
||||
_mtlLibName = value;
|
||||
std::cout << "Found material library: " << value << std::endl;
|
||||
break;
|
||||
}
|
||||
case 'u': {
|
||||
std::stringstream ss(line);
|
||||
std::string key, value;
|
||||
ss >> key;
|
||||
ss >> value;
|
||||
SetActiveMaterial(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
previous_line = line;
|
||||
}
|
||||
|
||||
|
||||
auto mtllib_path = obj_to_mtl_path(path);
|
||||
|
||||
_mats = load_mtllib(mtllib_path);
|
||||
|
||||
for (auto& group : _groups) {
|
||||
result.push_back(UnpackGroup(group));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private:
|
||||
std::vector<MaterialPtr> _mats;
|
||||
std::wstring obj_to_mtl_path(const std::wstring& obj_path){
|
||||
std::filesystem::path src(obj_path);
|
||||
auto dst = src.parent_path();
|
||||
return dst.append(_mtlLibName).wstring();
|
||||
}
|
||||
|
||||
std::vector<MaterialPtr> load_mtllib(const std::wstring& path){
|
||||
std::vector<MaterialPtr> result;
|
||||
|
||||
auto text = std::ifstream(path);
|
||||
|
||||
std::string line;
|
||||
auto default_shader = Shader::Create(L"Shaders/default.fx");
|
||||
|
||||
MaterialPtr active_material;
|
||||
while(std::getline(text, line))
|
||||
{
|
||||
if(line[0] == '#' || line.empty()){
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string word;
|
||||
std::stringstream ls(line);
|
||||
ls >> word;
|
||||
|
||||
if (word == "newmtl") {
|
||||
std::string mat_name;
|
||||
ls >> mat_name;
|
||||
if(active_material != nullptr)
|
||||
{
|
||||
result.push_back(active_material);
|
||||
}
|
||||
active_material = Material::Create(default_shader, mat_name);
|
||||
|
||||
} else {
|
||||
if (active_material == nullptr) {
|
||||
continue;
|
||||
} else {
|
||||
if(word == "Kd")
|
||||
{
|
||||
std::vector<float> color;
|
||||
float tmp = 0.0f;
|
||||
while(ls >> tmp)
|
||||
{
|
||||
color.push_back(tmp);
|
||||
}
|
||||
|
||||
if(color.size() == 3)
|
||||
{
|
||||
active_material->GetParametersBlock().SetValue(Material::DiffuseColorName(), float4(color[0], color[1], color[2], 1.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (active_material != nullptr) {
|
||||
result.push_back(active_material);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
typedef std::tuple<ObjVertex, Vertex> VertexPair;
|
||||
GameObjectPtr UnpackGroup(const ObjGroup& group) {
|
||||
std::vector<std::vector<ObjFace*>> facesTable;
|
||||
facesTable.resize(_vertices.size());
|
||||
std::vector<Vertex> vertices;
|
||||
std::map<size_t, std::vector<uint32_t>> submeshes;
|
||||
|
||||
//EmitGeometry(group, vertices, submeshes);
|
||||
EmitGeometrySimple(group, vertices, submeshes);
|
||||
|
||||
auto mesh = Mesh::Create();
|
||||
mesh->SetSubmeshCount(group.materials.size());
|
||||
mesh->SetVertices(vertices);
|
||||
|
||||
|
||||
|
||||
int id = 0;
|
||||
for(auto& p : submeshes)
|
||||
{
|
||||
mesh->SetIndices(p.second, MeshTopology::TriangleList, id);
|
||||
id++;
|
||||
}
|
||||
|
||||
auto obj = GameObject::create();
|
||||
obj->AddComponent<MeshRenderer>()->SetMesh(mesh);
|
||||
|
||||
|
||||
|
||||
for (size_t i = 0; i < group.materials.size(); ++i){
|
||||
auto mat_id = group.materials[i];
|
||||
|
||||
obj->GetComponent<MeshRenderer>()->SetMaterial(_mats[mat_id], i);
|
||||
}
|
||||
|
||||
mesh->RecalculateBounds();
|
||||
return obj;
|
||||
}
|
||||
|
||||
/*MeshPtr BuildMesh(ObjGroup& group) {
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<int32_t> indices;
|
||||
EmitGeometry(group, vertices, indices);
|
||||
|
||||
auto mesh = Mesh::Create();
|
||||
mesh->SetSubmeshCount(group.materials.size());
|
||||
return mesh;
|
||||
}*/
|
||||
|
||||
void EmitGeometry(const ObjGroup& group, std::vector<Vertex>& vertices, std::map<size_t, std::vector<uint32_t>>& submeshes) {
|
||||
auto vComp = [](ObjVertex v1, ObjVertex v2) {
|
||||
return (v1.vid == v2.vid) && (v1.tid == v2.tid) && (v1.nid && v2.nid);
|
||||
};
|
||||
|
||||
std::vector<ObjVertex> tmpVertices;
|
||||
|
||||
for (auto& f : group.faces) {
|
||||
for (auto& v : f.vertices) {
|
||||
int id = -1;
|
||||
for (size_t i = 0; i < tmpVertices.size(); ++i) {
|
||||
if (vComp(tmpVertices[i], v)) {
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (id == -1) {
|
||||
id = tmpVertices.size();
|
||||
tmpVertices.push_back(v);
|
||||
Vertex vertex;
|
||||
vertex.position = float4(_vertices[v.vid - 1], 1.0f);
|
||||
vertex.normal = _normals[v.nid - 1];
|
||||
vertex.uv0 = _texcoords[v.tid - 1].xy();
|
||||
vertices.push_back(vertex);
|
||||
}
|
||||
|
||||
submeshes[f.mid].push_back(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EmitGeometrySimple(const ObjGroup& group, std::vector<Vertex>& vertices, std::map<size_t, std::vector<uint32_t>>& submeshes) {
|
||||
int id = 0;
|
||||
for (auto& f : group.faces) {
|
||||
for (auto& v : f.vertices) {
|
||||
Vertex vertex;
|
||||
vertex.position = float4(_vertices[v.vid - 1], 1.0f);
|
||||
vertex.normal = _normals[v.nid - 1];
|
||||
vertex.uv0 = _texcoords[v.tid - 1].xy();
|
||||
vertices.push_back(vertex);
|
||||
submeshes[f.mid].push_back(id);
|
||||
++id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetActiveMaterial(const std::string& name) {
|
||||
for (size_t i = 0; i < _materials.size(); ++i) {
|
||||
if (_materials[i] == name) {
|
||||
_activeMatId = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
_activeMatId = _materials.size();
|
||||
_materials.push_back(name);
|
||||
}
|
||||
int _activeMatId;
|
||||
std::string _mtlLibName;
|
||||
std::vector<float3> _vertices;
|
||||
std::vector<float3> _normals;
|
||||
std::vector<float3> _texcoords;
|
||||
std::vector<std::string> _materials;
|
||||
std::vector<ObjGroup> _groups;
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "Object.h"
|
||||
#include "Archive.h"
|
||||
|
||||
std::map<ObjectRegistry::instance_id_t, std::weak_ptr<Object>> ObjectRegistry::_registry;
|
||||
|
||||
std::atomic<ObjectRegistry::instance_id_t> ObjectRegistry::_last_index = 0;
|
||||
|
||||
Object::Object():_instance_id(-1){
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<Object> Object::create(){
|
||||
auto result = std::shared_ptr<Object>(new Object());
|
||||
result->Register();
|
||||
return result;
|
||||
}
|
||||
|
||||
Object::~Object(){
|
||||
ObjectRegistry::remove_object(_instance_id);
|
||||
}
|
||||
|
||||
void Object::Register(){
|
||||
_instance_id = ObjectRegistry::add_object(shared_from_this());
|
||||
}
|
||||
|
||||
void Object::serialize(Archive& archive) {
|
||||
archive << _name;
|
||||
}
|
||||
|
||||
ObjectRegistry::instance_id_t ObjectRegistry::add_object(std::shared_ptr<Object> object) {
|
||||
auto result = _last_index++;
|
||||
_registry[result] = object;
|
||||
return result;
|
||||
}
|
||||
|
||||
void ObjectRegistry::remove_object(instance_id_t object) {
|
||||
_registry.erase(object);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
#ifndef Object_h__
|
||||
#define Object_h__
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <windows.h>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include "Asset.h"
|
||||
|
||||
class Object;
|
||||
class OutputArchive;
|
||||
|
||||
class ObjectRegistry {
|
||||
public:
|
||||
using instance_id_t = uint64_t;
|
||||
friend class Object;
|
||||
private:
|
||||
static instance_id_t add_object(std::shared_ptr<Object> object);
|
||||
static void remove_object(instance_id_t object);
|
||||
static std::map<instance_id_t, std::weak_ptr<Object>> _registry;
|
||||
static std::atomic<instance_id_t> _last_index;
|
||||
};
|
||||
|
||||
class Archive;
|
||||
class Object : public std::enable_shared_from_this<Object>{
|
||||
public:
|
||||
using instance_id_t = ObjectRegistry::instance_id_t;
|
||||
virtual void serialize(Archive& archive);
|
||||
|
||||
virtual void construct() {
|
||||
|
||||
}
|
||||
|
||||
virtual std::wstring get_type_name() const{
|
||||
return L"Object";
|
||||
}
|
||||
|
||||
std::shared_ptr<Object> as_object(){
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static std::vector<std::shared_ptr<T>> FindObjectsOfType() {
|
||||
std::vector<std::shared_ptr<T>> result;
|
||||
auto& registry = ObjectRegistry::_registry;
|
||||
for(auto& pair : registry){
|
||||
auto obj = pair.second.lock();
|
||||
auto targetObj = std::dynamic_pointer_cast<T>(obj);
|
||||
if(targetObj != nullptr){
|
||||
result.push_back(targetObj);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::shared_ptr<Object> Find(const AssetFileLink& link)
|
||||
{
|
||||
auto& registry = ObjectRegistry::_registry;
|
||||
for (auto& pair : registry) {
|
||||
auto obj = pair.second.lock();
|
||||
if(obj != nullptr && obj->GetFileLink() == link)
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static std::shared_ptr<Object> create();
|
||||
virtual ~Object();
|
||||
|
||||
const std::wstring& get_name() const{
|
||||
return _name;
|
||||
}
|
||||
|
||||
void SetName(const std::wstring& name){
|
||||
_name = name;
|
||||
}
|
||||
|
||||
instance_id_t GetInstanceId() const{
|
||||
return _instance_id;
|
||||
}
|
||||
|
||||
const AssetFileLink& GetFileLink() const{
|
||||
return _fileLink;
|
||||
}
|
||||
void SetLink(const AssetFileLink& link){
|
||||
_fileLink = link;
|
||||
}
|
||||
protected:
|
||||
void Register();
|
||||
Object();
|
||||
AssetFileLink _fileLink;
|
||||
instance_id_t _instance_id;
|
||||
private:
|
||||
std::wstring _name;
|
||||
};
|
||||
|
||||
#endif // Object_h__
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "ObjectsFactory.h"
|
||||
|
||||
|
||||
void ObjectsFactory::register_factory(factory_function factory, const std::wstring& class_name) {
|
||||
|
||||
_factory_functions[class_name] = factory;
|
||||
}
|
||||
|
||||
ObjectsFactory& ObjectsFactory::instance()
|
||||
{
|
||||
static ObjectsFactory instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::shared_ptr<Object> ObjectsFactory::create_object(const std::wstring& class_name) const {
|
||||
try {
|
||||
return _factory_functions.at(class_name)();
|
||||
} catch (...) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifndef ComponentFactory_h__
|
||||
#define ComponentFactory_h__
|
||||
|
||||
#include "ForwardDeclarations.h"
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include "Object.h"
|
||||
|
||||
class ObjectsFactory {
|
||||
public:
|
||||
typedef std::function<std::shared_ptr<Object>()> factory_function;
|
||||
typedef std::map<std::wstring, factory_function> factory_container;
|
||||
|
||||
static ObjectsFactory& instance();
|
||||
void register_factory(factory_function factory, const std::wstring& class_name);
|
||||
std::shared_ptr<Object> create_object(const std::wstring& class_name) const;
|
||||
|
||||
template<typename T>
|
||||
std::shared_ptr<T> create_object(){
|
||||
return std::dynamic_pointer_cast<T>(create_object(T::type_name(), game_object));
|
||||
}
|
||||
private:
|
||||
factory_container _factory_functions;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct ObjectFactory {
|
||||
typedef std::shared_ptr<T> object_pointer_t;
|
||||
ObjectFactory() {
|
||||
ObjectsFactory::instance().register_factory(&factory_func, T::type_name());
|
||||
}
|
||||
static std::shared_ptr<Object> factory_func() {
|
||||
return std::static_pointer_cast<Object>(T::create());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#define LOBJECT(__type_name, __base_type) \
|
||||
class __type_name;\
|
||||
static ObjectFactory<__type_name> __type_name##_factory;\
|
||||
class __type_name : public __base_type {\
|
||||
public:\
|
||||
static std::wstring type_name() {\
|
||||
return L#__type_name;\
|
||||
}\
|
||||
std::wstring get_type_name() const override{\
|
||||
return L#__type_name;\
|
||||
}\
|
||||
static std::shared_ptr<__type_name> create() {\
|
||||
auto result = std::shared_ptr<__type_name>(new __type_name());\
|
||||
result->Register();\
|
||||
result->construct();\
|
||||
return result;\
|
||||
}
|
||||
|
||||
|
||||
#endif // ComponentFactory_h__
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef OutputArchive_h__
|
||||
#define OutputArchive_h__
|
||||
|
||||
#include "Archive.h"
|
||||
#include "Object.h"
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
class OutputArchive : public Archive {
|
||||
public:
|
||||
OutputArchive(std::shared_ptr<std::ostream> stream)
|
||||
:_stream(stream) {
|
||||
// _stream = std::ofstream(path, std::ios::binary);
|
||||
}
|
||||
|
||||
virtual bool is_loading() const override {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_type get_offset() const override {
|
||||
return _stream->tellp();
|
||||
}
|
||||
|
||||
void set_offset(size_type offset) override {
|
||||
_stream->seekp(offset, std::ios::beg);
|
||||
}
|
||||
|
||||
virtual void serialize(void* data, size_t size) override {
|
||||
_stream->write(reinterpret_cast<char*>(data), size);
|
||||
}
|
||||
|
||||
virtual void flush() override {
|
||||
if(_stream->good()){
|
||||
_stream->flush();
|
||||
}
|
||||
}
|
||||
|
||||
~OutputArchive() {
|
||||
flush();
|
||||
}
|
||||
std::shared_ptr<std::ostream> GetStream()
|
||||
{
|
||||
return _stream;
|
||||
}
|
||||
private:
|
||||
std::shared_ptr<std::ostream> _stream;
|
||||
std::vector<std::shared_ptr<Object>> _processed_objects;
|
||||
};
|
||||
|
||||
|
||||
#endif // OutputArchive_h__
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <stdint.h>
|
||||
#include "Renderer.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class RenderOutput {
|
||||
public:
|
||||
|
||||
virtual ~RenderOutput() {
|
||||
}
|
||||
virtual uint32_t GetWidth() = 0;
|
||||
virtual uint32_t GetHeight() = 0;
|
||||
|
||||
//virtual CD3DX12_CPU_DESCRIPTOR_HANDLE GetRenderTargetDescriptor(uint32_t id) = 0;
|
||||
//virtual CD3DX12_CPU_DESCRIPTOR_HANDLE GetDepthStencilDescriptor(uint32_t id) = 0;
|
||||
|
||||
//virtual ID3D12ResourcePtr GetRenderTarget(uint32_t id) = 0;
|
||||
//virtual ID3D12ResourcePtr GetDepthBuffer(uint32_t id) = 0;
|
||||
|
||||
virtual void Present() = 0;
|
||||
virtual void OnPreRender(RendererPtr renderer) = 0;
|
||||
|
||||
virtual uint32_t GetCurrentBufferIndex() = 0;
|
||||
virtual uint32_t GetBuffersCount() = 0;
|
||||
protected:
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<RenderOutput> RenderOutputPtr;
|
||||
@@ -0,0 +1,81 @@
|
||||
#include "RenderTargetOutput.h"
|
||||
/*
|
||||
std::shared_ptr<RenderTargetOutput> RenderTargetOutput::Create(RendererPtr renderer) {
|
||||
return std::shared_ptr<RenderTargetOutput>(new RenderTargetOutput(renderer));
|
||||
}
|
||||
RenderTargetOutput::RenderTargetOutput(RendererPtr renderer)
|
||||
:_renderer(renderer) {
|
||||
|
||||
}
|
||||
uint32_t RenderTargetOutput::GetWidth() {
|
||||
if (_rt == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
_rt->GetDesc(&desc);
|
||||
return desc.Width;
|
||||
}
|
||||
uint32_t RenderTargetOutput::GetHeight() {
|
||||
if (_rt == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
_rt->GetDesc(&desc);
|
||||
return desc.Height;
|
||||
}
|
||||
ID3D11RenderTargetViewPtr RenderTargetOutput::GetRenderTargetView() {
|
||||
return _rtView;
|
||||
}
|
||||
ID3D11DepthStencilViewPtr RenderTargetOutput::GetDepthStencilView() {
|
||||
return _dsView;
|
||||
}
|
||||
void RenderTargetOutput::Present() {
|
||||
|
||||
}
|
||||
void RenderTargetOutput::OnPreRender(RendererPtr renderer) {
|
||||
|
||||
}
|
||||
void RenderTargetOutput::Resize(uint32_t width, uint32_t height) {
|
||||
if (_rt != nullptr) {
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
_rt->GetDesc(&desc);
|
||||
if (desc.Width == width && desc.Height == height) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_rt = nullptr;
|
||||
_ds = nullptr;
|
||||
_rtView = nullptr;
|
||||
_dsView = nullptr;
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc = { 0 };
|
||||
desc.Width = width;
|
||||
desc.Height = height;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
auto hr = _renderer->GetDevice()->CreateTexture2D(&desc, nullptr, &_rt);
|
||||
hr = _renderer->GetDevice()->CreateRenderTargetView(_rt, nullptr, &_rtView);
|
||||
|
||||
D3D11_TEXTURE2D_DESC descDepth;
|
||||
descDepth.Width = width;
|
||||
descDepth.Height = height;
|
||||
descDepth.MipLevels = 1;
|
||||
descDepth.ArraySize = 1;
|
||||
descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
descDepth.SampleDesc.Count = 1;
|
||||
descDepth.SampleDesc.Quality = 0;
|
||||
descDepth.Usage = D3D11_USAGE_DEFAULT;
|
||||
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
||||
descDepth.CPUAccessFlags = 0;
|
||||
descDepth.MiscFlags = 0;
|
||||
hr = _renderer->GetDevice()->CreateTexture2D(&descDepth, NULL, &_ds);
|
||||
hr = _renderer->GetDevice()->CreateDepthStencilView(_ds, nullptr, &_dsView);
|
||||
}*/
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "RenderOutput.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
|
||||
/*
|
||||
class RenderTargetOutput : public RenderOutput {
|
||||
public:
|
||||
static std::shared_ptr<RenderTargetOutput> Create(RendererPtr renderer);
|
||||
virtual uint32_t GetWidth() override;
|
||||
virtual uint32_t GetHeight() override;
|
||||
virtual ID3D11RenderTargetViewPtr GetRenderTargetView() override;
|
||||
virtual ID3D11DepthStencilViewPtr GetDepthStencilView() override;
|
||||
virtual void Present() override;
|
||||
virtual void OnPreRender(RendererPtr renderer) override;
|
||||
void Resize(uint32_t width, uint32_t height);
|
||||
private:
|
||||
RenderTargetOutput(RendererPtr renderer);
|
||||
ID3D11DepthStencilViewPtr _dsView;
|
||||
ID3D11RenderTargetViewPtr _rtView;
|
||||
ID3D11Texture2DPtr _ds;
|
||||
ID3D11Texture2DPtr _rt;
|
||||
RendererPtr _renderer;
|
||||
};*/
|
||||
@@ -0,0 +1,219 @@
|
||||
#include "Renderer.h"
|
||||
#include <iostream>
|
||||
#ifdef WIN32
|
||||
#include <vulkan/vulkan_win32.h>
|
||||
#endif
|
||||
|
||||
bool Renderer::Init() {
|
||||
_vulkanLibrary = std::make_shared<VulkanDynamicLibrary>();
|
||||
|
||||
auto layers = _vulkanLibrary->getSupportedLayers();
|
||||
|
||||
if (std::find_if(layers.begin(), layers.end(), [](VkLayerProperties& layer) { return std::string(layer.layerName) == "VK_LAYER_KHRONOS_validation"; }) == layers.end()) {
|
||||
throw std::runtime_error("Validation layer not found");
|
||||
}
|
||||
std::vector<std::string> instanceLayers;
|
||||
instanceLayers.push_back("VK_LAYER_KHRONOS_validation");
|
||||
|
||||
VulkanApplicationInfo appInfo("Test project", 1, "Test");
|
||||
|
||||
std::vector<std::string> requiredExtensions;
|
||||
requiredExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
#ifdef WIN32
|
||||
requiredExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
|
||||
#endif
|
||||
|
||||
_vulkanInstance = _vulkanLibrary->createInstance(appInfo, 0, instanceLayers, requiredExtensions);
|
||||
|
||||
auto physicalDevices = _vulkanInstance->enumeratePhysicalDevices();
|
||||
auto physicalDevice = physicalDevices[0];
|
||||
|
||||
auto families = physicalDevice->getQueueFamilyProperties();
|
||||
|
||||
//Find queues
|
||||
for (std::uint32_t i = 0; i < static_cast<std::uint32_t>(families.size()); ++i) {
|
||||
if (!_presentQueueFamilyIndex.has_value() && families[i].queueCount > 0 && physicalDevice->getPresentationSupport(i)) {
|
||||
_presentQueueFamilyIndex = i;
|
||||
std::cout << "Found present queue: " << i << std::endl;
|
||||
}
|
||||
|
||||
if (!_graphicsQueueFamilyIndex.has_value() && families[i].isGraphics() && families[i].queueCount > 0) {
|
||||
std::cout << "Found render queue: " << i << std::endl;
|
||||
_graphicsQueueFamilyIndex = i;
|
||||
}
|
||||
|
||||
if (_graphicsQueueFamilyIndex.has_value() && _presentQueueFamilyIndex.has_value()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_graphicsQueueFamilyIndex.has_value()) {
|
||||
throw std::runtime_error("Failed to find graphics queue family");
|
||||
}
|
||||
if (!_presentQueueFamilyIndex.has_value()) {
|
||||
throw std::runtime_error("Failed to find present queue family");
|
||||
}
|
||||
|
||||
|
||||
std::vector<VulkanQueueCreateInfo> queueDescriptions;
|
||||
if (_graphicsQueueFamilyIndex.has_value()) {
|
||||
queueDescriptions.push_back(VulkanQueueCreateInfo(_graphicsQueueFamilyIndex.value(), { 1.0f }));
|
||||
}
|
||||
if (_presentQueueFamilyIndex.has_value()) {
|
||||
if (_graphicsQueueFamilyIndex.value() != _presentQueueFamilyIndex.value()) {
|
||||
queueDescriptions.push_back(VulkanQueueCreateInfo(_presentQueueFamilyIndex.value(), { 1.0f }));
|
||||
}
|
||||
}
|
||||
|
||||
auto deviceExtensions = physicalDevice->getExtensions();
|
||||
std::vector<const char*> requiredDeviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
|
||||
auto swapChainExt = std::find_if(deviceExtensions.begin(), deviceExtensions.end(), [&requiredDeviceExtensions](VkExtensionProperties ext) { return std::string(requiredDeviceExtensions[0]) == ext.extensionName; });
|
||||
if (swapChainExt == deviceExtensions.end()) {
|
||||
throw std::runtime_error("Failed to find device with swap chain extension");
|
||||
}
|
||||
|
||||
_logicalDevice = PVulkanLogicalDevice(new VulkanLogicalDevice(physicalDevice, requiredDeviceExtensions, {}, queueDescriptions));
|
||||
|
||||
|
||||
//PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR p;
|
||||
//_vulkanInstance->functions().
|
||||
|
||||
/*
|
||||
|
||||
// Describe and create the command queue.
|
||||
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
||||
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
|
||||
device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&_directCommandQueue));
|
||||
device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&_directCommandAllocator));
|
||||
device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, _directCommandAllocator.Get(), nullptr, IID_PPV_ARGS(&_directCommandList));
|
||||
|
||||
|
||||
//create descriptor heaps
|
||||
|
||||
constexpr size_t descriptorHeapsSize = 512;
|
||||
|
||||
D3D12_DESCRIPTOR_HEAP_DESC srvHeapDesc = {};
|
||||
srvHeapDesc.NumDescriptors = descriptorHeapsSize;
|
||||
srvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||
srvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||
hr = device->CreateDescriptorHeap(&srvHeapDesc, IID_PPV_ARGS(&_srvDescriptorsHeap));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
FatalError(L"Failed to create SRV descriptors heap");
|
||||
}
|
||||
_srvDescriptorsHeap->SetName(L"SRV Heap");
|
||||
|
||||
_srvDescriptorAllocator = std::make_shared<D3d12DescriptorHeapAllocator>(_srvDescriptorsHeap);
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
//std::shared_ptr<D3d12DescriptorHeapAllocator> Renderer::getSrvDescriptorsAllocator(){
|
||||
// return _srvDescriptorAllocator;
|
||||
//}
|
||||
|
||||
//ComPtr<ID3D12GraphicsCommandList> Renderer::BeginCommandList(){
|
||||
// auto HR = _directCommandAllocator->Reset();
|
||||
// HR = _directCommandList->Reset(_directCommandAllocator.Get(), nullptr);
|
||||
// return _directCommandList;
|
||||
//}
|
||||
|
||||
void Renderer::EndCommandList(){
|
||||
//_directCommandList->Close();
|
||||
//ID3D12CommandList* ppCommandLists[] = { _directCommandList.Get()};
|
||||
//_directCommandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
|
||||
}
|
||||
|
||||
void Renderer::WaitCommandsQueue(){
|
||||
//ID3D12Fence* fence = nullptr;
|
||||
//HRESULT hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence));
|
||||
//if (hr)
|
||||
// return;
|
||||
//
|
||||
//auto eventHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
//
|
||||
//_directCommandQueue->Signal(fence, 1);
|
||||
//fence->SetEventOnCompletion(1, eventHandle);
|
||||
//WaitForSingleObject(eventHandle, INFINITE);
|
||||
//
|
||||
//CloseHandle(eventHandle);
|
||||
//fence->Release();
|
||||
}
|
||||
|
||||
PVulkanLogicalDevice Renderer::GetLogicalDevice() {
|
||||
return _logicalDevice;
|
||||
}
|
||||
|
||||
//std::vector<IDXGIOutput1Ptr> Renderer::EnumOutputs() {
|
||||
// IDXGIOutput1Ptr pOutput;
|
||||
// std::vector<IDXGIOutput1Ptr> vOutputs;
|
||||
// int outputId = 0;
|
||||
//
|
||||
// IDXGIOutputPtr o;
|
||||
// while (GetAdapter()->EnumOutputs(outputId, &o) != DXGI_ERROR_NOT_FOUND) {
|
||||
// o->QueryInterface(IID_PPV_ARGS(&pOutput));
|
||||
// vOutputs.push_back(pOutput);
|
||||
// pOutput = nullptr;
|
||||
// o = nullptr;
|
||||
// ++outputId;
|
||||
// }
|
||||
// return vOutputs;
|
||||
//}
|
||||
|
||||
// IDXGISwapChain1Ptr Renderer::CreateSwapChain(HWND window, bool windowed, uint32_t width, uint32_t height, uint32_t buffers_count, bool stereo) {
|
||||
// DXGI_SWAP_CHAIN_DESC1 swapChainDesc = { 0 };
|
||||
// swapChainDesc.Width = width;
|
||||
// swapChainDesc.Height = height;
|
||||
// swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
// swapChainDesc.Stereo = stereo;
|
||||
// swapChainDesc.SampleDesc.Count = 1;
|
||||
// swapChainDesc.SampleDesc.Quality = 0;
|
||||
// swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
// swapChainDesc.BufferCount = buffers_count;
|
||||
// swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
|
||||
// swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
||||
// swapChainDesc.Flags = 0;
|
||||
// swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
|
||||
|
||||
// /*DXGI_SWAP_CHAIN_FULLSCREEN_DESC fullscreenDesc = { 0 };
|
||||
// fullscreenDesc.RefreshRate = {60 ,0};
|
||||
// fullscreenDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
|
||||
// fullscreenDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
|
||||
// fullscreenDesc.Windowed = windowed;*/
|
||||
|
||||
// IDXGISwapChain1Ptr result;
|
||||
// auto hr = GetFactory()->CreateSwapChainForHwnd(_directCommandQueue.Get(), window, &swapChainDesc, nullptr, nullptr, &result);
|
||||
// if (S_OK != hr){
|
||||
// FatalError(TEXT("Failed to create swap chain"));
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
//auto backBufferFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
|
||||
//std::vector<DXGI_MODE_DESC1> Renderer::GetDisplayModes(DXGI_FORMAT format, IDXGIOutput1Ptr output) {
|
||||
// std::vector<DXGI_MODE_DESC1> result;
|
||||
// UINT numStereoModes = 0;
|
||||
// DXGI_MODE_DESC1 modes[1024];
|
||||
// auto enumFlags = DXGI_ENUM_MODES_STEREO;
|
||||
//
|
||||
// output->GetDisplayModeList1(format, enumFlags, &numStereoModes, 0);
|
||||
// output->GetDisplayModeList1(format, enumFlags, &numStereoModes, modes);
|
||||
//
|
||||
// for (UINT i = 0; i < numStereoModes; ++i) {
|
||||
// result.push_back(modes[i]);
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
|
||||
//std::vector<DXGI_MODE_DESC1> Renderer::GetStereoModes(std::vector<DXGI_MODE_DESC1>& modes) {
|
||||
// std::vector<DXGI_MODE_DESC1> result;
|
||||
// for (auto& m : modes) {
|
||||
// if (m.Stereo) {
|
||||
// result.push_back(m);
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include <dxgi1_3.h>
|
||||
#include <dxgi1_4.h>
|
||||
#include <dxgi1_5.h>
|
||||
#include <d3d11.h>
|
||||
#include <d3d12.h>
|
||||
#include <vector>
|
||||
#include "FatalError.h"
|
||||
#include <memory>
|
||||
#include <dxgidebug.h>
|
||||
#include <sstream>
|
||||
#include <RenderFramework/Vulkan/VulkanDynamicLibrary.h>
|
||||
#include <RenderFramework/Vulkan/VulkanLogicalDevice.h>
|
||||
#include <wrl.h>
|
||||
#include <optional>
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
bool Init();
|
||||
|
||||
PVulkanLogicalDevice GetLogicalDevice();
|
||||
|
||||
//ComPtr<IDXGIAdapter1> GetAdapter() {
|
||||
// return dxgiAdapter;
|
||||
//}
|
||||
//ComPtr<IDXGIFactory4> GetFactory() {
|
||||
// return dxgiFactory;
|
||||
//}
|
||||
|
||||
//ComPtr<ID3D12GraphicsCommandList> BeginCommandList();
|
||||
void EndCommandList();
|
||||
|
||||
//std::vector<IDXGIOutput1Ptr> EnumOutputs();
|
||||
//IDXGISwapChain1Ptr CreateSwapChain(HWND window, bool windowed, uint32_t width, uint32_t height, uint32_t buffers_count, bool stereo);
|
||||
//std::vector<DXGI_MODE_DESC1> GetDisplayModes(DXGI_FORMAT format, IDXGIOutput1Ptr output);
|
||||
//std::vector<DXGI_MODE_DESC1> GetStereoModes(std::vector<DXGI_MODE_DESC1>& modes);
|
||||
void WaitCommandsQueue();
|
||||
|
||||
//std::shared_ptr<D3d12DescriptorHeapAllocator> getSrvDescriptorsAllocator();
|
||||
private:
|
||||
std::shared_ptr<VulkanDynamicLibrary> _vulkanLibrary;
|
||||
IntrusivePtr<VulkanInstance> _vulkanInstance;
|
||||
PVulkanLogicalDevice _logicalDevice;
|
||||
|
||||
std::optional<std::uint32_t> _graphicsQueueFamilyIndex;
|
||||
std::optional<std::uint32_t> _presentQueueFamilyIndex;
|
||||
|
||||
//ComPtr<IDXGIInfoQueue> dxgiInfoQueue;
|
||||
//ID3D12DevicePtr device;
|
||||
//IDXGIAdapter1Ptr dxgiAdapter;
|
||||
//IDXGIFactory4Ptr dxgiFactory;
|
||||
//
|
||||
//ComPtr<ID3D12CommandQueue> _directCommandQueue;
|
||||
//ComPtr<ID3D12GraphicsCommandList> _directCommandList;
|
||||
//ComPtr<ID3D12CommandAllocator> _directCommandAllocator;
|
||||
//
|
||||
//ComPtr<ID3D12DescriptorHeap> _srvDescriptorsHeap;
|
||||
//std::shared_ptr<D3d12DescriptorHeapAllocator> _srvDescriptorAllocator;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Renderer> RendererPtr;
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "Scene.h"
|
||||
#include "GameObject.h"
|
||||
|
||||
void Scene::tick(float deltaTime) {
|
||||
for (auto go : objects) {
|
||||
go->tick(deltaTime);
|
||||
}
|
||||
}
|
||||
void Scene::SetName(const std::string& name) {
|
||||
_name = name;
|
||||
}
|
||||
std::string Scene::GetName() {
|
||||
return _name;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef Scene_h__
|
||||
#define Scene_h__
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "ForwardDeclarations.h"
|
||||
#include <string>
|
||||
#include "Gizmos.h"
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
Scene() {
|
||||
_gizmos.Init();
|
||||
}
|
||||
std::vector<GameObjectPtr> objects;
|
||||
void tick(float deltaTime);
|
||||
void SetName(const std::string& name);
|
||||
std::string GetName();
|
||||
Gizmos& GetGizmos() {
|
||||
return _gizmos;
|
||||
}
|
||||
private:
|
||||
Gizmos _gizmos;
|
||||
std::string _name;
|
||||
};
|
||||
#endif // Scene_h__
|
||||
@@ -0,0 +1,308 @@
|
||||
#include "SceneRenderer.h"
|
||||
#include "GameObject.h"
|
||||
#include "Transform.h"
|
||||
#include "Texture.h"
|
||||
|
||||
SceneRenderer::SceneRenderer()
|
||||
{
|
||||
auto renderer = LEngine::Instance()->GetRenderer();
|
||||
auto device = renderer->GetLogicalDevice();
|
||||
|
||||
//create samplers heap
|
||||
//D3D12_DESCRIPTOR_HEAP_DESC samplers_heap_desc;
|
||||
//samplers_heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||
//samplers_heap_desc.NodeMask = 0;
|
||||
//samplers_heap_desc.NumDescriptors = 1;
|
||||
//samplers_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
|
||||
// HR_ASSERT(device->CreateDescriptorHeap(&samplers_heap_desc, IID_PPV_ARGS(&samplers_heap)));
|
||||
//samplers_heap->SetName(L"Samplers heap");
|
||||
|
||||
//create texture sampler
|
||||
/*D3D12_SAMPLER_DESC sampler_desc = {};
|
||||
sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
sampler_desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
sampler_desc.MinLOD = 0;
|
||||
sampler_desc.MaxLOD = D3D12_FLOAT32_MAX;
|
||||
sampler_desc.MipLODBias = 0.0f;
|
||||
sampler_desc.MaxAnisotropy = 1;
|
||||
sampler_desc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;*/
|
||||
|
||||
// renderer->GetDevice()->CreateSampler(&sampler_desc, samplers_heap->GetCPUDescriptorHandleForHeapStart());
|
||||
}
|
||||
|
||||
void SceneRenderer::RenderScene(RendererPtr renderer, ScenePtr scene, CameraPtr camera, std::shared_ptr<RenderOutput> renderScreen) {
|
||||
camera->aspect = (float)renderScreen->GetWidth() / (float)renderScreen->GetHeight();
|
||||
renderScreen->OnPreRender(renderer);
|
||||
|
||||
D3D12_VIEWPORT viewport = {};
|
||||
viewport.TopLeftX = 0;
|
||||
viewport.TopLeftY = 0;
|
||||
viewport.Width = (float)renderScreen->GetWidth();
|
||||
viewport.Height = (float)renderScreen->GetHeight();
|
||||
viewport.MinDepth = 0;
|
||||
viewport.MaxDepth = 1;
|
||||
|
||||
|
||||
D3D12_RECT scissorRect = {};
|
||||
scissorRect.left = 0;
|
||||
scissorRect.top = 0;
|
||||
scissorRect.right = renderScreen->GetWidth();
|
||||
scissorRect.bottom = renderScreen->GetHeight();
|
||||
|
||||
// auto commandList = renderer->BeginCommandList();
|
||||
// auto rt = renderScreen->GetRenderTarget(renderScreen->GetCurrentBufferIndex());
|
||||
// commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(rt.Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));
|
||||
// auto rtvHandle = renderScreen->GetRenderTargetDescriptor(renderScreen->GetCurrentBufferIndex());
|
||||
// auto dsvHandle = renderScreen->GetDepthStencilDescriptor(renderScreen->GetCurrentBufferIndex());
|
||||
// commandList->OMSetRenderTargets(1, &rtvHandle, FALSE, &dsvHandle);
|
||||
//
|
||||
// const float clearColor[] = { 0.1f, 0.1f, 0.14f, 1.0f };
|
||||
// commandList->ClearRenderTargetView(rtvHandle, clearColor, 0, nullptr);
|
||||
// commandList->ClearDepthStencilView(dsvHandle, D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 1.0f, 0, 0, nullptr);
|
||||
|
||||
//renderer->EndCommandList();
|
||||
// renderer->WaitCommandsQueue();
|
||||
|
||||
// commandList->RSSetViewports(1, &viewport);
|
||||
// commandList->RSSetScissorRects(1, &scissorRect);
|
||||
|
||||
std::vector<ComPtr<ID3D12RootSignature>> signatures;
|
||||
std::vector<ComPtr<ID3D12PipelineState>> pso;
|
||||
|
||||
|
||||
//draw all objects
|
||||
for (auto obj : scene->objects) {
|
||||
auto mr = obj->GetComponent<MeshRenderer>();
|
||||
if (mr != nullptr) {
|
||||
auto mesh = mr->GetMesh();
|
||||
if (mesh != nullptr) {
|
||||
for (uint32_t i = 0; i < mesh->GetSubmeshCount(); ++i) {
|
||||
auto mat = mr->GetMaterials()[i];
|
||||
auto submesh = mesh->GetSubmeshes()[i];
|
||||
if (mat == nullptr || submesh == nullptr) {
|
||||
continue;
|
||||
}
|
||||
auto& params = mat->GetParametersBlock();
|
||||
|
||||
//params.SetShaderResource()
|
||||
|
||||
//set system variables
|
||||
auto tf = obj->transform->GetGlobalTransform();
|
||||
auto view = camera->worldToCameraMatrix();
|
||||
auto proj = camera->projectionMatrix();
|
||||
params.SetValue("mWorld", transpose(tf));
|
||||
params.SetValue("mView", transpose(view));
|
||||
params.SetValue("mProjection", transpose(proj));
|
||||
|
||||
auto camPos = camera->transform()->GetGlobalPosition();
|
||||
params.SetValue("cameraWorldPos", float4(camPos.x(), camPos.y(), camPos.z(), 0.0f));
|
||||
|
||||
mat->Apply();
|
||||
|
||||
|
||||
//create single element ranges for constant buffers
|
||||
std::vector<D3D12_ROOT_PARAMETER> root_parameters;
|
||||
|
||||
auto compiled_params = mat->GetCompiledParameters(ShaderType::Vs);
|
||||
|
||||
for(auto p : compiled_params.buffers)
|
||||
{
|
||||
D3D12_ROOT_DESCRIPTOR rootCBVDescriptor;
|
||||
rootCBVDescriptor.RegisterSpace = 0;
|
||||
rootCBVDescriptor.ShaderRegister = p.bindPoint;
|
||||
|
||||
D3D12_ROOT_PARAMETER root_param = {};
|
||||
root_param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
|
||||
root_param.Descriptor = rootCBVDescriptor;
|
||||
|
||||
root_parameters.push_back(root_param);
|
||||
}
|
||||
|
||||
|
||||
size_t srvParamOffset = root_parameters.size();
|
||||
size_t srvParamCount = 0;
|
||||
|
||||
// auto srvHeapAllocator = renderer->getSrvDescriptorsAllocator();
|
||||
// auto srvHeap = srvHeapAllocator->getHeap();
|
||||
|
||||
std::vector<D3D12_DESCRIPTOR_RANGE> srvRanges[2];
|
||||
//size_t srvParamCount =
|
||||
//VS + PS
|
||||
for(int id = 0; id < 2; ++id){
|
||||
auto shader_params = mat->GetCompiledParameters((ShaderType)id);
|
||||
|
||||
for(auto r : shader_params.resources){
|
||||
if(r.type == D3D_SIT_TEXTURE)
|
||||
{
|
||||
auto param = mat->GetParametersBlock().GetParameterByName(r.name);
|
||||
auto texParam = std::static_pointer_cast<ShaderTextureParameter>(param);
|
||||
auto tex = texParam == nullptr ? nullptr : texParam->value;
|
||||
|
||||
D3D12_DESCRIPTOR_RANGE range{};
|
||||
range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
|
||||
range.RegisterSpace = 0;
|
||||
range.NumDescriptors = 1;
|
||||
range.BaseShaderRegister = r.bindPoint;
|
||||
// range.OffsetInDescriptorsFromTableStart = srvHeapAllocator->getDescriptorId(tex->srvDescriptor);
|
||||
srvRanges[id].push_back(range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//for each shader => create root table parameter
|
||||
for(size_t s = 0; s < 2; ++s)
|
||||
{
|
||||
auto& ranges = srvRanges[s];
|
||||
if(!ranges.empty())
|
||||
{
|
||||
D3D12_ROOT_DESCRIPTOR_TABLE srvTable;
|
||||
srvTable.NumDescriptorRanges = ranges.size();
|
||||
srvTable.pDescriptorRanges = &ranges[0];
|
||||
|
||||
D3D12_ROOT_PARAMETER srvParameter;
|
||||
srvParameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
|
||||
srvParameter.ShaderVisibility = ((ShaderType)s == ShaderType::Vs) ? D3D12_SHADER_VISIBILITY_VERTEX : D3D12_SHADER_VISIBILITY_PIXEL;
|
||||
srvParameter.DescriptorTable = srvTable;
|
||||
root_parameters.push_back(srvParameter);
|
||||
|
||||
srvParamCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create a static sampler
|
||||
D3D12_STATIC_SAMPLER_DESC sampler = {};
|
||||
sampler.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
|
||||
sampler.AddressU = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
|
||||
sampler.AddressV = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
|
||||
sampler.AddressW = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
|
||||
sampler.MipLODBias = 0;
|
||||
sampler.MaxAnisotropy = 0;
|
||||
sampler.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER;
|
||||
sampler.BorderColor = D3D12_STATIC_BORDER_COLOR_TRANSPARENT_BLACK;
|
||||
sampler.MinLOD = 0.0f;
|
||||
sampler.MaxLOD = D3D12_FLOAT32_MAX;
|
||||
sampler.ShaderRegister = 0;
|
||||
sampler.RegisterSpace = 0;
|
||||
sampler.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
|
||||
|
||||
|
||||
//create root signature
|
||||
// CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
|
||||
// rootSignatureDesc.Init(root_parameters.size(), // we have 1 root parameter
|
||||
// &root_parameters[0], // a pointer to the beginning of our root parameters array
|
||||
// 1,
|
||||
// &sampler,
|
||||
// D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | // we can deny shader stages here for better performance
|
||||
// D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS |
|
||||
// D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
|
||||
// D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS);
|
||||
|
||||
|
||||
ComPtr<ID3DBlob> signature;
|
||||
ComPtr<ID3DBlob> signatureErrors;
|
||||
// auto hr = D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &signatureErrors);
|
||||
// if (FAILED(hr)) {
|
||||
// FatalError(L"Failed to serialize root signature");
|
||||
// }
|
||||
|
||||
ComPtr<ID3D12RootSignature> rootSignature;
|
||||
// hr = renderer->GetDevice()->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&rootSignature));
|
||||
// if (FAILED(hr)) {
|
||||
// FatalError(L"Failed to create root signature");
|
||||
// }
|
||||
|
||||
signatures.push_back(rootSignature);
|
||||
|
||||
|
||||
//create PSO
|
||||
DXGI_SAMPLE_DESC sampleDesc = {};
|
||||
sampleDesc.Count = 1;
|
||||
|
||||
D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
|
||||
psoDesc.pRootSignature = rootSignature.Get();
|
||||
psoDesc.InputLayout = mr->GetInputLayout();
|
||||
psoDesc.VS = mat->GetShader()->GetShader(ShaderType::Vs)->get_bytecode();
|
||||
psoDesc.PS = mat->GetShader()->GetShader(ShaderType::Ps)->get_bytecode();
|
||||
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
|
||||
psoDesc.RTVFormats[0] = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
psoDesc.SampleDesc = sampleDesc;
|
||||
psoDesc.SampleMask = 0xffffffff;
|
||||
// psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
|
||||
// psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
|
||||
// psoDesc.NumRenderTargets = 1;
|
||||
// psoDesc.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT);
|
||||
// psoDesc.DSVFormat = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
|
||||
auto device = renderer->GetLogicalDevice();
|
||||
|
||||
|
||||
// if (FAILED(hr)) {
|
||||
// FatalError(L"Failed to create PSO");
|
||||
// }
|
||||
|
||||
ComPtr<ID3D12PipelineState> pipelineStateObject;
|
||||
// hr = device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pipelineStateObject));
|
||||
pipelineStateObject->SetName(L"PSO");
|
||||
|
||||
|
||||
pso.push_back(pipelineStateObject);
|
||||
|
||||
|
||||
//commandList = renderer->BeginCommandList();
|
||||
|
||||
// commandList->SetPipelineState(pipelineStateObject.Get());
|
||||
|
||||
// commandList->SetGraphicsRootSignature(rootSignature.Get());
|
||||
|
||||
// commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
// auto vbView = mesh->GetVertexBufferView();
|
||||
|
||||
// commandList->IASetVertexBuffers(0, 1, &vbView);
|
||||
|
||||
// auto ibView = submesh->GetIndexBufferView();
|
||||
// commandList->IASetIndexBuffer(&ibView);
|
||||
|
||||
//commandList->SetGraphicsRootShaderResourceView()
|
||||
|
||||
|
||||
// ID3D12DescriptorHeap* descriptorHeaps[] = { srvHeap.Get() };
|
||||
// commandList->SetDescriptorHeaps(_countof(descriptorHeaps), descriptorHeaps);
|
||||
|
||||
|
||||
// for (size_t p = srvParamOffset; p < srvParamOffset + srvParamCount; ++p) {
|
||||
// commandList->SetGraphicsRootDescriptorTable(p, srvHeap->GetGPUDescriptorHandleForHeapStart());
|
||||
// }
|
||||
|
||||
// //apply constant buffers
|
||||
// for (size_t k = 0; k < compiled_params.buffers.size(); ++k) {
|
||||
// commandList->SetGraphicsRootConstantBufferView(k, compiled_params.buffers[k].buffer->GetGPUVirtualAddress());
|
||||
// }
|
||||
|
||||
|
||||
// commandList->DrawIndexedInstanced(submesh->GetIndicesCount(), 1, 0, 0, 0);
|
||||
|
||||
//renderer->EndCommandList();
|
||||
//renderer->WaitCommandsQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//commandList = renderer->BeginCommandList();
|
||||
// commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(rt.Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
|
||||
renderer->EndCommandList();
|
||||
renderer->WaitCommandsQueue();
|
||||
|
||||
|
||||
|
||||
renderScreen->Present();
|
||||
//signatures.clear();
|
||||
//renderer->reportLiveObjects();
|
||||
|
||||
scene->GetGizmos().PrepareRender();
|
||||
scene->GetGizmos().DrawAll(camera);
|
||||
scene->GetGizmos().Clear();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "LEngine.h"
|
||||
#include "Mesh.h"
|
||||
#include "MeshGenerator.h"
|
||||
#include "Scene.h"
|
||||
#include "Renderer.h"
|
||||
#include "Camera.h"
|
||||
#include "FatalError.h"
|
||||
#include "MeshRenderer.h"
|
||||
|
||||
#pragma comment(lib, "d3d11.lib")
|
||||
|
||||
class SceneRenderer {
|
||||
public:
|
||||
SceneRenderer();
|
||||
void RenderScene(RendererPtr renderer, ScenePtr scene, CameraPtr camera, std::shared_ptr<RenderOutput> renderScreen);
|
||||
private:
|
||||
ComPtr<ID3D12DescriptorHeap> samplers_heap;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
#include "Shader.h"
|
||||
#include <d3dcompiler.h>
|
||||
#include <fstream>
|
||||
#include "File.h"
|
||||
#include "LEngine.h"
|
||||
#include "AssetManager.h"
|
||||
#include "ShaderInclude.h"
|
||||
#include <filesystem>
|
||||
#include <SPIRV/GlslangToSpv.h>
|
||||
#include <glslang/Public/ShaderLang.h>
|
||||
#include <glslang/Public/ResourceLimits.h>
|
||||
|
||||
#pragma comment(lib, "D3dcompiler.lib")
|
||||
|
||||
static TBuiltInResource getShaderResources() {
|
||||
TBuiltInResource resources = {};
|
||||
resources.maxLights = 32;
|
||||
resources.maxClipPlanes = 6;
|
||||
resources.maxTextureUnits = 32;
|
||||
resources.maxTextureCoords = 32;
|
||||
resources.maxVertexAttribs = 64;
|
||||
resources.maxVertexUniformComponents = 4096;
|
||||
resources.maxVaryingFloats = 64;
|
||||
resources.maxVertexTextureImageUnits = 32;
|
||||
resources.maxCombinedTextureImageUnits = 80;
|
||||
resources.maxTextureImageUnits = 32;
|
||||
resources.maxFragmentUniformComponents = 4096;
|
||||
resources.maxDrawBuffers = 32;
|
||||
resources.maxVertexUniformVectors = 128;
|
||||
resources.maxVaryingVectors = 8;
|
||||
resources.maxFragmentUniformVectors = 16;
|
||||
resources.maxVertexOutputVectors = 16;
|
||||
resources.maxFragmentInputVectors = 15;
|
||||
resources.minProgramTexelOffset = -8;
|
||||
resources.maxProgramTexelOffset = 7;
|
||||
resources.maxClipDistances = 8;
|
||||
resources.maxComputeWorkGroupCountX = 65535;
|
||||
resources.maxComputeWorkGroupCountY = 65535;
|
||||
resources.maxComputeWorkGroupCountZ = 65535;
|
||||
resources.maxComputeWorkGroupSizeX = 1024;
|
||||
resources.maxComputeWorkGroupSizeY = 1024;
|
||||
resources.maxComputeWorkGroupSizeZ = 64;
|
||||
resources.maxComputeUniformComponents = 1024;
|
||||
resources.maxComputeTextureImageUnits = 16;
|
||||
resources.maxComputeImageUniforms = 8;
|
||||
resources.maxComputeAtomicCounters = 8;
|
||||
resources.maxComputeAtomicCounterBuffers = 1;
|
||||
resources.maxVaryingComponents = 60;
|
||||
resources.maxVertexOutputComponents = 64;
|
||||
resources.maxGeometryInputComponents = 64;
|
||||
resources.maxGeometryOutputComponents = 128;
|
||||
resources.maxFragmentInputComponents = 128;
|
||||
resources.maxImageUnits = 8;
|
||||
resources.maxCombinedImageUnitsAndFragmentOutputs = 8;
|
||||
resources.maxCombinedShaderOutputResources = 8;
|
||||
resources.maxImageSamples = 0;
|
||||
resources.maxVertexImageUniforms = 0;
|
||||
resources.maxTessControlImageUniforms = 0;
|
||||
resources.maxTessEvaluationImageUniforms = 0;
|
||||
resources.maxGeometryImageUniforms = 0;
|
||||
resources.maxFragmentImageUniforms = 8;
|
||||
resources.maxCombinedImageUniforms = 8;
|
||||
resources.maxGeometryTextureImageUnits = 16;
|
||||
resources.maxGeometryOutputVertices = 256;
|
||||
resources.maxGeometryTotalOutputComponents = 1024;
|
||||
resources.maxGeometryUniformComponents = 1024;
|
||||
resources.maxGeometryVaryingComponents = 64;
|
||||
resources.maxTessControlInputComponents = 128;
|
||||
resources.maxTessControlOutputComponents = 128;
|
||||
resources.maxTessControlTextureImageUnits = 16;
|
||||
resources.maxTessControlUniformComponents = 1024;
|
||||
resources.maxTessControlTotalOutputComponents = 4096;
|
||||
resources.maxTessEvaluationInputComponents = 128;
|
||||
resources.maxTessEvaluationOutputComponents = 128;
|
||||
resources.maxTessEvaluationTextureImageUnits = 16;
|
||||
resources.maxTessEvaluationUniformComponents = 1024;
|
||||
resources.maxTessPatchComponents = 120;
|
||||
resources.maxPatchVertices = 32;
|
||||
resources.maxTessGenLevel = 64;
|
||||
resources.maxViewports = 16;
|
||||
resources.maxVertexAtomicCounters = 0;
|
||||
resources.maxTessControlAtomicCounters = 0;
|
||||
resources.maxTessEvaluationAtomicCounters = 0;
|
||||
resources.maxGeometryAtomicCounters = 0;
|
||||
resources.maxFragmentAtomicCounters = 8;
|
||||
resources.maxCombinedAtomicCounters = 8;
|
||||
resources.maxAtomicCounterBindings = 1;
|
||||
resources.maxVertexAtomicCounterBuffers = 0;
|
||||
resources.maxTessControlAtomicCounterBuffers = 0;
|
||||
resources.maxTessEvaluationAtomicCounterBuffers = 0;
|
||||
resources.maxGeometryAtomicCounterBuffers = 0;
|
||||
resources.maxFragmentAtomicCounterBuffers = 1;
|
||||
resources.maxCombinedAtomicCounterBuffers = 1;
|
||||
resources.maxAtomicCounterBufferSize = 16384;
|
||||
resources.maxTransformFeedbackBuffers = 4;
|
||||
resources.maxTransformFeedbackInterleavedComponents = 64;
|
||||
resources.maxCullDistances = 8;
|
||||
resources.maxCombinedClipAndCullDistances = 8;
|
||||
resources.maxSamples = 4;
|
||||
resources.limits.nonInductiveForLoops = true;
|
||||
resources.limits.whileLoops = true;
|
||||
resources.limits.doWhileLoops = true;
|
||||
resources.limits.generalUniformIndexing = true;
|
||||
resources.limits.generalAttributeMatrixVectorIndexing = true;
|
||||
resources.limits.generalVaryingIndexing = true;
|
||||
resources.limits.generalSamplerIndexing = true;
|
||||
resources.limits.generalVariableIndexing = true;
|
||||
resources.limits.generalConstantMatrixVectorIndexing = true;
|
||||
return resources;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static EShLanguage getShaderLanguage(ShaderType stage) {
|
||||
switch(stage){
|
||||
case ShaderType::Vs:
|
||||
return EShLanguage::EShLangVertex;
|
||||
case ShaderType::Ps:
|
||||
return EShLanguage::EShLangFragment;
|
||||
default:
|
||||
throw std::runtime_error("Not yet implemented");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void* Shader::CompileSHader(const std::filesystem::path& filePath, ShaderType stage) {
|
||||
auto filePathString = filePath.string();
|
||||
|
||||
|
||||
std::string shaderCode;
|
||||
FileReadAllText(filePath.wstring(), shaderCode);
|
||||
|
||||
auto language = getShaderLanguage(stage);
|
||||
glslang::TProgram program;
|
||||
glslang::TShader shader(language);
|
||||
|
||||
const char* moduleSource = shaderCode.c_str();
|
||||
|
||||
const char* moduleName = filePathString.c_str();
|
||||
shader.setStringsWithLengthsAndNames(&moduleSource, nullptr, &moduleName, 1);
|
||||
|
||||
shader.setEnvInput(glslang::EShSourceGlsl, language, glslang::EShClientVulkan, 110);
|
||||
auto clientVersion = glslang::EShTargetVulkan_1_1;
|
||||
shader.setEnvClient(glslang::EShClientVulkan, clientVersion);
|
||||
shader.setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_0);
|
||||
|
||||
ShaderInclude includer;
|
||||
|
||||
|
||||
auto resources = getShaderResources();
|
||||
|
||||
std::string processedShader;
|
||||
auto messages = static_cast<EShMessages>(EShMsgSpvRules | EShMsgVulkanRules | EShMsgDefault | EShMsgDebugInfo);
|
||||
if (!shader.preprocess(&resources, clientVersion, ENoProfile, false, false, messages, &processedShader, includer)) {
|
||||
std::cout << "Shader preprocess failed" << std::endl;
|
||||
std::cout << shader.getInfoLog() << std::endl;
|
||||
std::cout << shader.getInfoDebugLog() << std::endl;
|
||||
throw std::runtime_error("Shader preprocess failed");
|
||||
}
|
||||
|
||||
if (!shader.parse(&resources, clientVersion, true, messages, includer)) {
|
||||
std::cout << "Shader parse failed" << std::endl;
|
||||
std::cout << shader.getInfoLog() << std::endl;
|
||||
std::cout << shader.getInfoDebugLog() << std::endl;
|
||||
throw std::runtime_error("Shader parse failed");
|
||||
}
|
||||
|
||||
program.addShader(&shader);
|
||||
|
||||
if (!program.link(messages) || !program.mapIO()) {
|
||||
throw std::runtime_error("Shader link failed");
|
||||
}
|
||||
|
||||
program.buildReflection();
|
||||
|
||||
program.dumpReflection();
|
||||
|
||||
|
||||
glslang::SpvOptions spvOptions;
|
||||
//DEBUG
|
||||
//spvOptions.generateDebugInfo = true;
|
||||
//spvOptions.disableOptimizer = true;
|
||||
//spvOptions.optimizeSize = false;
|
||||
|
||||
spvOptions.generateDebugInfo = false;
|
||||
spvOptions.disableOptimizer = false;
|
||||
spvOptions.optimizeSize = true;
|
||||
|
||||
spv::SpvBuildLogger logger;
|
||||
std::vector<uint32_t> spirv;
|
||||
GlslangToSpv(*program.getIntermediate(static_cast<EShLanguage>(language)), spirv, &logger, &spvOptions);
|
||||
|
||||
|
||||
//program.get
|
||||
|
||||
std::cout << "SPIR-V generation messages: " << logger.getAllMessages() << std::endl;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Shader::Shader(ComPtr<ID3D12Device> dev) :device(dev) {
|
||||
|
||||
}
|
||||
|
||||
ShaderPtr Shader::Create() {
|
||||
return std::shared_ptr<Shader>(nullptr);
|
||||
}
|
||||
|
||||
ShaderPtr Shader::Create(const std::filesystem::path& filePath) {
|
||||
auto shader = Create();
|
||||
shader->FromFile(AssetManager::Instance()->GetFullAssetPath(filePath));
|
||||
return shader;
|
||||
}
|
||||
|
||||
void Shader::FromFile(const std::filesystem::path& shaderFilePath) {
|
||||
|
||||
CompileSHader(shaderFilePath, ShaderType::Vs);
|
||||
//auto vsBlob = CompileSHader(shaderFilePath, "main_vs", "vs_5_0");
|
||||
//if(vsBlob != nullptr) {
|
||||
// ShaderDataPtr shader(new ShaderData());
|
||||
// shader->blob = vsBlob;
|
||||
// shaders[(int)ShaderType::Vs] = shader;
|
||||
//}
|
||||
//
|
||||
//auto psBlob = CompileSHader(shaderFilePath, "main_ps", "ps_5_0");
|
||||
//if(psBlob != nullptr) {
|
||||
// ShaderDataPtr shader(new ShaderData());
|
||||
// shader->blob = psBlob;
|
||||
// shaders[(int)ShaderType::Ps] = shader;
|
||||
//}
|
||||
}
|
||||
|
||||
ShaderDataPtr Shader::GetShader(ShaderType type) {
|
||||
return shaders[(uint32_t)type];
|
||||
}
|
||||
|
||||
ComPtr<ID3D12Device> Shader::GetDevice() {
|
||||
return device;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include "ForwardDeclarations.h"
|
||||
#include <d3d12.h>
|
||||
#include <d3d11.h>
|
||||
#include <wrl.h>
|
||||
#include <filesystem>
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
class ShaderData {
|
||||
public:
|
||||
ComPtr<ID3DBlob> blob;
|
||||
|
||||
D3D12_SHADER_BYTECODE get_bytecode() {
|
||||
D3D12_SHADER_BYTECODE bytecode = {};
|
||||
bytecode.BytecodeLength = blob->GetBufferSize();
|
||||
bytecode.pShaderBytecode = blob->GetBufferPointer();
|
||||
return bytecode;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<ShaderData> ShaderDataPtr;
|
||||
|
||||
enum class ShaderType {
|
||||
Vs,
|
||||
Ps,
|
||||
Gs,
|
||||
Hull,
|
||||
Domain,
|
||||
Count
|
||||
};
|
||||
|
||||
class Shader {
|
||||
public:
|
||||
std::wstring class_name() const {
|
||||
return L"Shader";
|
||||
|
||||
|
||||
}
|
||||
static ShaderPtr Create();
|
||||
static ShaderPtr Create(const std::filesystem::path& filePath);
|
||||
void FromFile(const std::filesystem::path& shaderFilePath);
|
||||
ShaderDataPtr GetShader(ShaderType type);
|
||||
ComPtr<ID3D12Device> GetDevice();
|
||||
private:
|
||||
Shader(ComPtr<ID3D12Device> dev);
|
||||
ShaderDataPtr shaders[(uint32_t)ShaderType::Count];
|
||||
ComPtr<ID3D12Device> device;
|
||||
void* CompileSHader(const std::filesystem::path& filename, ShaderType stage);
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3dcommon.h>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include "File.h"
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <filesystem>
|
||||
|
||||
#include <SPIRV/GlslangToSpv.h>
|
||||
#include <glslang/Public/ShaderLang.h>
|
||||
|
||||
|
||||
class ShaderInclude : public glslang::TShader::Includer {
|
||||
public:
|
||||
//ShaderInclude(std::wstring localDirectory){
|
||||
// _localPathStack.push(localDirectory);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
struct IncludeContext {
|
||||
std::filesystem::path path;
|
||||
std::vector<char> data;
|
||||
};
|
||||
|
||||
IncludeResult *includeLocal(const char *headerName, const char *includerName, size_t inclusionDepth) override {
|
||||
std::filesystem::path includerPath(includerName);
|
||||
auto includerDirectory = includerPath.parent_path();
|
||||
auto fullIncludePath = includerDirectory / headerName;
|
||||
|
||||
IncludeContext* context = new IncludeContext();
|
||||
FileReadAllBytes(fullIncludePath.string(), context->data);
|
||||
|
||||
IncludeResult* result = new IncludeResult(fullIncludePath.string(), context->data.data(), context->data.size(), context);
|
||||
_files.push(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
IncludeResult* includeSystem(const char* /*headerName*/, const char* /*includerName*/, size_t /*inclusionDepth*/) override {
|
||||
throw std::runtime_error("Not implemented");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void releaseInclude(IncludeResult* inc) override {
|
||||
auto* context = reinterpret_cast<IncludeContext*>(inc->userData);
|
||||
if (context != nullptr) {
|
||||
delete context;
|
||||
}
|
||||
|
||||
if (_files.top() == inc) {
|
||||
_files.pop();
|
||||
delete inc;
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Something went wrong");
|
||||
}
|
||||
}
|
||||
private:
|
||||
std::stack<IncludeResult*> _files;
|
||||
};
|
||||
@@ -0,0 +1,156 @@
|
||||
#pragma once
|
||||
|
||||
#include "Shader.h"
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include "ForwardDeclarations.h"
|
||||
|
||||
class ShaderBufferVariable {
|
||||
public:
|
||||
std::string name;
|
||||
uint32_t offset;
|
||||
uint32_t size;
|
||||
|
||||
ShaderBufferVariable() {
|
||||
|
||||
}
|
||||
|
||||
ShaderBufferVariable(const std::string& _name, uint32_t _offset, uint32_t _size)
|
||||
:name(_name), size(_size), offset(_offset){
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class ShaderResourceVariable {
|
||||
public:
|
||||
std::string name;
|
||||
uint32_t bindPoint;
|
||||
D3D_SHADER_INPUT_TYPE type;
|
||||
};
|
||||
|
||||
class ShaderBufferContext {
|
||||
public:
|
||||
//ID3D12ResourcePtr buffer;
|
||||
size_t size;
|
||||
std::vector<ShaderBufferVariable> variables;
|
||||
std::string name;
|
||||
uint32_t bindPoint;
|
||||
D3D_SHADER_INPUT_TYPE type;
|
||||
};
|
||||
|
||||
class ShaderParametersContext {
|
||||
public:
|
||||
void Clear() {
|
||||
buffers.clear();
|
||||
resources.clear();
|
||||
}
|
||||
std::vector<ShaderBufferContext> buffers;
|
||||
std::vector<ShaderResourceVariable> resources;
|
||||
};
|
||||
|
||||
class ShaderParameter {
|
||||
public:
|
||||
virtual ~ShaderParameter()
|
||||
{
|
||||
}
|
||||
|
||||
ShaderParameter(const std::string& _name) :name(_name) {
|
||||
|
||||
}
|
||||
virtual void* GetPointer() = 0;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<ShaderParameter> ShaderParameterPtr;
|
||||
|
||||
template<typename T>
|
||||
class ShaderValueParameter : public ShaderParameter {
|
||||
public:
|
||||
ShaderValueParameter(const std::string& _name) :ShaderParameter(_name)
|
||||
{
|
||||
|
||||
}
|
||||
void* GetPointer() override {
|
||||
return &value;
|
||||
}
|
||||
T value;
|
||||
};
|
||||
|
||||
class ShaderResourceParameter : public ShaderParameter {
|
||||
public:
|
||||
ShaderResourceParameter(const std::string& _name) :ShaderParameter(_name) {
|
||||
|
||||
}
|
||||
// ShaderResourceParameter(const std::string& _name, ID3D11ShaderResourceViewPtr view) : value(view), ShaderParameter(_name) {
|
||||
// name = _name;
|
||||
// }
|
||||
//ID3D11ShaderResourceViewPtr value;
|
||||
void* GetPointer() override {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class ShaderTextureParameter : public ShaderParameter {
|
||||
public:
|
||||
ShaderTextureParameter(const std::string& _name) :ShaderParameter(_name) {
|
||||
|
||||
}
|
||||
ShaderTextureParameter(const std::string& _name, TexturePtr view) : ShaderParameter(_name), value(view){
|
||||
name = _name;
|
||||
}
|
||||
TexturePtr value;
|
||||
void* GetPointer() override {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<ShaderResourceParameter> ShaderResourceParameterPtr;
|
||||
typedef std::shared_ptr<ShaderTextureParameter> ShaderTextureParameterPtr;
|
||||
|
||||
class ShaderParametersBlock {
|
||||
public:
|
||||
void SetTexture(const std::string& name, TexturePtr texture) {
|
||||
/*ID3D11ResourcePtr resourcePtr;
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
texture->GetDesc(&desc);
|
||||
texture.QueryInterface(&resourcePtr);
|
||||
SetShaderResource(name, resourcePtr);*/
|
||||
|
||||
ShaderTextureParameterPtr parameter(new ShaderTextureParameter(name, texture));
|
||||
for (auto it = parameters.begin(); it != parameters.end(); ++it) {
|
||||
if ((*it)->name == name) {
|
||||
*it = parameter;
|
||||
return;
|
||||
}
|
||||
}
|
||||
parameters.push_back(parameter);
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SetValue(const std::string& name, const T& value) {
|
||||
std::shared_ptr<ShaderValueParameter<T>> param(new ShaderValueParameter<T>(name));
|
||||
param->value = value;
|
||||
for (auto it = parameters.begin(); it != parameters.end(); ++it) {
|
||||
if ((*it)->name == name) {
|
||||
*it = param;
|
||||
return;
|
||||
}
|
||||
}
|
||||
parameters.push_back(param);
|
||||
}
|
||||
|
||||
ShaderParameterPtr GetParameterByName(const std::string& name) {
|
||||
for (auto p : parameters) {
|
||||
if (p->name == name) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
private:
|
||||
std::vector<ShaderParameterPtr> parameters;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "LEngine.h"
|
||||
#include <memory>
|
||||
|
||||
enum class MeshTopology {
|
||||
TriangleList,
|
||||
TriangleStrip,
|
||||
LineList,
|
||||
LineStrip
|
||||
};
|
||||
|
||||
class Submesh {
|
||||
public:
|
||||
typedef uint32_t index_count_t;
|
||||
typedef uint32_t index_t;
|
||||
typedef std::vector<index_t> index_array_t;
|
||||
|
||||
Submesh()
|
||||
:_indexCount(0)
|
||||
{
|
||||
|
||||
}
|
||||
//ID3D12ResourcePtr GetIndexBuffer() const{
|
||||
// return _indexBuffer;
|
||||
//}
|
||||
|
||||
MeshTopology GetTopology() const{
|
||||
return _topology;
|
||||
}
|
||||
|
||||
D3D12_INDEX_BUFFER_VIEW GetIndexBufferView()
|
||||
{
|
||||
return _indexBufferView;
|
||||
}
|
||||
|
||||
void Set(index_array_t indices, MeshTopology topology) {
|
||||
// _indexCount = indices.size();
|
||||
// _topology = topology;
|
||||
//_indexBuffer = nullptr;
|
||||
|
||||
// if (_indexCount == 0) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// D3D11_BUFFER_DESC desc = { 0 };
|
||||
// D3D11_SUBRESOURCE_DATA data = { 0 };
|
||||
|
||||
//index buffer
|
||||
// desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
// desc.ByteWidth = sizeof(indices[0]) * indices.size();
|
||||
// desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
// desc.CPUAccessFlags = 0;
|
||||
// desc.MiscFlags = 0;
|
||||
|
||||
// data.pSysMem = &indices[0];
|
||||
// data.SysMemPitch = 0;
|
||||
// data.SysMemSlicePitch = 0;
|
||||
|
||||
// auto renderer = LEngine::Instance()->GetRenderer();
|
||||
// auto device = renderer->GetDevice();
|
||||
// auto cmdList = renderer->BeginCommandList();
|
||||
|
||||
//create temporal upload resource
|
||||
// ComPtr<ID3D12Resource> uploadBuffer;
|
||||
// device->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
|
||||
// D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES,
|
||||
// &CD3DX12_RESOURCE_DESC::Buffer(desc.ByteWidth),
|
||||
// D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&uploadBuffer));
|
||||
|
||||
|
||||
//upload data to temporal resource
|
||||
// void* p;
|
||||
// uploadBuffer->Map(0, nullptr, &p);
|
||||
// memcpy(p, &indices[0], desc.ByteWidth);
|
||||
// uploadBuffer->Unmap(0, nullptr);
|
||||
|
||||
// device->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
|
||||
// D3D12_HEAP_FLAG_NONE,
|
||||
// &CD3DX12_RESOURCE_DESC::Buffer(desc.ByteWidth),
|
||||
// D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
// nullptr,
|
||||
// IID_PPV_ARGS(&_indexBuffer));
|
||||
|
||||
|
||||
// _indexBufferView.BufferLocation = _indexBuffer->GetGPUVirtualAddress();
|
||||
// _indexBufferView.SizeInBytes = desc.ByteWidth;
|
||||
// _indexBufferView.Format = DXGI_FORMAT_R32_UINT;
|
||||
|
||||
|
||||
// cmdList->CopyBufferRegion(_indexBuffer.Get(), 0, uploadBuffer.Get(), 0, desc.ByteWidth);
|
||||
|
||||
// CD3DX12_RESOURCE_BARRIER barriers[1] = {
|
||||
// CD3DX12_RESOURCE_BARRIER::Transition(_indexBuffer.Get(),
|
||||
// D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_INDEX_BUFFER)
|
||||
// };
|
||||
|
||||
|
||||
// cmdList->ResourceBarrier(1, barriers);
|
||||
// renderer->EndCommandList();
|
||||
// renderer->WaitCommandsQueue();
|
||||
}
|
||||
index_count_t GetIndicesCount() const {
|
||||
return _indexCount;
|
||||
}
|
||||
private:
|
||||
index_count_t _indexCount;
|
||||
MeshTopology _topology;
|
||||
//ID3D12ResourcePtr _indexBuffer;
|
||||
D3D12_INDEX_BUFFER_VIEW _indexBufferView;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Submesh> SubmeshPtr;
|
||||
@@ -0,0 +1,122 @@
|
||||
#pragma once
|
||||
|
||||
#include "RenderOutput.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
|
||||
class SwapChainOutput : public RenderOutput {
|
||||
public:
|
||||
SwapChainOutput(RendererPtr renderer, HWND window, uint32_t width, uint32_t height, bool stereo) : _activeBuffer(0){
|
||||
/*_buffersCount = 2;
|
||||
_swapChain = renderer->CreateSwapChain(window, true, width, height, _buffersCount, stereo);
|
||||
auto device = renderer->GetDevice();
|
||||
|
||||
//create RTV descriptors heap
|
||||
D3D12_DESCRIPTOR_HEAP_DESC heap_desc = {};
|
||||
heap_desc.NumDescriptors = _buffersCount;
|
||||
heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
|
||||
heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
|
||||
|
||||
HR_ASSERT_MSG(device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&rtvDescriptorHeap)), L"Failed to allocate RTV descriptors heap");
|
||||
rtvDescriptorHeap->SetName(L"RTV Heap");
|
||||
|
||||
rtvDescSize = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(rtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart());
|
||||
|
||||
|
||||
//create DSV descriptors heap
|
||||
heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
|
||||
HR_ASSERT_MSG(device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&dsvDescriptorHeap)), L"Failed to allocate DSV descriptors heap");
|
||||
dsvDescriptorHeap->SetName(L"DSV Heap");
|
||||
|
||||
dsvDescSize = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
|
||||
CD3DX12_CPU_DESCRIPTOR_HANDLE dsvHandle(dsvDescriptorHeap->GetCPUDescriptorHandleForHeapStart());
|
||||
|
||||
for(uint32_t i = 0; i < _buffersCount; ++i){
|
||||
//get back buffer
|
||||
ID3D12ResourcePtr _backBuffer;
|
||||
if (FAILED(_swapChain->GetBuffer(i, IID_PPV_ARGS(&_backBuffer)))){
|
||||
FatalError(TEXT("Failed to get swap chain's bffer"));
|
||||
}
|
||||
device->CreateRenderTargetView(_backBuffer.Get(), nullptr, rtvHandle);
|
||||
|
||||
|
||||
|
||||
//create depth buffer
|
||||
D3D12_CLEAR_VALUE depthOptimizedClearValue = {};
|
||||
depthOptimizedClearValue.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
depthOptimizedClearValue.DepthStencil.Depth = 1.0f;
|
||||
depthOptimizedClearValue.DepthStencil.Stencil = 0;
|
||||
|
||||
ComPtr<ID3D12Resource> depthStencilBuffer;
|
||||
device->CreateCommittedResource(
|
||||
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_D24_UNORM_S8_UINT, width, height, 1, 0, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL),
|
||||
D3D12_RESOURCE_STATE_DEPTH_WRITE,
|
||||
&depthOptimizedClearValue,
|
||||
IID_PPV_ARGS(&depthStencilBuffer)
|
||||
);
|
||||
|
||||
device->CreateDepthStencilView(depthStencilBuffer.Get(), nullptr, dsvHandle);
|
||||
|
||||
rtvHandle.Offset(1, rtvDescSize);
|
||||
dsvHandle.Offset(1, dsvDescSize);
|
||||
_buffers.push_back({ _backBuffer, depthStencilBuffer });
|
||||
} */
|
||||
}
|
||||
virtual uint32_t GetWidth() override{
|
||||
return GetDesc().Width;
|
||||
}
|
||||
|
||||
virtual uint32_t GetHeight() override
|
||||
{
|
||||
return GetDesc().Height;
|
||||
}
|
||||
|
||||
// CD3DX12_CPU_DESCRIPTOR_HANDLE GetRenderTargetDescriptor(uint32_t id) override {
|
||||
// return CD3DX12_CPU_DESCRIPTOR_HANDLE(rtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), id, rtvDescSize);
|
||||
// }
|
||||
// CD3DX12_CPU_DESCRIPTOR_HANDLE GetDepthStencilDescriptor(uint32_t id) override {
|
||||
// return CD3DX12_CPU_DESCRIPTOR_HANDLE(dsvDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), id, dsvDescSize);
|
||||
// }
|
||||
|
||||
// ID3D12ResourcePtr GetRenderTarget(uint32_t id) override{
|
||||
// return _buffers[id].first;
|
||||
// }
|
||||
|
||||
// ID3D12ResourcePtr GetDepthBuffer(uint32_t id) override {
|
||||
// return _buffers[id].second;
|
||||
// }
|
||||
|
||||
virtual void Present() override{
|
||||
//_swapChain->Present(0, 0);
|
||||
_activeBuffer = (_activeBuffer + 1) % _buffersCount;
|
||||
}
|
||||
|
||||
virtual void OnPreRender(RendererPtr renderer) override{
|
||||
|
||||
}
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC1 GetDesc() {
|
||||
DXGI_SWAP_CHAIN_DESC1 desc;
|
||||
//_swapChain->GetDesc1(&desc);
|
||||
return desc;
|
||||
}
|
||||
uint32_t GetCurrentBufferIndex() override{
|
||||
return _activeBuffer;
|
||||
}
|
||||
uint32_t GetBuffersCount() override{
|
||||
return _buffersCount;
|
||||
}
|
||||
private:
|
||||
// std::vector<std::pair<ID3D12ResourcePtr, ID3D12ResourcePtr>> _buffers;
|
||||
uint32_t _activeBuffer;
|
||||
uint32_t _buffersCount;
|
||||
UINT rtvDescSize;
|
||||
UINT dsvDescSize;
|
||||
// ComPtr<ID3D12DescriptorHeap> rtvDescriptorHeap;
|
||||
// ComPtr<ID3D12DescriptorHeap> dsvDescriptorHeap;
|
||||
// IDXGISwapChain1Ptr _swapChain;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
class Texture
|
||||
{
|
||||
public:
|
||||
Texture(/*ID3D12ResourcePtr _resource, D3D12_CPU_DESCRIPTOR_HANDLE _srvDescriptor*/)
|
||||
/*:resource(_resource), srvDescriptor(_srvDescriptor)*/
|
||||
{
|
||||
|
||||
}
|
||||
//ID3D12ResourcePtr resource;
|
||||
//D3D12_CPU_DESCRIPTOR_HANDLE srvDescriptor;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef TextureImporter_h__
|
||||
#define TextureImporter_h__
|
||||
|
||||
#include "AssetImporter.h"
|
||||
#include <filesystem>
|
||||
|
||||
/*
|
||||
class TextureImporter : public AssetImporter {
|
||||
public:
|
||||
virtual bool can_import(const std::wstring& path) const override {
|
||||
std::tr2::sys::path file_path(path);
|
||||
if (!file_path.has_extension()) {
|
||||
return false;
|
||||
} else {
|
||||
return file_path.extension() == ".bmp";
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool load_parameters(const std::wstring& params) override {
|
||||
throw std::logic_error("The method or operation is not implemented.");
|
||||
}
|
||||
|
||||
virtual std::wstring save_parameters() override {
|
||||
throw std::logic_error("The method or operation is not implemented.");
|
||||
}
|
||||
|
||||
virtual std::wstring name() override {
|
||||
return L"TextureImporter";
|
||||
}
|
||||
|
||||
};*/
|
||||
|
||||
#endif // TextureImporter_h__
|
||||
@@ -0,0 +1,94 @@
|
||||
#ifndef Transform_h__
|
||||
#define Transform_h__
|
||||
|
||||
#include <lmath/lmath.h>
|
||||
#include "Mathf.h"
|
||||
#include "ObjectsFactory.h"
|
||||
#include "Component.h"
|
||||
#include "Archive.h"
|
||||
|
||||
using namespace lm;
|
||||
|
||||
LOBJECT(Transform, Component)
|
||||
public:
|
||||
std::shared_ptr<Transform> parent;
|
||||
Quaternion_f _rotation;
|
||||
float3 _position;
|
||||
float3 _scale;
|
||||
|
||||
Transform()
|
||||
:_scale(1.0f,1.0f,1.0f), _position(0.0f,0.0f,0.0f), _rotation(0.0f,0.0f,0.0f,1.0f){
|
||||
}
|
||||
|
||||
void serialize(Archive& archive) override{
|
||||
Component::serialize(archive);
|
||||
archive << parent;
|
||||
archive << _rotation << _position << _scale;
|
||||
}
|
||||
|
||||
std::wstring class_name() const {
|
||||
return L"Transform";
|
||||
}
|
||||
|
||||
void SetLocalPosition(const float3& position) {
|
||||
_position = position;
|
||||
}
|
||||
float3 GetLocalPosition() {
|
||||
return _position;
|
||||
}
|
||||
|
||||
float3 forward() const{
|
||||
return GetGlobalTransform().z().xyz();
|
||||
}
|
||||
|
||||
float3 right() const {
|
||||
return GetGlobalTransform().x().xyz();
|
||||
}
|
||||
|
||||
float3 up() const {
|
||||
return GetGlobalTransform().y().xyz();
|
||||
}
|
||||
|
||||
void SetLocalRotation(const Quaternion_f& rotation) {
|
||||
_rotation = rotation;
|
||||
}
|
||||
|
||||
Quaternion_f GetLocalRotation() {
|
||||
return _rotation;
|
||||
}
|
||||
|
||||
void SetLocalScale(const float3& scale) {
|
||||
_scale = scale;
|
||||
}
|
||||
|
||||
float3 GetLocalScale() {
|
||||
return _scale;
|
||||
}
|
||||
|
||||
float4x4 GetLocalTransform() const{
|
||||
auto scaleMatrix = matrix4x4Scale(_scale);
|
||||
auto rotationMatrix = matrix4x4RotationQuaternion(_rotation);
|
||||
auto positionMatrix = matrix4x4Translation(_position);
|
||||
return lm::mul(lm::mul(scaleMatrix, rotationMatrix), positionMatrix);
|
||||
}
|
||||
|
||||
float4x4 GetGlobalTransform() const{
|
||||
if(parent == nullptr) {
|
||||
return GetLocalTransform();
|
||||
}
|
||||
return lm::mul(GetLocalTransform(), parent->GetGlobalTransform());
|
||||
}
|
||||
|
||||
float3 GetGlobalPosition() {
|
||||
auto tf = GetGlobalTransform();
|
||||
return float3(tf[0][3], tf[1][3], tf[2][3]);
|
||||
}
|
||||
|
||||
void RotateLocal(const Quaternion_f& rotation) {
|
||||
_rotation = lm::mul(_rotation, rotation);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // Transform_h__
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef Vertex_h__
|
||||
#define Vertex_h__
|
||||
|
||||
#include <lmath/lmath.h>
|
||||
|
||||
using namespace lm;
|
||||
struct Vertex {
|
||||
float4 position;
|
||||
float3 normal;
|
||||
float2 uv0;
|
||||
float2 uv1;
|
||||
|
||||
Vertex() {
|
||||
|
||||
}
|
||||
|
||||
Vertex(float4 _pos, float3 _norm) {
|
||||
position = _pos;
|
||||
normal = _norm;
|
||||
}
|
||||
Vertex(float4 _pos, float3 _norm, float2 _uv0) {
|
||||
position = _pos;
|
||||
normal = _norm;
|
||||
uv0 = _uv0;
|
||||
}
|
||||
};
|
||||
#endif // Vertex_h__
|
||||
@@ -0,0 +1,775 @@
|
||||
#include "Application.h"
|
||||
|
||||
|
||||
#include "VertexShader_unknown.h"
|
||||
#include "FragmentShader_unknown.h"
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include "VulkanDeviceFunctions.h"
|
||||
|
||||
Application::Application() {
|
||||
vulkan = std::make_shared<VulkanDynamicLibrary>();
|
||||
auto extensions = vulkan->getSupportedExtensions();
|
||||
auto layers = vulkan->getSupportedLayers();
|
||||
|
||||
if(std::find_if(layers.begin(), layers.end(), [](VkLayerProperties& layer){ return std::string(layer.layerName) == "VK_LAYER_KHRONOS_validation"; } ) == layers.end()){
|
||||
throw std::runtime_error("Validation layer not found");
|
||||
}
|
||||
|
||||
VulkanApplicationInfo appInfo("Test project", 1, "Test");
|
||||
|
||||
std::vector<std::string> instanceLayers;
|
||||
instanceLayers.push_back("VK_LAYER_KHRONOS_validation");
|
||||
|
||||
auto instance = vulkan->createInstance(appInfo, 0, instanceLayers, RenderWindow::getRequiredExtensionNames());
|
||||
|
||||
auto physicalDevices = instance->enumeratePhysicalDevices();
|
||||
device = physicalDevices[0];
|
||||
|
||||
|
||||
auto properties = device->getProperties();
|
||||
auto features = device->getFeatures();
|
||||
auto families = device->getQueueFamilyProperties();
|
||||
|
||||
window = new RenderWindow(instance, "VulkanWrapperSandbox");
|
||||
|
||||
std::cout << "Device queue families count: " << device->getQueueFamiliesCount() << std::endl;
|
||||
|
||||
//Find queues
|
||||
|
||||
for (uint32_t i = 0; i < device->getQueueFamiliesCount(); ++i) {
|
||||
if (presentQueueFamilyIndex == -1 && families[i].queueCount > 0 && window->canPresent(device, i)) {
|
||||
presentQueueFamilyIndex = i;
|
||||
std::cout << "Found present queue: " << i << std::endl;
|
||||
}
|
||||
|
||||
if (renderQueueFamilyIndex == -1 && families[i].isGraphics() && families[i].queueCount > 0) {
|
||||
std::cout << "Found render queue: " << i << std::endl;
|
||||
renderQueueFamilyIndex = i;
|
||||
}
|
||||
|
||||
if (renderQueueFamilyIndex != -1 && presentQueueFamilyIndex != -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<VulkanQueueCreateInfo> queueDescriptions;
|
||||
queueDescriptions.push_back(VulkanQueueCreateInfo(presentQueueFamilyIndex, { 1.0f }));
|
||||
if (presentQueueFamilyIndex != renderQueueFamilyIndex) {
|
||||
queueDescriptions.push_back(VulkanQueueCreateInfo(renderQueueFamilyIndex, { 1.0f }));
|
||||
}
|
||||
|
||||
auto deviceExtensions = device->getExtensions();
|
||||
|
||||
std::vector<const char*> requiredDeviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
|
||||
|
||||
auto swapChainExt = std::find_if(deviceExtensions.begin(), deviceExtensions.end(), [&requiredDeviceExtensions](VkExtensionProperties ext) { return std::string(requiredDeviceExtensions[0]) == ext.extensionName; });
|
||||
if (swapChainExt == deviceExtensions.end()) {
|
||||
throw std::runtime_error("Failed to find device with swap chain extension");
|
||||
}
|
||||
|
||||
logicalDevice = IntrusivePtr<VulkanLogicalDevice>(new VulkanLogicalDevice(device, requiredDeviceExtensions, {}, queueDescriptions));
|
||||
|
||||
|
||||
VkCommandPoolCreateInfo poolCreateInfo = {};
|
||||
poolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||
poolCreateInfo.queueFamilyIndex = presentQueueFamilyIndex;
|
||||
poolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
||||
|
||||
if (logicalDevice->functions().vkCreateCommandPool(&poolCreateInfo, nullptr, &presentCommandPool) != VK_SUCCESS) {
|
||||
std::cerr << "failed to create command queue for presentation queue family" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
std::cout << "created command pool for presentation queue family" << std::endl;
|
||||
}
|
||||
|
||||
if (renderQueueFamilyIndex == presentQueueFamilyIndex) {
|
||||
renderCommandPool = presentCommandPool;
|
||||
}
|
||||
else {
|
||||
poolCreateInfo.queueFamilyIndex = renderQueueFamilyIndex;
|
||||
if (logicalDevice->functions().vkCreateCommandPool(&poolCreateInfo, nullptr, &renderCommandPool) != VK_SUCCESS) {
|
||||
std::cerr << "failed to create command queue for render queue family" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
std::cout << "created command pool for render queue family" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
queues = logicalDevice->queues();
|
||||
|
||||
std::vector<Vertex> vertexData =
|
||||
{
|
||||
{ { 1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f } },
|
||||
{ { -1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f } },
|
||||
{ { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }
|
||||
};
|
||||
_vertexBuffer = createBuffer(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, vertexData.data(), sizeof(vertexData[0]) * vertexData.size(), logicalDevice, device, queues[0], renderCommandPool);
|
||||
|
||||
std::vector<uint32_t> indexData = { 0, 1, 2 };
|
||||
_indexBuffer = createBuffer(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, indexData.data(), sizeof(indexData[0]) * indexData.size(), logicalDevice, device, queues[0], renderCommandPool);
|
||||
|
||||
createSwapChain();
|
||||
|
||||
//for(std::size_t i = 0; i < swapChain->images)
|
||||
//_frameBuffers
|
||||
|
||||
//logicalDevice->functions().vkGetDeviceQueue()
|
||||
|
||||
for (auto image : swapChain->images()) {
|
||||
_imageViews.push_back(IntrusivePtr<VulkanImageView>(new VulkanImageView(logicalDevice, VulkanImageViewCreateInfo::image2D(image, swapChain->format()))));
|
||||
}
|
||||
|
||||
presentCommandBuffers.resize(swapChain->images().size());
|
||||
VkCommandBufferAllocateInfo allocInfo = {};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
allocInfo.commandPool = presentCommandPool;
|
||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
allocInfo.commandBufferCount = static_cast<uint32_t>(swapChain->images().size());
|
||||
if (logicalDevice->functions().vkAllocateCommandBuffers(&allocInfo, presentCommandBuffers.data()) != VK_SUCCESS) {
|
||||
std::cerr << "failed to allocate presentation command buffers" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
VkFenceCreateInfo fenceInfo{};
|
||||
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
|
||||
_cmdBufferFences.resize(swapChain->images().size());
|
||||
for(std::size_t i = 0; i < swapChain->images().size(); ++i){
|
||||
if(logicalDevice->functions().vkCreateFence(&fenceInfo, nullptr, &_cmdBufferFences[i]) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create synchronization objects for a frame!");
|
||||
}
|
||||
|
||||
_uniformBuffers.push_back(IntrusivePtr<UniformBuffer>(new UniformBuffer(logicalDevice, sizeof(UboPerObjectData))));
|
||||
}
|
||||
//
|
||||
|
||||
|
||||
|
||||
compileShaders();
|
||||
|
||||
|
||||
|
||||
VkAttachmentDescription colorAttachment = {};
|
||||
colorAttachment.format = swapChain->format();
|
||||
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
|
||||
VkAttachmentReference colorAttachmentRef = {};
|
||||
colorAttachmentRef.attachment = 0;
|
||||
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
|
||||
VkSubpassDescription subpass = {};
|
||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass.colorAttachmentCount = 1;
|
||||
subpass.pColorAttachments = &colorAttachmentRef;
|
||||
|
||||
VkRenderPassCreateInfo renderPassInfo = {};
|
||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||
renderPassInfo.attachmentCount = 1;
|
||||
renderPassInfo.pAttachments = &colorAttachment;
|
||||
renderPassInfo.subpassCount = 1;
|
||||
renderPassInfo.pSubpasses = &subpass;
|
||||
|
||||
|
||||
//Create render pass
|
||||
if (logicalDevice->functions().vkCreateRenderPass(&renderPassInfo, nullptr, &_renderPass) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create render pass!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (auto& imageView : _imageViews) {
|
||||
VkImageView attachments[] = {
|
||||
imageView->native()
|
||||
};
|
||||
|
||||
VkFramebufferCreateInfo framebufferInfo{};
|
||||
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||
framebufferInfo.renderPass = _renderPass;
|
||||
framebufferInfo.attachmentCount = 1;
|
||||
framebufferInfo.pAttachments = attachments;
|
||||
framebufferInfo.width = swapChain->extent().width;
|
||||
framebufferInfo.height = swapChain->extent().height;
|
||||
framebufferInfo.layers = 1;
|
||||
|
||||
//
|
||||
_frameBuffers.push_back(IntrusivePtr<VulkanFrameBuffer>(new VulkanFrameBuffer(logicalDevice, framebufferInfo)));
|
||||
}
|
||||
|
||||
|
||||
//Descriptor set layout for UBO
|
||||
VkDescriptorSetLayoutBinding uboLayoutBinding{};
|
||||
uboLayoutBinding.binding = 0;
|
||||
uboLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
uboLayoutBinding.descriptorCount = 1;
|
||||
uboLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
uboLayoutBinding.pImmutableSamplers = nullptr; // Optional
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo layoutInfo{};
|
||||
layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||
layoutInfo.bindingCount = 1;
|
||||
layoutInfo.pBindings = &uboLayoutBinding;
|
||||
|
||||
_uboDescriptorSetLayout = IntrusivePtr<VulkanDescriptorSetLayout>(new VulkanDescriptorSetLayout(logicalDevice, layoutInfo));
|
||||
|
||||
//Create pipeline
|
||||
createPipeline();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Application::createPipeline(){
|
||||
VkPipelineShaderStageCreateInfo vertShaderStageInfo{};
|
||||
vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
vertShaderStageInfo.module = vs->native();
|
||||
vertShaderStageInfo.pName = "main";
|
||||
vertShaderStageInfo.pSpecializationInfo = nullptr;
|
||||
|
||||
VkPipelineShaderStageCreateInfo fragShaderStageInfo{};
|
||||
fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
fragShaderStageInfo.module = ps->native();
|
||||
fragShaderStageInfo.pName = "main";
|
||||
|
||||
VkPipelineShaderStageCreateInfo shaderStages[] = {vertShaderStageInfo, fragShaderStageInfo};
|
||||
|
||||
|
||||
//Bind vertex data
|
||||
VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
|
||||
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||
|
||||
auto bindingDescription = Vertex::getBindingDescription();
|
||||
vertexInputInfo.vertexBindingDescriptionCount = 1;
|
||||
vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; // Optional
|
||||
|
||||
auto attributeDescriptions = Vertex::getAttributeDescriptions();
|
||||
vertexInputInfo.vertexAttributeDescriptionCount = attributeDescriptions.size();
|
||||
vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data(); // Optional
|
||||
|
||||
//Input assembly
|
||||
VkPipelineInputAssemblyStateCreateInfo inputAssembly{};
|
||||
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
||||
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
inputAssembly.primitiveRestartEnable = VK_FALSE;
|
||||
|
||||
//Viewport
|
||||
VkViewport viewport = {};
|
||||
viewport.x = 0.0f;
|
||||
viewport.y = 0.0f;
|
||||
viewport.width = (float)swapChain->extent().width;
|
||||
viewport.height = (float)swapChain->extent().height;
|
||||
viewport.minDepth = 0.0f;
|
||||
viewport.maxDepth = 1.0f;
|
||||
|
||||
//Scissor
|
||||
VkRect2D scissor = {};
|
||||
scissor.offset = { 0, 0 };
|
||||
scissor.extent = swapChain->extent();
|
||||
|
||||
//Pipeline Viewport State
|
||||
VkPipelineViewportStateCreateInfo viewportState = {};
|
||||
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
||||
viewportState.viewportCount = 1;
|
||||
viewportState.pViewports = &viewport;
|
||||
viewportState.scissorCount = 1;
|
||||
viewportState.pScissors = &scissor;
|
||||
|
||||
//Rasterizer
|
||||
VkPipelineRasterizationStateCreateInfo rasterizer = {};
|
||||
rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
|
||||
rasterizer.depthClampEnable = VK_FALSE;
|
||||
rasterizer.rasterizerDiscardEnable = VK_FALSE;
|
||||
rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
|
||||
rasterizer.lineWidth = 1.0f;
|
||||
rasterizer.cullMode = VK_CULL_MODE_NONE; //VK_CULL_MODE_BACK_BIT;
|
||||
rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE;
|
||||
rasterizer.depthBiasEnable = VK_FALSE;
|
||||
rasterizer.depthBiasConstantFactor = 0.0f; // Optional
|
||||
rasterizer.depthBiasClamp = 0.0f; // Optional
|
||||
rasterizer.depthBiasSlopeFactor = 0.0f; // Optional
|
||||
|
||||
//Multisample
|
||||
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
||||
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
||||
multisampling.sampleShadingEnable = VK_FALSE;
|
||||
multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
multisampling.minSampleShading = 1.0f; // Optional
|
||||
multisampling.pSampleMask = nullptr; // Optional
|
||||
multisampling.alphaToCoverageEnable = VK_FALSE; // Optional
|
||||
multisampling.alphaToOneEnable = VK_FALSE; // Optional
|
||||
|
||||
//Pipeline layout
|
||||
VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
|
||||
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||
pipelineLayoutInfo.setLayoutCount = 1;
|
||||
VkDescriptorSetLayout layout = _uboDescriptorSetLayout->native();
|
||||
pipelineLayoutInfo.pSetLayouts = &layout;
|
||||
pipelineLayoutInfo.pushConstantRangeCount = 0;
|
||||
|
||||
auto pipelineLayout = IntrusivePtr<VulkanPipelineLayout>(new VulkanPipelineLayout(logicalDevice, pipelineLayoutInfo));
|
||||
|
||||
//Blend state attachment
|
||||
VkPipelineColorBlendAttachmentState colorBlendAttachment = {};
|
||||
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
||||
colorBlendAttachment.blendEnable = VK_FALSE;
|
||||
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE; // Optional
|
||||
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO; // Optional
|
||||
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; // Optional
|
||||
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; // Optional
|
||||
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; // Optional
|
||||
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; // Optional
|
||||
|
||||
//Blend state
|
||||
VkPipelineColorBlendStateCreateInfo colorBlending{};
|
||||
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
||||
colorBlending.logicOpEnable = VK_FALSE;
|
||||
colorBlending.logicOp = VK_LOGIC_OP_COPY;
|
||||
colorBlending.attachmentCount = 1;
|
||||
colorBlending.pAttachments = &colorBlendAttachment;
|
||||
colorBlending.blendConstants[0] = 0.0f;
|
||||
colorBlending.blendConstants[1] = 0.0f;
|
||||
colorBlending.blendConstants[2] = 0.0f;
|
||||
colorBlending.blendConstants[3] = 0.0f;
|
||||
|
||||
|
||||
//Pipeline
|
||||
VkGraphicsPipelineCreateInfo pipelineInfo{};
|
||||
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||
pipelineInfo.stageCount = 2;
|
||||
pipelineInfo.pStages = shaderStages;
|
||||
pipelineInfo.pVertexInputState = &vertexInputInfo;
|
||||
pipelineInfo.pInputAssemblyState = &inputAssembly;
|
||||
pipelineInfo.pViewportState = &viewportState;
|
||||
pipelineInfo.pRasterizationState = &rasterizer;
|
||||
pipelineInfo.pMultisampleState = &multisampling;
|
||||
pipelineInfo.pColorBlendState = &colorBlending;
|
||||
pipelineInfo.pDynamicState = nullptr;
|
||||
pipelineInfo.layout = pipelineLayout->native();
|
||||
pipelineInfo.renderPass = _renderPass;
|
||||
pipelineInfo.subpass = 0;
|
||||
pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
|
||||
|
||||
_pipeline = IntrusivePtr<VulkanPipeline>(new VulkanPipeline(logicalDevice, pipelineLayout, pipelineInfo));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Application::compileShaders() {
|
||||
auto vertexBinary = ShaderCompiler::compile(vert, ShaderCompilerStage::vert);
|
||||
|
||||
|
||||
spv_reflect::ShaderModule sm(vertexBinary.binary.size(), vertexBinary.binary.data());
|
||||
auto name = sm.GetEntryPointName();
|
||||
|
||||
|
||||
|
||||
uint32_t count = 0;
|
||||
auto res = sm.EnumerateDescriptorSets(&count, nullptr);
|
||||
std::vector<SpvReflectDescriptorSet*> descriptorSets(count);
|
||||
res = sm.EnumerateDescriptorSets(&count, descriptorSets.data());
|
||||
|
||||
for(uint32_t i = 0; i < count; ++i){
|
||||
SpvReflectDescriptorSet* v = descriptorSets[i];
|
||||
std::cout << "V" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
auto fragmentBinary = ShaderCompiler::compile(frag, ShaderCompilerStage::frag);
|
||||
|
||||
|
||||
|
||||
vs = IntrusivePtr<VulkanShaderModule>(new VulkanShaderModule(logicalDevice, vertexBinary.binary.data(), vertexBinary.binary.size()));
|
||||
ps = IntrusivePtr<VulkanShaderModule>(new VulkanShaderModule(logicalDevice, fragmentBinary.binary.data(), fragmentBinary.binary.size()));
|
||||
}
|
||||
|
||||
void Application::createSwapChain() {
|
||||
auto formats = VulkanSwapChain::getSurfaceFormats(device, window->getSurface());
|
||||
auto caps = VulkanSwapChain::getSurfaceCapabilities(device, window->getSurface());
|
||||
auto presentModes = VulkanSwapChain::getPresentModes(device, window->getSurface());
|
||||
|
||||
VkSwapchainCreateInfoKHR createInfo = {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
||||
createInfo.pNext = NULL;
|
||||
createInfo.surface = window->getSurface();
|
||||
createInfo.imageFormat = formats[0].format;
|
||||
createInfo.imageColorSpace = formats[0].colorSpace;
|
||||
createInfo.minImageCount = caps.minImageCount + 1;
|
||||
createInfo.imageExtent = caps.currentExtent;
|
||||
createInfo.preTransform = caps.currentTransform;
|
||||
createInfo.presentMode = VK_PRESENT_MODE_MAILBOX_KHR;
|
||||
createInfo.imageArrayLayers = 1;
|
||||
createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
|
||||
std::vector<uint32_t> swapChainQueueFamilies;
|
||||
swapChainQueueFamilies.push_back(renderQueueFamilyIndex);
|
||||
swapChainQueueFamilies.push_back(presentQueueFamilyIndex);
|
||||
|
||||
if (presentQueueFamilyIndex == renderQueueFamilyIndex) {
|
||||
createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
createInfo.queueFamilyIndexCount = 0; // Optional
|
||||
createInfo.pQueueFamilyIndices = nullptr; // Optional
|
||||
}
|
||||
else {
|
||||
createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
|
||||
createInfo.queueFamilyIndexCount = 2;
|
||||
createInfo.pQueueFamilyIndices = &swapChainQueueFamilies[0];
|
||||
}
|
||||
createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
createInfo.clipped = VK_TRUE;
|
||||
createInfo.oldSwapchain = VK_NULL_HANDLE;
|
||||
|
||||
|
||||
swapChain = new VulkanSwapChain(logicalDevice, createInfo);
|
||||
}
|
||||
|
||||
void Application::recordCommandBuffer(VkCommandBuffer cmdBuffer, uint32_t cmdBufferIndex, uint32_t imageIndex){
|
||||
VkCommandBufferBeginInfo beginInfo = {};
|
||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
|
||||
|
||||
VkImageSubresourceRange subResourceRange = {};
|
||||
subResourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
subResourceRange.baseMipLevel = 0;
|
||||
subResourceRange.levelCount = 1;
|
||||
subResourceRange.baseArrayLayer = 0;
|
||||
subResourceRange.layerCount = 1;
|
||||
|
||||
|
||||
VkImageMemoryBarrier presentToClearBarrier = {};
|
||||
presentToClearBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
presentToClearBarrier.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
||||
presentToClearBarrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
presentToClearBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
presentToClearBarrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
presentToClearBarrier.srcQueueFamilyIndex = presentQueueFamilyIndex;
|
||||
presentToClearBarrier.dstQueueFamilyIndex = presentQueueFamilyIndex;
|
||||
presentToClearBarrier.image = swapChain->images()[imageIndex];
|
||||
presentToClearBarrier.subresourceRange = subResourceRange;
|
||||
|
||||
// Change layout of image to be optimal for presenting
|
||||
VkImageMemoryBarrier clearToPresentBarrier = {};
|
||||
clearToPresentBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
clearToPresentBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
clearToPresentBarrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
||||
clearToPresentBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; // VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
clearToPresentBarrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
clearToPresentBarrier.srcQueueFamilyIndex = presentQueueFamilyIndex;
|
||||
clearToPresentBarrier.dstQueueFamilyIndex = presentQueueFamilyIndex;
|
||||
clearToPresentBarrier.image = swapChain->images()[imageIndex];
|
||||
clearToPresentBarrier.subresourceRange = subResourceRange;
|
||||
|
||||
// Record command buffer
|
||||
logicalDevice->functions().vkBeginCommandBuffer(presentCommandBuffers[imageIndex], &beginInfo);
|
||||
|
||||
logicalDevice->functions().vkCmdPipelineBarrier(presentCommandBuffers[imageIndex], VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &presentToClearBarrier);
|
||||
|
||||
//logicalDevice->functions().vkCmdClearColorImage(presentCommandBuffers[i], swapChain->images()[i], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearColors[i % 3], 1, &subResourceRange);
|
||||
|
||||
VkClearColorValue clearColors[3] = {
|
||||
{{ 1.0f, 0, 0, 1.0f }},
|
||||
{{ 0, 1, 0, 1.0f }},
|
||||
{{ 0, 0, 1, 1.0f }}
|
||||
};
|
||||
|
||||
VkRenderPassBeginInfo renderPassInfo{};
|
||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||
renderPassInfo.renderPass = _renderPass;
|
||||
renderPassInfo.framebuffer = _frameBuffers[imageIndex]->native();
|
||||
renderPassInfo.renderArea.offset = {0, 0};
|
||||
renderPassInfo.renderArea.extent = swapChain->extent();
|
||||
|
||||
VkClearValue clearColor = {{{0.0f, 0.0f, 1.0f, 1.0f}}};
|
||||
renderPassInfo.clearValueCount = 1;
|
||||
renderPassInfo.pClearValues = &clearColor;
|
||||
|
||||
logicalDevice->functions().vkCmdBeginRenderPass(cmdBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
logicalDevice->functions().vkCmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, _pipeline->native());
|
||||
|
||||
//VkViewport viewport{};
|
||||
//viewport.x = 0.0f;
|
||||
//viewport.y = 0.0f;
|
||||
//viewport.width = (float) swapChain->extent().width;
|
||||
//viewport.height = (float) swapChain->extent().height;
|
||||
//viewport.minDepth = 0.0f;
|
||||
//viewport.maxDepth = 1.0f;
|
||||
//logicalDevice->functions().vkCmdSetViewport(cmdBuffer, 0, 1, &viewport);
|
||||
//
|
||||
//VkRect2D scissor{};
|
||||
//scissor.offset = {0, 0};
|
||||
//scissor.extent = swapChain->extent();
|
||||
//logicalDevice->functions().vkCmdSetScissor(cmdBuffer, 0, 1, &scissor);
|
||||
|
||||
VkBuffer vertexBuffers[] = {_vertexBuffer->native()};
|
||||
VkDeviceSize offsets[] = {0};
|
||||
logicalDevice->functions().vkCmdBindVertexBuffers(cmdBuffer, 0, 1, vertexBuffers, offsets);
|
||||
|
||||
logicalDevice->functions().vkCmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, _pipeline->layout()->native(), 0, 1, &descriptorSets[cmdBufferIndex], 0, nullptr);
|
||||
|
||||
auto vertexCount = _vertexBuffer->size() / sizeof(Vertex);
|
||||
logicalDevice->functions().vkCmdDraw(cmdBuffer, static_cast<uint32_t>(vertexCount), 1, 0, 0);
|
||||
logicalDevice->functions().vkCmdEndRenderPass(cmdBuffer);
|
||||
|
||||
|
||||
|
||||
logicalDevice->functions().vkCmdPipelineBarrier(presentCommandBuffers[imageIndex], VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &clearToPresentBarrier);
|
||||
|
||||
if (logicalDevice->functions().vkEndCommandBuffer(presentCommandBuffers[imageIndex]) != VK_SUCCESS) {
|
||||
std::cerr << "failed to record command buffer" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
std::cout << "recorded command buffer for image " << imageIndex << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Application::updateUniformBuffer(uint32_t currentImage){
|
||||
static auto startTime = std::chrono::high_resolution_clock::now();
|
||||
auto currentTime = std::chrono::high_resolution_clock::now();
|
||||
float time = std::chrono::duration<float, std::chrono::seconds::period>(currentTime - startTime).count();
|
||||
|
||||
UboPerObjectData ubo{};
|
||||
ubo.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(90.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
ubo.view = glm::lookAtLH(glm::vec3(0.0f, 2.0f, -2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
ubo.proj = glm::perspectiveLH(glm::radians(90.0f), swapChain->extent().width / (float) swapChain->extent().height, 0.1f, 10.0f);
|
||||
ubo.proj[1][1] *= -1;
|
||||
|
||||
memcpy(_uniformBuffers[currentImage]->mappedMemory(), &ubo, sizeof(ubo));
|
||||
}
|
||||
|
||||
void Application::run() {
|
||||
auto swapChainImageCount = swapChain->images().size();
|
||||
|
||||
std::vector<IntrusivePtr<VulkanSemaphore>> imageAvailableSemaphores;
|
||||
std::vector<IntrusivePtr<VulkanSemaphore>> renderingFinishedSemaphores;
|
||||
|
||||
for(std::size_t i = 0; i < _cmdBufferFences.size(); ++i){
|
||||
imageAvailableSemaphores.push_back(IntrusivePtr<VulkanSemaphore>(new VulkanSemaphore(logicalDevice)));
|
||||
renderingFinishedSemaphores.push_back(IntrusivePtr<VulkanSemaphore>(new VulkanSemaphore(logicalDevice)));
|
||||
}
|
||||
|
||||
auto uboDescriptorPool = createDescriptorPool(_cmdBufferFences.size());
|
||||
std::vector<VkDescriptorSetLayout> layouts(_cmdBufferFences.size(), _uboDescriptorSetLayout->native());
|
||||
VkDescriptorSetAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||
allocInfo.descriptorPool = uboDescriptorPool;
|
||||
allocInfo.descriptorSetCount = static_cast<uint32_t>(_cmdBufferFences.size());
|
||||
allocInfo.pSetLayouts = layouts.data();
|
||||
|
||||
descriptorSets.resize(_cmdBufferFences.size());
|
||||
if (logicalDevice->functions().vkAllocateDescriptorSets(&allocInfo, descriptorSets.data()) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to allocate descriptor sets!");
|
||||
}
|
||||
for (size_t i = 0; i < _cmdBufferFences.size(); i++) {
|
||||
VkDescriptorBufferInfo bufferInfo{};
|
||||
bufferInfo.buffer = _uniformBuffers[i]->buffer()->native();
|
||||
bufferInfo.offset = 0;
|
||||
bufferInfo.range = sizeof(UboPerObjectData);
|
||||
|
||||
VkWriteDescriptorSet descriptorWrite{};
|
||||
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
descriptorWrite.dstSet = descriptorSets[i];
|
||||
descriptorWrite.dstBinding = 0;
|
||||
descriptorWrite.dstArrayElement = 0;
|
||||
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
descriptorWrite.descriptorCount = 1;
|
||||
descriptorWrite.pBufferInfo = &bufferInfo;
|
||||
descriptorWrite.pImageInfo = nullptr; // Optional
|
||||
descriptorWrite.pTexelBufferView = nullptr; // Optional
|
||||
logicalDevice->functions().vkUpdateDescriptorSets(1, &descriptorWrite, 0, nullptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::cout << "allocated presentation command buffers" << std::endl;
|
||||
|
||||
int cmdBufferIndex = 0;
|
||||
|
||||
while (window->update()) {
|
||||
//Wait cmd buffer to finish it's job to use it again
|
||||
logicalDevice->functions().vkWaitForFences(1, &_cmdBufferFences[cmdBufferIndex], VK_TRUE, UINT64_MAX);
|
||||
|
||||
|
||||
std::uint32_t imageIndex = 0;
|
||||
auto result = logicalDevice->functions().vkAcquireNextImageKHR(swapChain->native(), UINT64_MAX, imageAvailableSemaphores[cmdBufferIndex]->native(), nullptr, &imageIndex);
|
||||
if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) {
|
||||
std::cerr << "failed to acquire image" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
updateUniformBuffer(cmdBufferIndex);
|
||||
|
||||
logicalDevice->functions().vkResetFences(1, &_cmdBufferFences[cmdBufferIndex]);
|
||||
|
||||
logicalDevice->functions().vkResetCommandBuffer(presentCommandBuffers[cmdBufferIndex], /*VkCommandBufferResetFlagBits*/ 0);
|
||||
recordCommandBuffer(presentCommandBuffers[cmdBufferIndex], cmdBufferIndex, imageIndex);
|
||||
|
||||
|
||||
|
||||
VkSubmitInfo submitInfo = {};
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
|
||||
submitInfo.waitSemaphoreCount = 1;
|
||||
submitInfo.pWaitSemaphores = &imageAvailableSemaphores[cmdBufferIndex]->native();
|
||||
submitInfo.signalSemaphoreCount = 1;
|
||||
submitInfo.pSignalSemaphores = &renderingFinishedSemaphores[cmdBufferIndex]->native();
|
||||
|
||||
// This is the stage where the queue should wait on the semaphore (it doesn't have to wait with drawing, for example)
|
||||
VkPipelineStageFlags waitDstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||
submitInfo.pWaitDstStageMask = &waitDstStageMask;
|
||||
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &presentCommandBuffers[cmdBufferIndex];
|
||||
|
||||
if (logicalDevice->functions().vkQueueSubmit(queues[0].queue, 1, &submitInfo, _cmdBufferFences[cmdBufferIndex]) != VK_SUCCESS) {
|
||||
std::cerr << "failed to submit draw command buffer" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// std::cout << "submitted draw command buffer" << std::endl;
|
||||
|
||||
// Present drawn image
|
||||
// Note: semaphore here is not strictly necessary, because commands are processed in submission order within a single queue
|
||||
VkPresentInfoKHR presentInfo = {};
|
||||
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||
presentInfo.waitSemaphoreCount = 1;
|
||||
presentInfo.pWaitSemaphores = &renderingFinishedSemaphores[cmdBufferIndex]->native();
|
||||
|
||||
auto nativeSwapChain = swapChain->native();
|
||||
presentInfo.swapchainCount = 1;
|
||||
presentInfo.pSwapchains = &nativeSwapChain;
|
||||
presentInfo.pImageIndices = &imageIndex;
|
||||
|
||||
auto res = logicalDevice->functions().vkQueuePresentKHR(queues[0].queue, &presentInfo);
|
||||
|
||||
if (res != VK_SUCCESS) {
|
||||
std::cerr << "failed to submit present command buffer" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cmdBufferIndex = (cmdBufferIndex + 1) % _cmdBufferFences.size();
|
||||
//std::cout << "submitted presentation command buffer for image " << imageIndex << std::endl;
|
||||
|
||||
|
||||
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
std::cout << "Test" << std::endl;
|
||||
}
|
||||
|
||||
void Application::copyBufferHostToDevice(IntrusivePtr<VulkanLogicalDevice> device, VulkanQueue queue, VkCommandPool pool, IntrusivePtr<VulkanBuffer> hostBuffer, IntrusivePtr<VulkanBuffer> deviceBuffer) {
|
||||
VkCommandBuffer cmdBuffer;
|
||||
|
||||
VkCommandBufferAllocateInfo allocInfo = {};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
allocInfo.commandPool = pool;
|
||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
allocInfo.commandBufferCount = 1;
|
||||
|
||||
if (device->functions().vkAllocateCommandBuffers(&allocInfo, &cmdBuffer) != VK_SUCCESS) {
|
||||
throw std::runtime_error("Failed to allocate command buffer");
|
||||
}
|
||||
|
||||
// If requested, also start the new command buffer
|
||||
VkCommandBufferBeginInfo beginInfo = {};
|
||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
|
||||
device->functions().vkBeginCommandBuffer(cmdBuffer, &beginInfo);
|
||||
|
||||
|
||||
VkBufferCopy copyRegion = {};
|
||||
copyRegion.size = hostBuffer->getMemoryRequirements().size;
|
||||
|
||||
device->functions().vkCmdCopyBuffer(cmdBuffer, hostBuffer->native(), deviceBuffer->native(), 1, ©Region);
|
||||
|
||||
device->functions().vkEndCommandBuffer(cmdBuffer);
|
||||
|
||||
VkSubmitInfo submitInfo = {};
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &cmdBuffer;
|
||||
|
||||
// Create fence to ensure that the command buffer has finished executing
|
||||
VkFenceCreateInfo fenceCreateInfo = {};
|
||||
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||
fenceCreateInfo.flags = 0;
|
||||
VkFence fence;
|
||||
device->functions().vkCreateFence(&fenceCreateInfo, nullptr, &fence);
|
||||
|
||||
// Submit to the queue
|
||||
device->functions().vkQueueSubmit(queue.queue, 1, &submitInfo, fence);
|
||||
// Wait for the fence to signal that command buffer has finished executing
|
||||
device->functions().vkWaitForFences(1, &fence, VK_TRUE, DEFAULT_FENCE_TIMEOUT);
|
||||
|
||||
device->functions().vkDestroyFence(fence, nullptr);
|
||||
device->functions().vkFreeCommandBuffers(pool, 1, &cmdBuffer);
|
||||
|
||||
}
|
||||
|
||||
IntrusivePtr<VulkanBuffer> Application::createBuffer(VkBufferUsageFlagBits usage, const void* data, VkDeviceSize size, IntrusivePtr<VulkanLogicalDevice> logicalDevice, IntrusivePtr<VulkanPhysicalDevice> device, VulkanQueue queue, VkCommandPool commandPool) {
|
||||
auto memoryProps = device->getMemoryProperties();
|
||||
|
||||
auto stagingBuffer = IntrusivePtr<VulkanBuffer>(new VulkanBuffer(logicalDevice, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT));
|
||||
auto memoryRequirements = stagingBuffer->getMemoryRequirements();
|
||||
auto suitableIndices = memoryProps.findSuitableMemoryTypeIndices(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, memoryRequirements.memoryTypeBits);
|
||||
|
||||
auto stagingBufferMemory = IntrusivePtr<VulkanMemory>(new VulkanMemory(logicalDevice, memoryRequirements.size, suitableIndices[0]));
|
||||
stagingBufferMemory->write(data, size);
|
||||
|
||||
stagingBuffer->bindMemory(stagingBufferMemory);
|
||||
|
||||
|
||||
auto result = IntrusivePtr<VulkanBuffer>(new VulkanBuffer(logicalDevice, size, usage | VK_BUFFER_USAGE_TRANSFER_DST_BIT));
|
||||
memoryRequirements = result->getMemoryRequirements();
|
||||
suitableIndices = memoryProps.findSuitableMemoryTypeIndices(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, memoryRequirements.memoryTypeBits);
|
||||
auto resultMemory = IntrusivePtr<VulkanMemory>(new VulkanMemory(logicalDevice, memoryRequirements.size, suitableIndices[0]));
|
||||
result->bindMemory(resultMemory);
|
||||
|
||||
copyBufferHostToDevice(logicalDevice, queue, commandPool, stagingBuffer, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
VkDescriptorPool Application::createDescriptorPool(std::size_t descriptorCount)
|
||||
{
|
||||
// We need to tell the API the number of max. requested descriptors per type
|
||||
VkDescriptorPoolSize typeCounts[1];
|
||||
// This example only uses one descriptor type (uniform buffer) and only requests one descriptor of this type
|
||||
typeCounts[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
typeCounts[0].descriptorCount = descriptorCount;
|
||||
// For additional types you need to add new entries in the type count list
|
||||
// E.g. for two combined image samplers :
|
||||
// typeCounts[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
// typeCounts[1].descriptorCount = 2;
|
||||
|
||||
// Create the global descriptor pool
|
||||
// All descriptors used in this example are allocated from this pool
|
||||
VkDescriptorPoolCreateInfo descriptorPoolInfo = {};
|
||||
descriptorPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
descriptorPoolInfo.pNext = nullptr;
|
||||
descriptorPoolInfo.poolSizeCount = 1;
|
||||
descriptorPoolInfo.pPoolSizes = typeCounts;
|
||||
// Set the max. number of descriptor sets that can be requested from this pool (requesting beyond this limit will result in an error)
|
||||
descriptorPoolInfo.maxSets = descriptorCount;
|
||||
|
||||
VkDescriptorPool result;
|
||||
|
||||
|
||||
if (logicalDevice->functions().vkCreateDescriptorPool(&descriptorPoolInfo, nullptr, &result) != VK_SUCCESS)
|
||||
{
|
||||
throw std::runtime_error("Failed to create descriptor pool");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <Windows.h>
|
||||
#include "DynamicLibrary.h"
|
||||
#include "VulkanInstance.h"
|
||||
#include "VulkanDynamicLibrary.h"
|
||||
#include "VulkanLogicalDevice.h"
|
||||
#include "VulkanImageView.h"
|
||||
#include "VulkanSwapChain.h"
|
||||
#include "VulkanImageView.h"
|
||||
#include "VulkanShaderModule.h"
|
||||
#include "VulkanSemaphore.h"
|
||||
#include "VulkanDescriptorSetLayout.h"
|
||||
#include "VulkanMemory.h"
|
||||
#include "VulkanBuffer.h"
|
||||
#include "VulkanPipeline.h"
|
||||
#include "VulkanFrameBuffer.h"
|
||||
#include "UboPerObjectData.h"
|
||||
#include "RenderWindow.h"
|
||||
#include "TempFile.h"
|
||||
#include "ShaderCompiler.h"
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <optional>
|
||||
#include "Vertex.h"
|
||||
#include "UniformBuffer.h"
|
||||
#include <spirv_reflect.h>
|
||||
|
||||
|
||||
#define DEFAULT_FENCE_TIMEOUT 100000000000
|
||||
|
||||
class Application {
|
||||
public:
|
||||
Application();
|
||||
|
||||
void createSwapChain();
|
||||
|
||||
void run();
|
||||
|
||||
void copyBufferHostToDevice(IntrusivePtr<VulkanLogicalDevice> device, VulkanQueue queue, VkCommandPool pool, IntrusivePtr<VulkanBuffer> hostBuffer, IntrusivePtr<VulkanBuffer> deviceBuffer);
|
||||
|
||||
IntrusivePtr<VulkanBuffer> createBuffer(VkBufferUsageFlagBits usage, const void* data, VkDeviceSize size, IntrusivePtr<VulkanLogicalDevice> logicalDevice, IntrusivePtr<VulkanPhysicalDevice> device, VulkanQueue queue, VkCommandPool commandPool);
|
||||
|
||||
VkDescriptorPool createDescriptorPool(std::size_t descriptorCount);
|
||||
|
||||
void createPipeline();
|
||||
|
||||
void recordCommandBuffer(VkCommandBuffer cmdBuffer, uint32_t cmdBufferIndex, uint32_t imageIndex);
|
||||
|
||||
void updateUniformBuffer(uint32_t currentImage);
|
||||
private:
|
||||
std::shared_ptr<VulkanDynamicLibrary> vulkan;
|
||||
IntrusivePtr<VulkanPhysicalDevice> device;
|
||||
IntrusivePtr<VulkanLogicalDevice> logicalDevice;
|
||||
std::vector<VulkanQueue> queues;
|
||||
VulkanSwapChain* swapChain;
|
||||
RenderWindow* window;
|
||||
VkCommandPool presentCommandPool;
|
||||
VkCommandPool renderCommandPool;
|
||||
uint32_t presentQueueFamilyIndex = -1;
|
||||
uint32_t renderQueueFamilyIndex = -1;
|
||||
|
||||
IntrusivePtr<VulkanShaderModule> vs;
|
||||
IntrusivePtr<VulkanShaderModule> ps;
|
||||
|
||||
IntrusivePtr<VulkanBuffer> _vertexBuffer;
|
||||
IntrusivePtr<VulkanBuffer> _indexBuffer;
|
||||
|
||||
IntrusivePtr<VulkanPipeline> _pipeline;
|
||||
|
||||
std::vector<IntrusivePtr<VulkanFrameBuffer>> _frameBuffers;
|
||||
std::vector<IntrusivePtr<VulkanImageView>> _imageViews;
|
||||
std::vector<IntrusivePtr<UniformBuffer>> _uniformBuffers;
|
||||
|
||||
IntrusivePtr<VulkanDescriptorSetLayout> _uboDescriptorSetLayout;
|
||||
|
||||
std::vector<VkDescriptorSet> descriptorSets;
|
||||
|
||||
VkRenderPass _renderPass;
|
||||
|
||||
std::vector<VkCommandBuffer> presentCommandBuffers;
|
||||
std::vector<VkFence> _cmdBufferFences;
|
||||
|
||||
void compileShaders();
|
||||
};
|
||||
@@ -0,0 +1,86 @@
|
||||
|
||||
|
||||
include(VulkanTools)
|
||||
|
||||
Vulkan_generateFunctionsFile("${CMAKE_CURRENT_LIST_DIR}")
|
||||
|
||||
add_library(VulkanWrapper INTERFACE)
|
||||
|
||||
target_compile_definitions(VulkanWrapper
|
||||
INTERFACE
|
||||
VK_NO_PROTOTYPES
|
||||
)
|
||||
|
||||
target_sources(VulkanWrapper
|
||||
INTERFACE
|
||||
Application.cpp
|
||||
Application.h
|
||||
CMakeLists.txt
|
||||
DynamicLibrary.cpp
|
||||
DynamicLibrary.h
|
||||
FragmentShader_unknown.h
|
||||
FunctionTraits.h
|
||||
IntrusivePtr.h
|
||||
main.cpp
|
||||
RefCountedObject.h
|
||||
RenderWindow.h
|
||||
RenderWindowWindows.cpp
|
||||
ShaderCompiler.h
|
||||
TempFile.h
|
||||
VertexShader_unknown.h
|
||||
VulkanApplicationInfo.h
|
||||
VulkanBuffer.h
|
||||
VulkanCommon.h
|
||||
VulkanDynamicLibrary.h
|
||||
VulkanFunctions.h
|
||||
VulkanImageView.h
|
||||
VulkanInstance.cpp
|
||||
VulkanInstance.h
|
||||
VulkanLibrary.cpp
|
||||
VulkanLibrary.h
|
||||
VulkanLogicalDevice.cpp
|
||||
VulkanLogicalDevice.h
|
||||
VulkanMemory.h
|
||||
VulkanMemoryProperties.h
|
||||
VulkanPhysicalDevice.cpp
|
||||
VulkanPhysicalDevice.h
|
||||
VulkanQueueFamilyProperties.h
|
||||
VulkanSemaphore.h
|
||||
VulkanShaderModule.h
|
||||
VulkanSwapChain.h
|
||||
WindowWindows.h
|
||||
|
||||
VulkanDeviceFunctions.h
|
||||
VulkanInstanceFunctions.h
|
||||
VulkanGlobalFunctions.h
|
||||
|
||||
Vertex.h
|
||||
VulkanPipelineLayout.h
|
||||
VulkanPipelineLayout.cpp
|
||||
|
||||
VulkanPipeline.h
|
||||
VulkanPipeline.cpp
|
||||
|
||||
VulkanFrameBuffer.h
|
||||
VulkanFrameBuffer.cpp
|
||||
|
||||
VulkanDescriptorSetLayout.h
|
||||
VulkanDescriptorSetLayout.cpp
|
||||
UboPerObjectData.h
|
||||
|
||||
UniformBuffer.h
|
||||
|
||||
${Vulkan_INCLUDE_DIR}/../Source/SPIRV-Reflect/spirv_reflect.h
|
||||
${Vulkan_INCLUDE_DIR}/../Source/SPIRV-Reflect/spirv_reflect.c
|
||||
)
|
||||
|
||||
target_include_directories(VulkanWrapper
|
||||
INTERFACE
|
||||
${Vulkan_INCLUDE_DIR}/../Source/SPIRV-Reflect
|
||||
)
|
||||
|
||||
target_link_libraries(VulkanWrapper
|
||||
INTERFACE
|
||||
Vulkan::Vulkan
|
||||
glslang::glslang
|
||||
)
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "DynamicLibrary.h"
|
||||
|
||||
|
||||
DynamicLibrary::DynamicLibrary(const std::filesystem::path& path) {
|
||||
_library = LoadLibraryW(path.c_str());
|
||||
|
||||
if (_library == NULL) {
|
||||
throw std::runtime_error("Failed to load library");
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicLibrary::addSearchPath(const std::filesystem::path& path) {
|
||||
SetDllDirectoryW(path.c_str());
|
||||
}
|
||||
|
||||
void* DynamicLibrary::getFunction(const std::string& name) {
|
||||
return GetProcAddress(_library, name.c_str());
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <Windows.h>
|
||||
#include <type_traits>
|
||||
#include <filesystem>
|
||||
|
||||
class DynamicLibrary {
|
||||
public:
|
||||
DynamicLibrary(const std::filesystem::path& path);
|
||||
static void addSearchPath(const std::filesystem::path& path);
|
||||
|
||||
template<typename FunctionPtr, typename = std::enable_if_t<std::is_function_v<std::remove_pointer_t<FunctionPtr>>>>
|
||||
FunctionPtr getFunction(const std::string& name) {
|
||||
return reinterpret_cast<FunctionPtr>(getFunction(name));
|
||||
}
|
||||
|
||||
void* getFunction(const std::string& name);
|
||||
private:
|
||||
HMODULE _library = NULL;
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
const char* frag = R"(
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 fragColor;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(fragColor, 1.0);
|
||||
}
|
||||
)";
|
||||
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
|
||||
template<class F>
|
||||
struct FunctionTraits;
|
||||
|
||||
template<class R, class... Args>
|
||||
struct FunctionTraits<R(Args...)>
|
||||
{
|
||||
using ReturnType = R;
|
||||
|
||||
static constexpr std::size_t Arity = sizeof...(Args);
|
||||
|
||||
using AllArgs = std::tuple<Args...>;
|
||||
|
||||
template <int N>
|
||||
struct ArgumentHelper
|
||||
{
|
||||
static_assert(N < Arity, "error: invalid parameter index.");
|
||||
using Type = typename std::tuple_element<N, std::tuple<Args...>>::type;
|
||||
};
|
||||
|
||||
template <int N>
|
||||
using Argument = typename ArgumentHelper<N>::Type;
|
||||
};
|
||||
|
||||
// function pointer
|
||||
template<class R, class... Args>
|
||||
struct FunctionTraits<R(*)(Args...)> : public FunctionTraits<R(Args...)>
|
||||
{};
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct RemoveFirstType
|
||||
{
|
||||
};
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
struct RemoveFirstType<std::tuple<T, Ts...>>
|
||||
{
|
||||
typedef std::tuple<Ts...> type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct RemoveFirstArg {};
|
||||
|
||||
template<typename TResult, typename ... TArgs>
|
||||
struct RemoveFirstArg<TResult(TArgs...)> {
|
||||
|
||||
template<typename TResult1, typename T = void, typename ... TArgs1>
|
||||
struct TypeHelper {
|
||||
using type = TResult1(*)(TArgs1...);
|
||||
};
|
||||
using pointerType = typename TypeHelper<TResult, TArgs...>::type;
|
||||
using type = std::remove_pointer_t<pointerType>;
|
||||
};
|
||||
|
||||
template<typename TResult, typename ... TArgs>
|
||||
struct RemoveFirstArg<TResult(*)(TArgs...)> : RemoveFirstArg<TResult(TArgs...)> {};
|
||||
|
||||
template<typename T>
|
||||
using RemoveFirstArgT = typename RemoveFirstArg<T>::type;
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct LambdaHelper {};
|
||||
|
||||
template<typename R, typename ... Args>
|
||||
struct LambdaHelper<R(Args...)> {
|
||||
using RawFunc = R(*)(VkDevice, Args...);
|
||||
static auto makeLambda(RawFunc func, VkDevice device) {
|
||||
return [func, device](Args... args) {
|
||||
return func(device, args...);
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,104 @@
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
#include <stdexcept>
|
||||
|
||||
template<typename T>
|
||||
void IntrusivePtrAddRef(T* ptr) {
|
||||
ptr->addref();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void IntrusivePtrRelease(T* ptr) {
|
||||
ptr->release();
|
||||
}
|
||||
|
||||
template<typename Object>
|
||||
class IntrusivePtr {
|
||||
public:
|
||||
IntrusivePtr() {
|
||||
}
|
||||
~IntrusivePtr() {
|
||||
reset();
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
IntrusivePtr(U* src, bool addref = true) : _object(static_cast<std::add_pointer_t<std::enable_if_t<std::is_convertible_v<U, Object>, Object>>>(src)) {
|
||||
if (addref) {
|
||||
addrefImpl();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
IntrusivePtr(const IntrusivePtr<U>& src) : _object(static_cast<std::add_pointer_t<std::enable_if_t<std::is_convertible_v<U, Object>, Object>>>(src.get())) {
|
||||
addrefImpl();
|
||||
}
|
||||
|
||||
IntrusivePtr(Object* object, bool addref = true) :_object(object) {
|
||||
if (addref) {
|
||||
addrefImpl();
|
||||
}
|
||||
}
|
||||
IntrusivePtr(const IntrusivePtr& ptr) {
|
||||
_object = ptr._object;
|
||||
if (_object) {
|
||||
addrefImpl();
|
||||
}
|
||||
}
|
||||
IntrusivePtr& operator=(const IntrusivePtr& other) {
|
||||
assign(other._object, true);
|
||||
return *this;
|
||||
}
|
||||
IntrusivePtr& operator=(std::nullptr_t) {
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
static inline IntrusivePtr<Object> create(Args... args){
|
||||
return IntrusivePtr<Object>( new Object(std::forward<Args>(args)... ));
|
||||
}
|
||||
|
||||
void assign(Object* object, bool addref = true) {
|
||||
if (object != nullptr && addref) {
|
||||
object->addref();
|
||||
}
|
||||
reset();
|
||||
_object = object;
|
||||
}
|
||||
|
||||
Object* operator->() {
|
||||
if (_object == nullptr) {
|
||||
throw new std::runtime_error("Accessing null object in IntrusivePtr");
|
||||
}
|
||||
return _object;
|
||||
}
|
||||
|
||||
const Object* operator->() const {
|
||||
if (_object == nullptr) {
|
||||
throw new std::runtime_error("Accessing null object in IntrusivePtr");
|
||||
}
|
||||
return _object;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
if (_object != nullptr) {
|
||||
releaseImpl();
|
||||
_object = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Object* get() const {
|
||||
return _object;
|
||||
}
|
||||
|
||||
private:
|
||||
Object * _object = nullptr;
|
||||
|
||||
void addrefImpl() {
|
||||
IntrusivePtrAddRef(_object);
|
||||
}
|
||||
|
||||
void releaseImpl() {
|
||||
IntrusivePtrRelease(_object);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "IntrusivePtr.h"
|
||||
|
||||
class RefCountedObject {
|
||||
public:
|
||||
virtual ~RefCountedObject() = default;
|
||||
void addref() {
|
||||
++_refCount;
|
||||
}
|
||||
void release() {
|
||||
if (--_refCount == 0) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
private:
|
||||
size_t _refCount = 0;
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "VulkanInstance.h"
|
||||
#include "IntrusivePtr.h"
|
||||
#include <vector>
|
||||
|
||||
class RenderWindow {
|
||||
public:
|
||||
RenderWindow(IntrusivePtr<VulkanInstance> instance);
|
||||
RenderWindow(IntrusivePtr<VulkanInstance> instance, const std::string& name);
|
||||
~RenderWindow();
|
||||
static std::vector<std::string> getRequiredExtensionNames();
|
||||
bool update();
|
||||
bool canPresent(IntrusivePtr<VulkanPhysicalDevice> physicalDevice, uint32_t queueFamilyIndex);
|
||||
VkSurfaceKHR getSurface() const;
|
||||
private:
|
||||
class RenderWindowPrivate;
|
||||
std::unique_ptr<RenderWindowPrivate> _private{};
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "RenderWindow.h"
|
||||
#include "WindowWindows.h"
|
||||
#include <memory>
|
||||
#include <vulkan/vulkan_win32.h>
|
||||
|
||||
class RenderWindow::RenderWindowPrivate {
|
||||
public:
|
||||
RenderWindowPrivate(IntrusivePtr<VulkanInstance> instance, const std::string& name):instance(instance) {
|
||||
window = std::make_unique<Window>(name);
|
||||
}
|
||||
|
||||
~RenderWindowPrivate() {
|
||||
auto destroySurfaceKHR = instance->getProcAddr<PFN_vkDestroySurfaceKHR>("vkDestroySurfaceKHR");
|
||||
if (destroySurfaceKHR) {
|
||||
destroySurfaceKHR(instance->vkInstance(), surface, nullptr);
|
||||
}
|
||||
}
|
||||
std::unique_ptr<Window> window{};
|
||||
VkSurfaceKHR surface;
|
||||
IntrusivePtr<VulkanInstance> instance;
|
||||
};
|
||||
|
||||
RenderWindow::RenderWindow(IntrusivePtr<VulkanInstance> instance) : RenderWindow(instance, "RenderWindow") {}
|
||||
RenderWindow::RenderWindow(IntrusivePtr<VulkanInstance> instance, const std::string& name) {
|
||||
_private.reset(new RenderWindowPrivate(instance, name));
|
||||
|
||||
VkWin32SurfaceCreateInfoKHR createInfo = {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
||||
createInfo.hwnd = _private->window->getHwnd();
|
||||
createInfo.hinstance = GetModuleHandle(nullptr);
|
||||
|
||||
auto createWin32SurfaceKHR = instance->getProcAddr<PFN_vkCreateWin32SurfaceKHR>("vkCreateWin32SurfaceKHR");
|
||||
|
||||
if (!createWin32SurfaceKHR || createWin32SurfaceKHR(instance->vkInstance(), &createInfo, nullptr, &_private->surface) != VK_SUCCESS) {
|
||||
throw std::runtime_error("Failed to create render window surface");
|
||||
}
|
||||
}
|
||||
RenderWindow::~RenderWindow() = default;
|
||||
|
||||
std::vector<std::string> RenderWindow::getRequiredExtensionNames(){
|
||||
return { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME };
|
||||
}
|
||||
|
||||
bool RenderWindow::update() {
|
||||
return _private->window->update();
|
||||
}
|
||||
|
||||
bool RenderWindow::canPresent(IntrusivePtr<VulkanPhysicalDevice> physicalDevice, uint32_t queueFamilyIndex) {
|
||||
auto func = _private->instance->getProcAddr<PFN_vkGetPhysicalDeviceSurfaceSupportKHR>("vkGetPhysicalDeviceSurfaceSupportKHR");
|
||||
if (func == nullptr) {
|
||||
return false;
|
||||
}
|
||||
VkBool32 presentSupported = VK_FALSE;
|
||||
func(physicalDevice->getDevice(), queueFamilyIndex, _private->surface, &presentSupported);
|
||||
return presentSupported != VK_FALSE;
|
||||
}
|
||||
VkSurfaceKHR RenderWindow::getSurface() const {
|
||||
return _private->surface;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "TempFile.h"
|
||||
#include <stdexcept>
|
||||
|
||||
enum class ShaderCompilerStage {
|
||||
vert,
|
||||
tesc,
|
||||
tese,
|
||||
geom,
|
||||
frag,
|
||||
comp
|
||||
};
|
||||
|
||||
inline const char* toString(ShaderCompilerStage stage) {
|
||||
switch (stage) {
|
||||
case ShaderCompilerStage::vert:
|
||||
return "vert";
|
||||
case ShaderCompilerStage::tesc:
|
||||
return "tesc";
|
||||
case ShaderCompilerStage::tese:
|
||||
return "tese";
|
||||
case ShaderCompilerStage::geom:
|
||||
return "geom";
|
||||
case ShaderCompilerStage::frag:
|
||||
return "frag";
|
||||
case ShaderCompilerStage::comp:
|
||||
return "comp";
|
||||
default:
|
||||
throw std::runtime_error("Unknown ShaderCompilerStage");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct ShaderCompilerResult {
|
||||
bool success;
|
||||
std::string errors;
|
||||
std::vector<char> binary;
|
||||
};
|
||||
|
||||
class ShaderCompiler {
|
||||
public:
|
||||
static ShaderCompilerResult compile(const std::string& code, ShaderCompilerStage stage) {
|
||||
ShaderCompilerResult result;
|
||||
auto inputFile = TempFile();
|
||||
inputFile.open();
|
||||
inputFile << code;
|
||||
inputFile.close();
|
||||
|
||||
auto outputVertexFile = TempFile();
|
||||
|
||||
auto errorFile = TempFile();
|
||||
|
||||
std::string compilerPath = R"(C:\VulkanSDK\1.3.290.0\Bin\glslangValidator.exe)";
|
||||
|
||||
if (!std::filesystem::exists(compilerPath)) {
|
||||
throw new std::runtime_error("Failed to find shader compiler at path: " + compilerPath);
|
||||
}
|
||||
|
||||
std::string cmd = compilerPath + " -V ";
|
||||
cmd += inputFile.path() + " -o " + outputVertexFile.path() + " -S " + toString(stage) + " >" + errorFile.path();
|
||||
|
||||
int errorCode = std::system(cmd.c_str());
|
||||
errorFile.open(std::ios_base::in | std::ios_base::binary);
|
||||
auto errorData = errorFile.readAll();
|
||||
std::string error(errorData.data(), errorData.size());
|
||||
result.errors = error;
|
||||
|
||||
result.success = errorCode == 0;
|
||||
|
||||
if(!result.success){
|
||||
std::cout << result.errors << std::endl;
|
||||
throw std::runtime_error("Failed to compile shader");
|
||||
}
|
||||
|
||||
outputVertexFile.open(std::ios_base::in | std::ios_base::binary);
|
||||
result.binary = outputVertexFile.readAll();
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <Windows.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
class TempFile {
|
||||
public:
|
||||
TempFile() {
|
||||
std::vector<char> path;
|
||||
path.resize(MAX_PATH);
|
||||
GetTempPathA(path.size(), path.data());
|
||||
|
||||
std::vector<char> name;
|
||||
name.resize(MAX_PATH);
|
||||
GetTempFileNameA(path.data(), "vk", 0, name.data());
|
||||
_path = name.data();
|
||||
}
|
||||
|
||||
std::fstream& open(std::ios_base::openmode mode = std::ios_base::out | std::ios_base::in | std::ios_base::binary) {
|
||||
_stream.open(_path, mode);
|
||||
return _stream;
|
||||
}
|
||||
|
||||
void close() {
|
||||
_stream.close();
|
||||
}
|
||||
|
||||
std::vector<char> readAll() {
|
||||
_stream.seekg(0, std::ios::end);
|
||||
auto pos = _stream.tellg();
|
||||
_stream.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<char> result(pos);
|
||||
|
||||
if (pos > 0) {
|
||||
_stream.read(&result[0], pos);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
TempFile& operator <<(const T& value) {
|
||||
_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
TempFile& operator >>(T& value) {
|
||||
_stream >> value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
~TempFile() {
|
||||
if (_stream.is_open()) {
|
||||
_stream.close();
|
||||
}
|
||||
DeleteFileA(_path.data());
|
||||
}
|
||||
const std::string& path() const {
|
||||
return _path;
|
||||
}
|
||||
|
||||
std::fstream& stream() {
|
||||
return _stream;
|
||||
}
|
||||
private:
|
||||
std::fstream _stream;
|
||||
std::string _path;
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
struct UboPerObjectData {
|
||||
glm::mat4 model;
|
||||
glm::mat4 view;
|
||||
glm::mat4 proj;
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "VulkanBuffer.h"
|
||||
#include "VulkanLogicalDevice.h"
|
||||
#include "RefCountedObject.h"
|
||||
|
||||
class UniformBuffer : public RefCountedObject {
|
||||
public:
|
||||
UniformBuffer(IntrusivePtr<VulkanLogicalDevice> device, std::size_t dataSize) {
|
||||
_buffer = IntrusivePtr<VulkanBuffer>(new VulkanBuffer(device, dataSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT));
|
||||
_buffer->allocateMemory(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
auto memory = _buffer->memory();
|
||||
_mappedMemory = memory->map(dataSize, 0);
|
||||
}
|
||||
IntrusivePtr<VulkanBuffer> buffer() {
|
||||
return _buffer;
|
||||
}
|
||||
void* mappedMemory() const {
|
||||
return _mappedMemory;
|
||||
}
|
||||
~UniformBuffer() {
|
||||
_buffer->memory()->unmap();
|
||||
}
|
||||
private:
|
||||
void* _mappedMemory;
|
||||
IntrusivePtr<VulkanBuffer> _buffer;
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <array>
|
||||
|
||||
struct Vertex {
|
||||
float position[3];
|
||||
float color[3];
|
||||
|
||||
static VkVertexInputBindingDescription getBindingDescription(uint32_t bindingId = 0) {
|
||||
VkVertexInputBindingDescription bindingDescription{};
|
||||
bindingDescription.binding = bindingId;
|
||||
bindingDescription.stride = sizeof(Vertex);
|
||||
bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||
return bindingDescription;
|
||||
}
|
||||
|
||||
static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescriptions(uint32_t bindingId = 0) {
|
||||
std::array<VkVertexInputAttributeDescription, 2> attributeDescriptions{};
|
||||
attributeDescriptions[0].binding = bindingId;
|
||||
attributeDescriptions[0].location = 0;
|
||||
attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||
attributeDescriptions[0].offset = offsetof(Vertex, position);
|
||||
|
||||
|
||||
attributeDescriptions[1].binding = bindingId;
|
||||
attributeDescriptions[1].location = 1;
|
||||
attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||
attributeDescriptions[1].offset = offsetof(Vertex, color);
|
||||
|
||||
return attributeDescriptions;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
const char* vert = R"(
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(binding = 0) uniform UniformBufferObject {
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
} ubo;
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec3 inColor;
|
||||
|
||||
layout(location = 0) out vec3 fragColor;
|
||||
|
||||
void main() {
|
||||
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition.xyz, 1.0);
|
||||
fragColor = vec3(inColor.xyz);
|
||||
}
|
||||
)";
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
struct VulkanApplicationInfo : public VkApplicationInfo {
|
||||
VulkanApplicationInfo(const char* pApplicationName_ = nullptr, uint32_t applicationVersion_ = 0, const char* pEngineName_ = nullptr, uint32_t engineVersion_ = 0, uint32_t apiVersion_ = 0) {
|
||||
sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
pNext = nullptr;
|
||||
pApplicationName = pApplicationName_;
|
||||
applicationVersion = applicationVersion_;
|
||||
pEngineName = pEngineName_;
|
||||
engineVersion = engineVersion_;
|
||||
apiVersion = apiVersion_;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "VulkanLogicalDevice.h"
|
||||
#include "VulkanMemory.h"
|
||||
#include "IntrusivePtr.h"
|
||||
|
||||
class VulkanBuffer : public RefCountedObject {
|
||||
public:
|
||||
VulkanBuffer(IntrusivePtr<VulkanLogicalDevice> device, VkBufferCreateInfo createInfo):_device(device) {
|
||||
internalConstruct(createInfo);
|
||||
}
|
||||
|
||||
VulkanBuffer(const VulkanBuffer&) = delete;
|
||||
|
||||
VulkanBuffer(VulkanBuffer&& other) noexcept {
|
||||
_buffer = other._buffer;
|
||||
_size = other._size;
|
||||
_device = other._device;
|
||||
_memory = other._memory;
|
||||
|
||||
other._buffer = nullptr;
|
||||
other._size = 0;
|
||||
other._device = nullptr;
|
||||
other._memory = nullptr;
|
||||
}
|
||||
|
||||
VulkanBuffer(IntrusivePtr<VulkanLogicalDevice> device, VkDeviceSize size, VkBufferUsageFlags usageFlags) : _device(device) {
|
||||
VkBufferCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
createInfo.size = size;
|
||||
createInfo.usage = usageFlags;
|
||||
internalConstruct(createInfo);
|
||||
}
|
||||
|
||||
VkMemoryRequirements getMemoryRequirements() {
|
||||
VkMemoryRequirements result;
|
||||
_device->functions().vkGetBufferMemoryRequirements(_buffer, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void bindMemory(IntrusivePtr<VulkanMemory> memory) {
|
||||
_memory = memory;
|
||||
if (_device->functions().vkBindBufferMemory(_buffer, _memory->native(), 0) != VK_SUCCESS) {
|
||||
throw std::runtime_error("Failed to bind memory to vulkan buffer");
|
||||
}
|
||||
}
|
||||
|
||||
void allocateMemory(VkMemoryPropertyFlags flags) {
|
||||
auto memoryProps = _device->physicalDevice()->getMemoryProperties();
|
||||
auto memoryRequirements = getMemoryRequirements();
|
||||
auto suitableIndices = memoryProps.findSuitableMemoryTypeIndices(flags, memoryRequirements.memoryTypeBits);
|
||||
auto memory = IntrusivePtr<VulkanMemory>(new VulkanMemory(_device, memoryRequirements.size, suitableIndices[0]));
|
||||
bindMemory(memory);
|
||||
}
|
||||
|
||||
VkBuffer native() const {
|
||||
return _buffer;
|
||||
}
|
||||
VkDeviceSize size() const {
|
||||
return _size;
|
||||
}
|
||||
IntrusivePtr<VulkanMemory> memory() {
|
||||
return _memory;
|
||||
}
|
||||
~VulkanBuffer() {
|
||||
if (_buffer != nullptr) {
|
||||
_device->functions().vkDestroyBuffer(_buffer, nullptr);
|
||||
}
|
||||
}
|
||||
private:
|
||||
void internalConstruct( VkBufferCreateInfo createInfo) {
|
||||
if (_device->functions().vkCreateBuffer(&createInfo, nullptr, &_buffer) != VK_SUCCESS) {
|
||||
throw std::runtime_error("Failed to create vulkan buffer");
|
||||
}
|
||||
_size = createInfo.size;
|
||||
}
|
||||
VkBuffer _buffer = {};
|
||||
VkDeviceSize _size;
|
||||
IntrusivePtr<VulkanLogicalDevice> _device;
|
||||
IntrusivePtr<VulkanMemory> _memory;
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
template<typename T>
|
||||
using VulkanPtr = std::shared_ptr<T>;
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "VulkanDescriptorSetLayout.h"
|
||||
#include "VulkanLogicalDevice.h"
|
||||
|
||||
VulkanDescriptorSetLayout::VulkanDescriptorSetLayout(IntrusivePtr<VulkanLogicalDevice> device, const VkDescriptorSetLayoutCreateInfo& createInfo):_device(device){
|
||||
if (device->functions().vkCreateDescriptorSetLayout(&createInfo, nullptr, &_native) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create descriptor set layout!");
|
||||
}
|
||||
}
|
||||
VulkanDescriptorSetLayout::VulkanDescriptorSetLayout(IntrusivePtr<VulkanLogicalDevice> device, VkDescriptorSetLayout native):_device(device), _native(native){
|
||||
|
||||
}
|
||||
VulkanDescriptorSetLayout::~VulkanDescriptorSetLayout(){
|
||||
if(_native != nullptr){
|
||||
_device->functions().vkDestroyDescriptorSetLayout(_native, nullptr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "IntrusivePtr.h"
|
||||
#include "RefCountedObject.h"
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
class VulkanLogicalDevice;
|
||||
|
||||
class VulkanDescriptorSetLayout : public RefCountedObject {
|
||||
public:
|
||||
VulkanDescriptorSetLayout(IntrusivePtr<VulkanLogicalDevice> device, const VkDescriptorSetLayoutCreateInfo& createInfo);
|
||||
VulkanDescriptorSetLayout(IntrusivePtr<VulkanLogicalDevice> device, VkDescriptorSetLayout native);
|
||||
VkDescriptorSetLayout native() const {
|
||||
return _native;
|
||||
|
||||
}
|
||||
~VulkanDescriptorSetLayout();
|
||||
private:
|
||||
IntrusivePtr<VulkanLogicalDevice> _device;
|
||||
VkDescriptorSetLayout _native;
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "VulkanLibrary.h"
|
||||
#include "DynamicLibrary.h"
|
||||
#include <memory>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <filesystem>
|
||||
|
||||
class VulkanDynamicLibrary : public VulkanLibrary {
|
||||
public:
|
||||
VulkanDynamicLibrary(const std::filesystem::path& path = "vulkan-1") : _library(path) {
|
||||
getInstanceProcAddr = _library.getFunction<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||
|
||||
#define VK_USE_GLOBAL_FUNCTION(name) _functions.name = reinterpret_cast<PFN_##name>(getInstanceProcAddr(nullptr, #name));
|
||||
VK_GLOBAL_FUNCTIONS
|
||||
#undef VK_USE_GLOBAL_FUNCTION
|
||||
}
|
||||
|
||||
private:
|
||||
DynamicLibrary _library;
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "VulkanFrameBuffer.h"
|
||||
#include "VulkanLogicalDevice.h"
|
||||
|
||||
VulkanFrameBuffer::VulkanFrameBuffer(IntrusivePtr<VulkanLogicalDevice> device, const VkFramebufferCreateInfo& createInfo) : _device(device){
|
||||
if (_device->functions().vkCreateFramebuffer(&createInfo, nullptr, &_native) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create framebuffer!");
|
||||
}
|
||||
}
|
||||
VulkanFrameBuffer::VulkanFrameBuffer(IntrusivePtr<VulkanLogicalDevice> device, VkFramebuffer native) : _device(device), _native(native){
|
||||
|
||||
}
|
||||
VulkanFrameBuffer::~VulkanFrameBuffer(){
|
||||
if(_native != nullptr){
|
||||
_device->functions().vkDestroyFramebuffer(_native, nullptr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "IntrusivePtr.h"
|
||||
#include "RefCountedObject.h"
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
class VulkanLogicalDevice;
|
||||
|
||||
class VulkanFrameBuffer : public RefCountedObject {
|
||||
public:
|
||||
VulkanFrameBuffer(IntrusivePtr<VulkanLogicalDevice> device, const VkFramebufferCreateInfo& createInfo);
|
||||
VulkanFrameBuffer(IntrusivePtr<VulkanLogicalDevice> device, VkFramebuffer native);
|
||||
VkFramebuffer native() const {
|
||||
return _native;
|
||||
}
|
||||
~VulkanFrameBuffer();
|
||||
private:
|
||||
IntrusivePtr<VulkanLogicalDevice> _device;
|
||||
VkFramebuffer _native;
|
||||
};
|
||||
@@ -0,0 +1,636 @@
|
||||
#define VK_INSTANCE_FUNCTIONS \
|
||||
VK_USE_INSTANCE_FUNCTION(vkDestroyInstance) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkEnumeratePhysicalDevices) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceFeatures) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceFormatProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceImageFormatProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceQueueFamilyProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceMemoryProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetInstanceProcAddr) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetDeviceProcAddr) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkCreateDevice) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkEnumerateDeviceExtensionProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkEnumerateDeviceLayerProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceSparseImageFormatProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkEnumeratePhysicalDeviceGroups) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceFeatures2) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceProperties2) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceFormatProperties2) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceImageFormatProperties2) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceQueueFamilyProperties2) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceMemoryProperties2) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceSparseImageFormatProperties2) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceExternalBufferProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceExternalFenceProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceExternalSemaphoreProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceToolProperties) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkDestroySurfaceKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceSupportKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceFormatsKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfacePresentModesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDevicePresentRectanglesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPropertiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPlanePropertiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetDisplayPlaneSupportedDisplaysKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetDisplayModePropertiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkCreateDisplayModeKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetDisplayPlaneCapabilitiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkCreateDisplayPlaneSurfaceKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceVideoCapabilitiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceVideoFormatPropertiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceFeatures2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceProperties2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceFormatProperties2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceImageFormatProperties2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceQueueFamilyProperties2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceMemoryProperties2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceSparseImageFormatProperties2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkEnumeratePhysicalDeviceGroupsKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceExternalBufferPropertiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceExternalSemaphorePropertiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceExternalFencePropertiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceCapabilities2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceFormats2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayProperties2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPlaneProperties2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetDisplayModeProperties2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetDisplayPlaneCapabilities2KHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceFragmentShadingRatesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceCalibrateableTimeDomainsKHR) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkCreateDebugReportCallbackEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkDestroyDebugReportCallbackEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkDebugReportMessageEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceExternalImageFormatPropertiesNV) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkReleaseDisplayEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceCapabilities2EXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkCreateDebugUtilsMessengerEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkDestroyDebugUtilsMessengerEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkSubmitDebugUtilsMessageEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceMultisamplePropertiesEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceCalibrateableTimeDomainsEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceToolPropertiesEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceCooperativeMatrixPropertiesNV) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceSupportedFramebufferMixedSamplesCombinationsNV) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkCreateHeadlessSurfaceEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkAcquireDrmDisplayEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetDrmDisplayEXT) \
|
||||
VK_USE_INSTANCE_FUNCTION(vkGetPhysicalDeviceOpticalFlowImageFormatsNV) \
|
||||
|
||||
#define VK_DEVICE_FUNCTIONS \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyDevice) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceQueue) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDeviceWaitIdle) \
|
||||
VK_USE_DEVICE_FUNCTION(vkAllocateMemory) \
|
||||
VK_USE_DEVICE_FUNCTION(vkFreeMemory) \
|
||||
VK_USE_DEVICE_FUNCTION(vkMapMemory) \
|
||||
VK_USE_DEVICE_FUNCTION(vkUnmapMemory) \
|
||||
VK_USE_DEVICE_FUNCTION(vkFlushMappedMemoryRanges) \
|
||||
VK_USE_DEVICE_FUNCTION(vkInvalidateMappedMemoryRanges) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceMemoryCommitment) \
|
||||
VK_USE_DEVICE_FUNCTION(vkBindBufferMemory) \
|
||||
VK_USE_DEVICE_FUNCTION(vkBindImageMemory) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetBufferMemoryRequirements) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageMemoryRequirements) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageSparseMemoryRequirements) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateFence) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyFence) \
|
||||
VK_USE_DEVICE_FUNCTION(vkResetFences) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetFenceStatus) \
|
||||
VK_USE_DEVICE_FUNCTION(vkWaitForFences) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateSemaphore) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroySemaphore) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateEvent) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyEvent) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetEventStatus) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSetEvent) \
|
||||
VK_USE_DEVICE_FUNCTION(vkResetEvent) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateQueryPool) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyQueryPool) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetQueryPoolResults) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateBuffer) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyBuffer) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateBufferView) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyBufferView) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateImage) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyImage) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageSubresourceLayout) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateImageView) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyImageView) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateShaderModule) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyShaderModule) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreatePipelineCache) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyPipelineCache) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetPipelineCacheData) \
|
||||
VK_USE_DEVICE_FUNCTION(vkMergePipelineCaches) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateGraphicsPipelines) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateComputePipelines) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyPipeline) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreatePipelineLayout) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyPipelineLayout) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateSampler) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroySampler) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateDescriptorSetLayout) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyDescriptorSetLayout) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateDescriptorPool) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyDescriptorPool) \
|
||||
VK_USE_DEVICE_FUNCTION(vkResetDescriptorPool) \
|
||||
VK_USE_DEVICE_FUNCTION(vkAllocateDescriptorSets) \
|
||||
VK_USE_DEVICE_FUNCTION(vkFreeDescriptorSets) \
|
||||
VK_USE_DEVICE_FUNCTION(vkUpdateDescriptorSets) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateFramebuffer) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyFramebuffer) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateRenderPass) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyRenderPass) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetRenderAreaGranularity) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateCommandPool) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyCommandPool) \
|
||||
VK_USE_DEVICE_FUNCTION(vkResetCommandPool) \
|
||||
VK_USE_DEVICE_FUNCTION(vkAllocateCommandBuffers) \
|
||||
VK_USE_DEVICE_FUNCTION(vkFreeCommandBuffers) \
|
||||
VK_USE_DEVICE_FUNCTION(vkBindBufferMemory2) \
|
||||
VK_USE_DEVICE_FUNCTION(vkBindImageMemory2) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceGroupPeerMemoryFeatures) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageMemoryRequirements2) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetBufferMemoryRequirements2) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageSparseMemoryRequirements2) \
|
||||
VK_USE_DEVICE_FUNCTION(vkTrimCommandPool) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceQueue2) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateSamplerYcbcrConversion) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroySamplerYcbcrConversion) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateDescriptorUpdateTemplate) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyDescriptorUpdateTemplate) \
|
||||
VK_USE_DEVICE_FUNCTION(vkUpdateDescriptorSetWithTemplate) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDescriptorSetLayoutSupport) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateRenderPass2) \
|
||||
VK_USE_DEVICE_FUNCTION(vkResetQueryPool) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetSemaphoreCounterValue) \
|
||||
VK_USE_DEVICE_FUNCTION(vkWaitSemaphores) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSignalSemaphore) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetBufferDeviceAddress) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetBufferOpaqueCaptureAddress) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceMemoryOpaqueCaptureAddress) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreatePrivateDataSlot) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyPrivateDataSlot) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSetPrivateData) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetPrivateData) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceBufferMemoryRequirements) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceImageMemoryRequirements) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceImageSparseMemoryRequirements) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateSwapchainKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroySwapchainKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetSwapchainImagesKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkAcquireNextImageKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceGroupPresentCapabilitiesKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceGroupSurfacePresentModesKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkAcquireNextImage2KHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateSharedSwapchainsKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateVideoSessionKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyVideoSessionKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetVideoSessionMemoryRequirementsKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkBindVideoSessionMemoryKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateVideoSessionParametersKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkUpdateVideoSessionParametersKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyVideoSessionParametersKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceGroupPeerMemoryFeaturesKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkTrimCommandPoolKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetMemoryFdKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetMemoryFdPropertiesKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkImportSemaphoreFdKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetSemaphoreFdKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateDescriptorUpdateTemplateKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyDescriptorUpdateTemplateKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkUpdateDescriptorSetWithTemplateKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateRenderPass2KHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetSwapchainStatusKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkImportFenceFdKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetFenceFdKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkAcquireProfilingLockKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkReleaseProfilingLockKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageMemoryRequirements2KHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetBufferMemoryRequirements2KHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageSparseMemoryRequirements2KHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateSamplerYcbcrConversionKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroySamplerYcbcrConversionKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkBindBufferMemory2KHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkBindImageMemory2KHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDescriptorSetLayoutSupportKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetSemaphoreCounterValueKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkWaitSemaphoresKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSignalSemaphoreKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkWaitForPresentKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetBufferDeviceAddressKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetBufferOpaqueCaptureAddressKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceMemoryOpaqueCaptureAddressKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateDeferredOperationKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyDeferredOperationKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeferredOperationMaxConcurrencyKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeferredOperationResultKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDeferredOperationJoinKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetPipelineExecutablePropertiesKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetPipelineExecutableStatisticsKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetPipelineExecutableInternalRepresentationsKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkMapMemory2KHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkUnmapMemory2KHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetEncodedVideoSessionParametersKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceBufferMemoryRequirementsKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceImageMemoryRequirementsKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceImageSparseMemoryRequirementsKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetRenderingAreaGranularityKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceImageSubresourceLayoutKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageSubresourceLayout2KHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetCalibratedTimestampsKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDebugMarkerSetObjectTagEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDebugMarkerSetObjectNameEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateCuModuleNVX) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateCuFunctionNVX) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyCuModuleNVX) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyCuFunctionNVX) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageViewHandleNVX) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageViewAddressNVX) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetShaderInfoAMD) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDisplayPowerControlEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkRegisterDeviceEventEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkRegisterDisplayEventEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetSwapchainCounterEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetRefreshCycleDurationGOOGLE) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetPastPresentationTimingGOOGLE) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSetHdrMetadataEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSetDebugUtilsObjectNameEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSetDebugUtilsObjectTagEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageDrmFormatModifierPropertiesEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateValidationCacheEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyValidationCacheEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkMergeValidationCachesEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetValidationCacheDataEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateAccelerationStructureNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyAccelerationStructureNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetAccelerationStructureMemoryRequirementsNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkBindAccelerationStructureMemoryNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateRayTracingPipelinesNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetRayTracingShaderGroupHandlesKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetRayTracingShaderGroupHandlesNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetAccelerationStructureHandleNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCompileDeferredNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetMemoryHostPointerPropertiesEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetCalibratedTimestampsEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkInitializePerformanceApiINTEL) \
|
||||
VK_USE_DEVICE_FUNCTION(vkUninitializePerformanceApiINTEL) \
|
||||
VK_USE_DEVICE_FUNCTION(vkAcquirePerformanceConfigurationINTEL) \
|
||||
VK_USE_DEVICE_FUNCTION(vkReleasePerformanceConfigurationINTEL) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetPerformanceParameterINTEL) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSetLocalDimmingAMD) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetBufferDeviceAddressEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkResetQueryPoolEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCopyMemoryToImageEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCopyImageToMemoryEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCopyImageToImageEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkTransitionImageLayoutEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageSubresourceLayout2EXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkReleaseSwapchainImagesEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetGeneratedCommandsMemoryRequirementsNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateIndirectCommandsLayoutNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyIndirectCommandsLayoutNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreatePrivateDataSlotEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyPrivateDataSlotEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSetPrivateDataEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetPrivateDataEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateCudaModuleNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetCudaModuleCacheNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateCudaFunctionNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyCudaModuleNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyCudaFunctionNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDescriptorSetLayoutSizeEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDescriptorSetLayoutBindingOffsetEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDescriptorEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetBufferOpaqueCaptureDescriptorDataEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageOpaqueCaptureDescriptorDataEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetImageViewOpaqueCaptureDescriptorDataEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetSamplerOpaqueCaptureDescriptorDataEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetAccelerationStructureOpaqueCaptureDescriptorDataEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceFaultInfoEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceSubpassShadingMaxWorkgroupSizeHUAWEI) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetMemoryRemoteAddressNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetPipelinePropertiesEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateMicromapEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyMicromapEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkBuildMicromapsEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCopyMicromapEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCopyMicromapToMemoryEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCopyMemoryToMicromapEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkWriteMicromapsPropertiesEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceMicromapCompatibilityEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetMicromapBuildSizesEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSetDeviceMemoryPriorityEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDescriptorSetLayoutHostMappingInfoVALVE) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDescriptorSetHostMappingVALVE) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetPipelineIndirectMemoryRequirementsNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetPipelineIndirectDeviceAddressNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetShaderModuleIdentifierEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetShaderModuleCreateInfoIdentifierEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateOpticalFlowSessionNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyOpticalFlowSessionNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkBindOpticalFlowSessionImageNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateShadersEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyShaderEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetShaderBinaryDataEXT) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetFramebufferTilePropertiesQCOM) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDynamicRenderingTilePropertiesQCOM) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSetLatencySleepModeNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkLatencySleepNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkSetLatencyMarkerNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetLatencyTimingsNV) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateAccelerationStructureKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkDestroyAccelerationStructureKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkBuildAccelerationStructuresKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCopyAccelerationStructureKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCopyAccelerationStructureToMemoryKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCopyMemoryToAccelerationStructureKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkWriteAccelerationStructuresPropertiesKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetAccelerationStructureDeviceAddressKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetDeviceAccelerationStructureCompatibilityKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetAccelerationStructureBuildSizesKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkCreateRayTracingPipelinesKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetRayTracingCaptureReplayShaderGroupHandlesKHR) \
|
||||
VK_USE_DEVICE_FUNCTION(vkGetRayTracingShaderGroupStackSizeKHR) \
|
||||
|
||||
#define VK_DEVICE_QUEUE_FUNCTIONS \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkQueueSubmit) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkQueueWaitIdle) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkQueueBindSparse) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkQueueSubmit2) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkQueuePresentKHR) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkQueueSubmit2KHR) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkGetQueueCheckpointData2NV) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkQueueBeginDebugUtilsLabelEXT) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkQueueEndDebugUtilsLabelEXT) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkQueueInsertDebugUtilsLabelEXT) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkGetQueueCheckpointDataNV) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkQueueSetPerformanceConfigurationINTEL) \
|
||||
VK_USE_DEVICE_QUEUE_FUNCTION(vkQueueNotifyOutOfBandNV) \
|
||||
|
||||
#define VK_DEVICE_CMD_FUNCTIONS \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkBeginCommandBuffer) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkEndCommandBuffer) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkResetCommandBuffer) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindPipeline) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetViewport) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetScissor) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetLineWidth) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthBias) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetBlendConstants) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthBounds) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetStencilCompareMask) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetStencilWriteMask) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetStencilReference) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindDescriptorSets) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindIndexBuffer) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindVertexBuffers) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDraw) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawIndexed) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawIndirect) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawIndexedIndirect) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDispatch) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDispatchIndirect) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyBuffer) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyImage) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBlitImage) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyBufferToImage) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyImageToBuffer) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdUpdateBuffer) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdFillBuffer) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdClearColorImage) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdClearDepthStencilImage) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdClearAttachments) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdResolveImage) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetEvent) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdResetEvent) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdWaitEvents) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdPipelineBarrier) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBeginQuery) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEndQuery) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdResetQueryPool) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdWriteTimestamp) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyQueryPoolResults) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdPushConstants) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBeginRenderPass) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdNextSubpass) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEndRenderPass) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdExecuteCommands) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDeviceMask) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDispatchBase) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawIndirectCount) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawIndexedIndirectCount) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBeginRenderPass2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdNextSubpass2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEndRenderPass2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetEvent2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdResetEvent2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdWaitEvents2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdPipelineBarrier2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdWriteTimestamp2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyBuffer2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyImage2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyBufferToImage2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyImageToBuffer2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBlitImage2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdResolveImage2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBeginRendering) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEndRendering) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetCullMode) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetFrontFace) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetPrimitiveTopology) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetViewportWithCount) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetScissorWithCount) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindVertexBuffers2) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthTestEnable) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthWriteEnable) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthCompareOp) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthBoundsTestEnable) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetStencilTestEnable) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetStencilOp) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetRasterizerDiscardEnable) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthBiasEnable) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetPrimitiveRestartEnable) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBeginVideoCodingKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEndVideoCodingKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdControlVideoCodingKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDecodeVideoKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBeginRenderingKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEndRenderingKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDeviceMaskKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDispatchBaseKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdPushDescriptorSetKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdPushDescriptorSetWithTemplateKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBeginRenderPass2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdNextSubpass2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEndRenderPass2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawIndirectCountKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawIndexedIndirectCountKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetFragmentShadingRateKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetRenderingAttachmentLocationsKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetRenderingInputAttachmentIndicesKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEncodeVideoKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetEvent2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdResetEvent2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdWaitEvents2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdPipelineBarrier2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdWriteTimestamp2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdWriteBufferMarker2AMD) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyBuffer2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyImage2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyBufferToImage2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyImageToBuffer2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBlitImage2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdResolveImage2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdTraceRaysIndirect2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindIndexBuffer2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetLineStippleKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindDescriptorSets2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdPushConstants2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdPushDescriptorSet2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdPushDescriptorSetWithTemplate2KHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDescriptorBufferOffsets2EXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindDescriptorBufferEmbeddedSamplers2EXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDebugMarkerBeginEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDebugMarkerEndEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDebugMarkerInsertEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindTransformFeedbackBuffersEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBeginTransformFeedbackEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEndTransformFeedbackEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBeginQueryIndexedEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEndQueryIndexedEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawIndirectByteCountEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCuLaunchKernelNVX) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawIndirectCountAMD) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawIndexedIndirectCountAMD) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBeginConditionalRenderingEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEndConditionalRenderingEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetViewportWScalingNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDiscardRectangleEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDiscardRectangleEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDiscardRectangleModeEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBeginDebugUtilsLabelEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdEndDebugUtilsLabelEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdInsertDebugUtilsLabelEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetSampleLocationsEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindShadingRateImageNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetViewportShadingRatePaletteNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetCoarseSampleOrderNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBuildAccelerationStructureNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyAccelerationStructureNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdTraceRaysNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdWriteAccelerationStructuresPropertiesNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdWriteBufferMarkerAMD) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawMeshTasksNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawMeshTasksIndirectNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawMeshTasksIndirectCountNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetExclusiveScissorEnableNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetExclusiveScissorNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetCheckpointNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetPerformanceMarkerINTEL) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetPerformanceStreamMarkerINTEL) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetPerformanceOverrideINTEL) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetLineStippleEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetCullModeEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetFrontFaceEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetPrimitiveTopologyEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetViewportWithCountEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetScissorWithCountEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindVertexBuffers2EXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthTestEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthWriteEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthCompareOpEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthBoundsTestEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetStencilTestEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetStencilOpEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdPreprocessGeneratedCommandsNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdExecuteGeneratedCommandsNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindPipelineShaderGroupNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthBias2EXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCudaLaunchKernelNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindDescriptorBuffersEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDescriptorBufferOffsetsEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindDescriptorBufferEmbeddedSamplersEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetFragmentShadingRateEnumNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetVertexInputEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSubpassShadingHUAWEI) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindInvocationMaskHUAWEI) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetPatchControlPointsEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetRasterizerDiscardEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthBiasEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetLogicOpEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetPrimitiveRestartEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetColorWriteEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawMultiEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawMultiIndexedEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBuildMicromapsEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyMicromapEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyMicromapToMemoryEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyMemoryToMicromapEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdWriteMicromapsPropertiesEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawClusterHUAWEI) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawClusterIndirectHUAWEI) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyMemoryIndirectNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyMemoryToImageIndirectNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDecompressMemoryNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDecompressMemoryIndirectCountNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdUpdatePipelineIndirectBufferNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthClampEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetPolygonModeEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetRasterizationSamplesEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetSampleMaskEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetAlphaToCoverageEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetAlphaToOneEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetLogicOpEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetColorBlendEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetColorBlendEquationEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetColorWriteMaskEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetTessellationDomainOriginEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetRasterizationStreamEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetConservativeRasterizationModeEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetExtraPrimitiveOverestimationSizeEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthClipEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetSampleLocationsEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetColorBlendAdvancedEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetProvokingVertexModeEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetLineRasterizationModeEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetLineStippleEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetDepthClipNegativeOneToOneEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetViewportWScalingEnableNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetViewportSwizzleNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetCoverageToColorEnableNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetCoverageToColorLocationNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetCoverageModulationModeNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetCoverageModulationTableEnableNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetCoverageModulationTableNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetShadingRateImageEnableNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetRepresentativeFragmentTestEnableNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetCoverageReductionModeNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdOpticalFlowExecuteNV) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBindShadersEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetAttachmentFeedbackLoopEnableEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBuildAccelerationStructuresKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdBuildAccelerationStructuresIndirectKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyAccelerationStructureKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyAccelerationStructureToMemoryKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdCopyMemoryToAccelerationStructureKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdWriteAccelerationStructuresPropertiesKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdTraceRaysKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdTraceRaysIndirectKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdSetRayTracingPipelineStackSizeKHR) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawMeshTasksEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawMeshTasksIndirectEXT) \
|
||||
VK_USE_DEVICE_CMD_FUNCTION(vkCmdDrawMeshTasksIndirectCountEXT) \
|
||||
|
||||
#define VK_GLOBAL_FUNCTIONS \
|
||||
VK_USE_GLOBAL_FUNCTION(vkCreateInstance) \
|
||||
VK_USE_GLOBAL_FUNCTION(vkEnumerateInstanceExtensionProperties) \
|
||||
VK_USE_GLOBAL_FUNCTION(vkEnumerateInstanceLayerProperties) \
|
||||
VK_USE_GLOBAL_FUNCTION(vkEnumerateInstanceVersion) \
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "VulkanLogicalDevice.h"
|
||||
|
||||
struct VulkanImageViewCreateInfo : VkImageViewCreateInfo {
|
||||
VulkanImageViewCreateInfo() {
|
||||
this->sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
this->pNext = nullptr;
|
||||
this->flags = 0;
|
||||
}
|
||||
|
||||
static VulkanImageViewCreateInfo image2D(VkImage image, VkFormat format, uint32_t baseMip = 0, uint32_t mipCount = 1, VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT) {
|
||||
VulkanImageViewCreateInfo result;
|
||||
result.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
result.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
result.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
result.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
result.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
result.image = image;
|
||||
result.format = format;
|
||||
result.subresourceRange.baseArrayLayer = 0;
|
||||
result.subresourceRange.layerCount = 1;
|
||||
result.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
result.subresourceRange.baseMipLevel = 0;
|
||||
result.subresourceRange.levelCount = 1;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
class VulkanImageView : public RefCountedObject {
|
||||
public:
|
||||
VulkanImageView(IntrusivePtr<VulkanLogicalDevice> device, VulkanImageViewCreateInfo createInfo):_device(device){
|
||||
if (_device->functions().vkCreateImageView(&createInfo, nullptr, &_native) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create image views!");
|
||||
}
|
||||
}
|
||||
~VulkanImageView() {
|
||||
if(_native != nullptr){
|
||||
_device->functions().vkDestroyImageView(_native, nullptr);
|
||||
}
|
||||
}
|
||||
VkImageView native() const {
|
||||
return _native;
|
||||
}
|
||||
private:
|
||||
IntrusivePtr<VulkanLogicalDevice> _device;
|
||||
VkImageView _native;
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "VulkanInstance.h"
|
||||
|
||||
|
||||
std::vector<PVulkanPhysicalDevice> VulkanInstance::enumeratePhysicalDevices() {
|
||||
auto deviceCount = getPhysicalDeviceCount();
|
||||
std::vector<VkPhysicalDevice> devices(deviceCount);
|
||||
|
||||
if (deviceCount == 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
while (true) {
|
||||
|
||||
auto result = _instanceFunctions.vkEnumeratePhysicalDevices(_instance, &deviceCount, &devices[0]);
|
||||
if (result == VK_INCOMPLETE) {
|
||||
deviceCount = getPhysicalDeviceCount();
|
||||
}
|
||||
else if (result == VK_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Failed to enumerate physical devices");
|
||||
}
|
||||
}
|
||||
devices.resize(deviceCount);
|
||||
|
||||
std::vector<PVulkanPhysicalDevice> result;
|
||||
for (auto& device : devices) {
|
||||
result.push_back(new VulkanPhysicalDevice(this, device));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include "DynamicLibrary.h"
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <memory>
|
||||
#include "VulkanApplicationInfo.h"
|
||||
|
||||
#include "VulkanFunctions.h"
|
||||
#include "VulkanPhysicalDevice.h"
|
||||
#include "VulkanLibrary.h"
|
||||
#include "RefCountedObject.h"
|
||||
#include "VulkanInstanceFunctions.h"
|
||||
|
||||
|
||||
//TODO: manage external and internal instance creation and destroy instance in destructor if created internally
|
||||
class VulkanInstance : public RefCountedObject {
|
||||
public:
|
||||
VulkanInstance(IntrusivePtr<VulkanLibrary> library, VkInstance instance) : _library(library),_instance(instance){
|
||||
_instanceFunctions = VulkanInstanceFunctions([this](const char* name){ return reinterpret_cast<void*>(_library->getInstanceProcAddr(_instance, name)); });
|
||||
|
||||
}
|
||||
|
||||
const VulkanInstanceFunctions& functions() const {
|
||||
return _instanceFunctions;
|
||||
}
|
||||
|
||||
VkInstance vkInstance() const {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
template<typename FunctionPtr, typename = std::enable_if_t<std::is_function_v<std::remove_pointer_t<FunctionPtr>>>>
|
||||
auto getProcAddr(const char* name) const {
|
||||
return reinterpret_cast<FunctionPtr>(_library->getInstanceProcAddr(_instance, name));
|
||||
}
|
||||
|
||||
uint32_t getPhysicalDeviceCount() const {
|
||||
uint32_t count = 0;
|
||||
if (_instanceFunctions.vkEnumeratePhysicalDevices(_instance, &count, nullptr) != VK_SUCCESS) {
|
||||
throw std::runtime_error("Failed to get physical device count");
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
std::vector<IntrusivePtr<VulkanPhysicalDevice>> enumeratePhysicalDevices();
|
||||
|
||||
private:
|
||||
VulkanInstanceFunctions _instanceFunctions;
|
||||
IntrusivePtr<VulkanLibrary> _library;
|
||||
VkInstance _instance = nullptr;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,423 @@
|
||||
#pragma once
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <functional>
|
||||
class VulkanInstanceFunctions {
|
||||
public:
|
||||
VulkanInstanceFunctions(std::function<void*(const char*)> loader){
|
||||
_vkDestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>(loader("vkDestroyInstance"));
|
||||
_vkEnumeratePhysicalDevices = reinterpret_cast<PFN_vkEnumeratePhysicalDevices>(loader("vkEnumeratePhysicalDevices"));
|
||||
_vkGetPhysicalDeviceFeatures = reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures>(loader("vkGetPhysicalDeviceFeatures"));
|
||||
_vkGetPhysicalDeviceFormatProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceFormatProperties>(loader("vkGetPhysicalDeviceFormatProperties"));
|
||||
_vkGetPhysicalDeviceImageFormatProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceImageFormatProperties>(loader("vkGetPhysicalDeviceImageFormatProperties"));
|
||||
_vkGetPhysicalDeviceProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>(loader("vkGetPhysicalDeviceProperties"));
|
||||
_vkGetPhysicalDeviceQueueFamilyProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceQueueFamilyProperties>(loader("vkGetPhysicalDeviceQueueFamilyProperties"));
|
||||
_vkGetPhysicalDeviceMemoryProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(loader("vkGetPhysicalDeviceMemoryProperties"));
|
||||
_vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(loader("vkGetInstanceProcAddr"));
|
||||
_vkGetDeviceProcAddr = reinterpret_cast<PFN_vkGetDeviceProcAddr>(loader("vkGetDeviceProcAddr"));
|
||||
_vkCreateDevice = reinterpret_cast<PFN_vkCreateDevice>(loader("vkCreateDevice"));
|
||||
_vkEnumerateDeviceExtensionProperties = reinterpret_cast<PFN_vkEnumerateDeviceExtensionProperties>(loader("vkEnumerateDeviceExtensionProperties"));
|
||||
_vkEnumerateDeviceLayerProperties = reinterpret_cast<PFN_vkEnumerateDeviceLayerProperties>(loader("vkEnumerateDeviceLayerProperties"));
|
||||
_vkGetPhysicalDeviceSparseImageFormatProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceSparseImageFormatProperties>(loader("vkGetPhysicalDeviceSparseImageFormatProperties"));
|
||||
_vkEnumeratePhysicalDeviceGroups = reinterpret_cast<PFN_vkEnumeratePhysicalDeviceGroups>(loader("vkEnumeratePhysicalDeviceGroups"));
|
||||
_vkGetPhysicalDeviceFeatures2 = reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures2>(loader("vkGetPhysicalDeviceFeatures2"));
|
||||
_vkGetPhysicalDeviceProperties2 = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2>(loader("vkGetPhysicalDeviceProperties2"));
|
||||
_vkGetPhysicalDeviceFormatProperties2 = reinterpret_cast<PFN_vkGetPhysicalDeviceFormatProperties2>(loader("vkGetPhysicalDeviceFormatProperties2"));
|
||||
_vkGetPhysicalDeviceImageFormatProperties2 = reinterpret_cast<PFN_vkGetPhysicalDeviceImageFormatProperties2>(loader("vkGetPhysicalDeviceImageFormatProperties2"));
|
||||
_vkGetPhysicalDeviceQueueFamilyProperties2 = reinterpret_cast<PFN_vkGetPhysicalDeviceQueueFamilyProperties2>(loader("vkGetPhysicalDeviceQueueFamilyProperties2"));
|
||||
_vkGetPhysicalDeviceMemoryProperties2 = reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties2>(loader("vkGetPhysicalDeviceMemoryProperties2"));
|
||||
_vkGetPhysicalDeviceSparseImageFormatProperties2 = reinterpret_cast<PFN_vkGetPhysicalDeviceSparseImageFormatProperties2>(loader("vkGetPhysicalDeviceSparseImageFormatProperties2"));
|
||||
_vkGetPhysicalDeviceExternalBufferProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceExternalBufferProperties>(loader("vkGetPhysicalDeviceExternalBufferProperties"));
|
||||
_vkGetPhysicalDeviceExternalFenceProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceExternalFenceProperties>(loader("vkGetPhysicalDeviceExternalFenceProperties"));
|
||||
_vkGetPhysicalDeviceExternalSemaphoreProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceExternalSemaphoreProperties>(loader("vkGetPhysicalDeviceExternalSemaphoreProperties"));
|
||||
_vkGetPhysicalDeviceToolProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceToolProperties>(loader("vkGetPhysicalDeviceToolProperties"));
|
||||
_vkDestroySurfaceKHR = reinterpret_cast<PFN_vkDestroySurfaceKHR>(loader("vkDestroySurfaceKHR"));
|
||||
_vkGetPhysicalDeviceSurfaceSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceSupportKHR>(loader("vkGetPhysicalDeviceSurfaceSupportKHR"));
|
||||
_vkGetPhysicalDeviceSurfaceCapabilitiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR>(loader("vkGetPhysicalDeviceSurfaceCapabilitiesKHR"));
|
||||
_vkGetPhysicalDeviceSurfaceFormatsKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR>(loader("vkGetPhysicalDeviceSurfaceFormatsKHR"));
|
||||
_vkGetPhysicalDeviceSurfacePresentModesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR>(loader("vkGetPhysicalDeviceSurfacePresentModesKHR"));
|
||||
_vkGetPhysicalDevicePresentRectanglesKHR = reinterpret_cast<PFN_vkGetPhysicalDevicePresentRectanglesKHR>(loader("vkGetPhysicalDevicePresentRectanglesKHR"));
|
||||
_vkGetPhysicalDeviceDisplayPropertiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceDisplayPropertiesKHR>(loader("vkGetPhysicalDeviceDisplayPropertiesKHR"));
|
||||
_vkGetPhysicalDeviceDisplayPlanePropertiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR>(loader("vkGetPhysicalDeviceDisplayPlanePropertiesKHR"));
|
||||
_vkGetDisplayPlaneSupportedDisplaysKHR = reinterpret_cast<PFN_vkGetDisplayPlaneSupportedDisplaysKHR>(loader("vkGetDisplayPlaneSupportedDisplaysKHR"));
|
||||
_vkGetDisplayModePropertiesKHR = reinterpret_cast<PFN_vkGetDisplayModePropertiesKHR>(loader("vkGetDisplayModePropertiesKHR"));
|
||||
_vkCreateDisplayModeKHR = reinterpret_cast<PFN_vkCreateDisplayModeKHR>(loader("vkCreateDisplayModeKHR"));
|
||||
_vkGetDisplayPlaneCapabilitiesKHR = reinterpret_cast<PFN_vkGetDisplayPlaneCapabilitiesKHR>(loader("vkGetDisplayPlaneCapabilitiesKHR"));
|
||||
_vkCreateDisplayPlaneSurfaceKHR = reinterpret_cast<PFN_vkCreateDisplayPlaneSurfaceKHR>(loader("vkCreateDisplayPlaneSurfaceKHR"));
|
||||
_vkGetPhysicalDeviceVideoCapabilitiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceVideoCapabilitiesKHR>(loader("vkGetPhysicalDeviceVideoCapabilitiesKHR"));
|
||||
_vkGetPhysicalDeviceVideoFormatPropertiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceVideoFormatPropertiesKHR>(loader("vkGetPhysicalDeviceVideoFormatPropertiesKHR"));
|
||||
_vkGetPhysicalDeviceFeatures2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures2KHR>(loader("vkGetPhysicalDeviceFeatures2KHR"));
|
||||
_vkGetPhysicalDeviceProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2KHR>(loader("vkGetPhysicalDeviceProperties2KHR"));
|
||||
_vkGetPhysicalDeviceFormatProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceFormatProperties2KHR>(loader("vkGetPhysicalDeviceFormatProperties2KHR"));
|
||||
_vkGetPhysicalDeviceImageFormatProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceImageFormatProperties2KHR>(loader("vkGetPhysicalDeviceImageFormatProperties2KHR"));
|
||||
_vkGetPhysicalDeviceQueueFamilyProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceQueueFamilyProperties2KHR>(loader("vkGetPhysicalDeviceQueueFamilyProperties2KHR"));
|
||||
_vkGetPhysicalDeviceMemoryProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties2KHR>(loader("vkGetPhysicalDeviceMemoryProperties2KHR"));
|
||||
_vkGetPhysicalDeviceSparseImageFormatProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSparseImageFormatProperties2KHR>(loader("vkGetPhysicalDeviceSparseImageFormatProperties2KHR"));
|
||||
_vkEnumeratePhysicalDeviceGroupsKHR = reinterpret_cast<PFN_vkEnumeratePhysicalDeviceGroupsKHR>(loader("vkEnumeratePhysicalDeviceGroupsKHR"));
|
||||
_vkGetPhysicalDeviceExternalBufferPropertiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceExternalBufferPropertiesKHR>(loader("vkGetPhysicalDeviceExternalBufferPropertiesKHR"));
|
||||
_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR>(loader("vkGetPhysicalDeviceExternalSemaphorePropertiesKHR"));
|
||||
_vkGetPhysicalDeviceExternalFencePropertiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR>(loader("vkGetPhysicalDeviceExternalFencePropertiesKHR"));
|
||||
_vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR = reinterpret_cast<PFN_vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR>(loader("vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR"));
|
||||
_vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR>(loader("vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR"));
|
||||
_vkGetPhysicalDeviceSurfaceCapabilities2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR>(loader("vkGetPhysicalDeviceSurfaceCapabilities2KHR"));
|
||||
_vkGetPhysicalDeviceSurfaceFormats2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceFormats2KHR>(loader("vkGetPhysicalDeviceSurfaceFormats2KHR"));
|
||||
_vkGetPhysicalDeviceDisplayProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceDisplayProperties2KHR>(loader("vkGetPhysicalDeviceDisplayProperties2KHR"));
|
||||
_vkGetPhysicalDeviceDisplayPlaneProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceDisplayPlaneProperties2KHR>(loader("vkGetPhysicalDeviceDisplayPlaneProperties2KHR"));
|
||||
_vkGetDisplayModeProperties2KHR = reinterpret_cast<PFN_vkGetDisplayModeProperties2KHR>(loader("vkGetDisplayModeProperties2KHR"));
|
||||
_vkGetDisplayPlaneCapabilities2KHR = reinterpret_cast<PFN_vkGetDisplayPlaneCapabilities2KHR>(loader("vkGetDisplayPlaneCapabilities2KHR"));
|
||||
_vkGetPhysicalDeviceFragmentShadingRatesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceFragmentShadingRatesKHR>(loader("vkGetPhysicalDeviceFragmentShadingRatesKHR"));
|
||||
_vkGetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR>(loader("vkGetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR"));
|
||||
_vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR>(loader("vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR"));
|
||||
_vkGetPhysicalDeviceCalibrateableTimeDomainsKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsKHR>(loader("vkGetPhysicalDeviceCalibrateableTimeDomainsKHR"));
|
||||
_vkCreateDebugReportCallbackEXT = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>(loader("vkCreateDebugReportCallbackEXT"));
|
||||
_vkDestroyDebugReportCallbackEXT = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(loader("vkDestroyDebugReportCallbackEXT"));
|
||||
_vkDebugReportMessageEXT = reinterpret_cast<PFN_vkDebugReportMessageEXT>(loader("vkDebugReportMessageEXT"));
|
||||
_vkGetPhysicalDeviceExternalImageFormatPropertiesNV = reinterpret_cast<PFN_vkGetPhysicalDeviceExternalImageFormatPropertiesNV>(loader("vkGetPhysicalDeviceExternalImageFormatPropertiesNV"));
|
||||
_vkReleaseDisplayEXT = reinterpret_cast<PFN_vkReleaseDisplayEXT>(loader("vkReleaseDisplayEXT"));
|
||||
_vkGetPhysicalDeviceSurfaceCapabilities2EXT = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceCapabilities2EXT>(loader("vkGetPhysicalDeviceSurfaceCapabilities2EXT"));
|
||||
_vkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(loader("vkCreateDebugUtilsMessengerEXT"));
|
||||
_vkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(loader("vkDestroyDebugUtilsMessengerEXT"));
|
||||
_vkSubmitDebugUtilsMessageEXT = reinterpret_cast<PFN_vkSubmitDebugUtilsMessageEXT>(loader("vkSubmitDebugUtilsMessageEXT"));
|
||||
_vkGetPhysicalDeviceMultisamplePropertiesEXT = reinterpret_cast<PFN_vkGetPhysicalDeviceMultisamplePropertiesEXT>(loader("vkGetPhysicalDeviceMultisamplePropertiesEXT"));
|
||||
_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT = reinterpret_cast<PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT>(loader("vkGetPhysicalDeviceCalibrateableTimeDomainsEXT"));
|
||||
_vkGetPhysicalDeviceToolPropertiesEXT = reinterpret_cast<PFN_vkGetPhysicalDeviceToolPropertiesEXT>(loader("vkGetPhysicalDeviceToolPropertiesEXT"));
|
||||
_vkGetPhysicalDeviceCooperativeMatrixPropertiesNV = reinterpret_cast<PFN_vkGetPhysicalDeviceCooperativeMatrixPropertiesNV>(loader("vkGetPhysicalDeviceCooperativeMatrixPropertiesNV"));
|
||||
_vkGetPhysicalDeviceSupportedFramebufferMixedSamplesCombinationsNV = reinterpret_cast<PFN_vkGetPhysicalDeviceSupportedFramebufferMixedSamplesCombinationsNV>(loader("vkGetPhysicalDeviceSupportedFramebufferMixedSamplesCombinationsNV"));
|
||||
_vkCreateHeadlessSurfaceEXT = reinterpret_cast<PFN_vkCreateHeadlessSurfaceEXT>(loader("vkCreateHeadlessSurfaceEXT"));
|
||||
_vkAcquireDrmDisplayEXT = reinterpret_cast<PFN_vkAcquireDrmDisplayEXT>(loader("vkAcquireDrmDisplayEXT"));
|
||||
_vkGetDrmDisplayEXT = reinterpret_cast<PFN_vkGetDrmDisplayEXT>(loader("vkGetDrmDisplayEXT"));
|
||||
_vkGetPhysicalDeviceOpticalFlowImageFormatsNV = reinterpret_cast<PFN_vkGetPhysicalDeviceOpticalFlowImageFormatsNV>(loader("vkGetPhysicalDeviceOpticalFlowImageFormatsNV"));
|
||||
|
||||
}
|
||||
VulkanInstanceFunctions(){}
|
||||
void vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator) const {
|
||||
_vkDestroyInstance(instance, pAllocator);
|
||||
}
|
||||
VkResult vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) const {
|
||||
return _vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
|
||||
}
|
||||
void vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures) const {
|
||||
_vkGetPhysicalDeviceFeatures(physicalDevice, pFeatures);
|
||||
}
|
||||
void vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties) const {
|
||||
_vkGetPhysicalDeviceFormatProperties(physicalDevice, format, pFormatProperties);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties) const {
|
||||
return _vkGetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, pImageFormatProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties) const {
|
||||
_vkGetPhysicalDeviceProperties(physicalDevice, pProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties* pQueueFamilyProperties) const {
|
||||
_vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties) const {
|
||||
_vkGetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
|
||||
}
|
||||
PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance instance, const char* pName) const {
|
||||
return _vkGetInstanceProcAddr(instance, pName);
|
||||
}
|
||||
PFN_vkVoidFunction vkGetDeviceProcAddr(VkDevice device, const char* pName) const {
|
||||
return _vkGetDeviceProcAddr(device, pName);
|
||||
}
|
||||
VkResult vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) const {
|
||||
return _vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
|
||||
}
|
||||
VkResult vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties) const {
|
||||
return _vkEnumerateDeviceExtensionProperties(physicalDevice, pLayerName, pPropertyCount, pProperties);
|
||||
}
|
||||
VkResult vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkLayerProperties* pProperties) const {
|
||||
return _vkEnumerateDeviceLayerProperties(physicalDevice, pPropertyCount, pProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pPropertyCount, VkSparseImageFormatProperties* pProperties) const {
|
||||
_vkGetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, pPropertyCount, pProperties);
|
||||
}
|
||||
VkResult vkEnumeratePhysicalDeviceGroups(VkInstance instance, uint32_t* pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) const {
|
||||
return _vkEnumeratePhysicalDeviceGroups(instance, pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures2* pFeatures) const {
|
||||
_vkGetPhysicalDeviceFeatures2(physicalDevice, pFeatures);
|
||||
}
|
||||
void vkGetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2* pProperties) const {
|
||||
_vkGetPhysicalDeviceProperties2(physicalDevice, pProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties2* pFormatProperties) const {
|
||||
_vkGetPhysicalDeviceFormatProperties2(physicalDevice, format, pFormatProperties);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, VkImageFormatProperties2* pImageFormatProperties) const {
|
||||
return _vkGetPhysicalDeviceImageFormatProperties2(physicalDevice, pImageFormatInfo, pImageFormatProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2* pQueueFamilyProperties) const {
|
||||
_vkGetPhysicalDeviceQueueFamilyProperties2(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceMemoryProperties2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties2* pMemoryProperties) const {
|
||||
_vkGetPhysicalDeviceMemoryProperties2(physicalDevice, pMemoryProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceSparseImageFormatProperties2(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, uint32_t* pPropertyCount, VkSparseImageFormatProperties2* pProperties) const {
|
||||
_vkGetPhysicalDeviceSparseImageFormatProperties2(physicalDevice, pFormatInfo, pPropertyCount, pProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, VkExternalBufferProperties* pExternalBufferProperties) const {
|
||||
_vkGetPhysicalDeviceExternalBufferProperties(physicalDevice, pExternalBufferInfo, pExternalBufferProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceExternalFenceProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, VkExternalFenceProperties* pExternalFenceProperties) const {
|
||||
_vkGetPhysicalDeviceExternalFenceProperties(physicalDevice, pExternalFenceInfo, pExternalFenceProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceExternalSemaphoreProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, VkExternalSemaphoreProperties* pExternalSemaphoreProperties) const {
|
||||
_vkGetPhysicalDeviceExternalSemaphoreProperties(physicalDevice, pExternalSemaphoreInfo, pExternalSemaphoreProperties);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceToolProperties(VkPhysicalDevice physicalDevice, uint32_t* pToolCount, VkPhysicalDeviceToolProperties* pToolProperties) const {
|
||||
return _vkGetPhysicalDeviceToolProperties(physicalDevice, pToolCount, pToolProperties);
|
||||
}
|
||||
void vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator) const {
|
||||
_vkDestroySurfaceKHR(instance, surface, pAllocator);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, VkSurfaceKHR surface, VkBool32* pSupported) const {
|
||||
return _vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, pSupported);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR* pSurfaceCapabilities) const {
|
||||
return _vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, pSurfaceCapabilities);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pSurfaceFormatCount, VkSurfaceFormatKHR* pSurfaceFormats) const {
|
||||
return _vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes) const {
|
||||
return _vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, pPresentModes);
|
||||
}
|
||||
VkResult vkGetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pRectCount, VkRect2D* pRects) const {
|
||||
return _vkGetPhysicalDevicePresentRectanglesKHR(physicalDevice, surface, pRectCount, pRects);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPropertiesKHR* pProperties) const {
|
||||
return _vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, pPropertyCount, pProperties);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPlanePropertiesKHR* pProperties) const {
|
||||
return _vkGetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, pPropertyCount, pProperties);
|
||||
}
|
||||
VkResult vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) const {
|
||||
return _vkGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, pDisplayCount, pDisplays);
|
||||
}
|
||||
VkResult vkGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t* pPropertyCount, VkDisplayModePropertiesKHR* pProperties) const {
|
||||
return _vkGetDisplayModePropertiesKHR(physicalDevice, display, pPropertyCount, pProperties);
|
||||
}
|
||||
VkResult vkCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, const VkDisplayModeCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDisplayModeKHR* pMode) const {
|
||||
return _vkCreateDisplayModeKHR(physicalDevice, display, pCreateInfo, pAllocator, pMode);
|
||||
}
|
||||
VkResult vkGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR* pCapabilities) const {
|
||||
return _vkGetDisplayPlaneCapabilitiesKHR(physicalDevice, mode, planeIndex, pCapabilities);
|
||||
}
|
||||
VkResult vkCreateDisplayPlaneSurfaceKHR(VkInstance instance, const VkDisplaySurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) const {
|
||||
return _vkCreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceVideoCapabilitiesKHR(VkPhysicalDevice physicalDevice, const VkVideoProfileInfoKHR* pVideoProfile, VkVideoCapabilitiesKHR* pCapabilities) const {
|
||||
return _vkGetPhysicalDeviceVideoCapabilitiesKHR(physicalDevice, pVideoProfile, pCapabilities);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceVideoFormatPropertiesKHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceVideoFormatInfoKHR* pVideoFormatInfo, uint32_t* pVideoFormatPropertyCount, VkVideoFormatPropertiesKHR* pVideoFormatProperties) const {
|
||||
return _vkGetPhysicalDeviceVideoFormatPropertiesKHR(physicalDevice, pVideoFormatInfo, pVideoFormatPropertyCount, pVideoFormatProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceFeatures2KHR(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures2* pFeatures) const {
|
||||
_vkGetPhysicalDeviceFeatures2KHR(physicalDevice, pFeatures);
|
||||
}
|
||||
void vkGetPhysicalDeviceProperties2KHR(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2* pProperties) const {
|
||||
_vkGetPhysicalDeviceProperties2KHR(physicalDevice, pProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceFormatProperties2KHR(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties2* pFormatProperties) const {
|
||||
_vkGetPhysicalDeviceFormatProperties2KHR(physicalDevice, format, pFormatProperties);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceImageFormatProperties2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, VkImageFormatProperties2* pImageFormatProperties) const {
|
||||
return _vkGetPhysicalDeviceImageFormatProperties2KHR(physicalDevice, pImageFormatInfo, pImageFormatProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2* pQueueFamilyProperties) const {
|
||||
_vkGetPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceMemoryProperties2KHR(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties2* pMemoryProperties) const {
|
||||
_vkGetPhysicalDeviceMemoryProperties2KHR(physicalDevice, pMemoryProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceSparseImageFormatProperties2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, uint32_t* pPropertyCount, VkSparseImageFormatProperties2* pProperties) const {
|
||||
_vkGetPhysicalDeviceSparseImageFormatProperties2KHR(physicalDevice, pFormatInfo, pPropertyCount, pProperties);
|
||||
}
|
||||
VkResult vkEnumeratePhysicalDeviceGroupsKHR(VkInstance instance, uint32_t* pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) const {
|
||||
return _vkEnumeratePhysicalDeviceGroupsKHR(instance, pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceExternalBufferPropertiesKHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, VkExternalBufferProperties* pExternalBufferProperties) const {
|
||||
_vkGetPhysicalDeviceExternalBufferPropertiesKHR(physicalDevice, pExternalBufferInfo, pExternalBufferProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, VkExternalSemaphoreProperties* pExternalSemaphoreProperties) const {
|
||||
_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(physicalDevice, pExternalSemaphoreInfo, pExternalSemaphoreProperties);
|
||||
}
|
||||
void vkGetPhysicalDeviceExternalFencePropertiesKHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, VkExternalFenceProperties* pExternalFenceProperties) const {
|
||||
_vkGetPhysicalDeviceExternalFencePropertiesKHR(physicalDevice, pExternalFenceInfo, pExternalFenceProperties);
|
||||
}
|
||||
VkResult vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t* pCounterCount, VkPerformanceCounterKHR* pCounters, VkPerformanceCounterDescriptionKHR* pCounterDescriptions) const {
|
||||
return _vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(physicalDevice, queueFamilyIndex, pCounterCount, pCounters, pCounterDescriptions);
|
||||
}
|
||||
void vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(VkPhysicalDevice physicalDevice, const VkQueryPoolPerformanceCreateInfoKHR* pPerformanceQueryCreateInfo, uint32_t* pNumPasses) const {
|
||||
_vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physicalDevice, pPerformanceQueryCreateInfo, pNumPasses);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, VkSurfaceCapabilities2KHR* pSurfaceCapabilities) const {
|
||||
return _vkGetPhysicalDeviceSurfaceCapabilities2KHR(physicalDevice, pSurfaceInfo, pSurfaceCapabilities);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, uint32_t* pSurfaceFormatCount, VkSurfaceFormat2KHR* pSurfaceFormats) const {
|
||||
return _vkGetPhysicalDeviceSurfaceFormats2KHR(physicalDevice, pSurfaceInfo, pSurfaceFormatCount, pSurfaceFormats);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayProperties2KHR* pProperties) const {
|
||||
return _vkGetPhysicalDeviceDisplayProperties2KHR(physicalDevice, pPropertyCount, pProperties);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPlaneProperties2KHR* pProperties) const {
|
||||
return _vkGetPhysicalDeviceDisplayPlaneProperties2KHR(physicalDevice, pPropertyCount, pProperties);
|
||||
}
|
||||
VkResult vkGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t* pPropertyCount, VkDisplayModeProperties2KHR* pProperties) const {
|
||||
return _vkGetDisplayModeProperties2KHR(physicalDevice, display, pPropertyCount, pProperties);
|
||||
}
|
||||
VkResult vkGetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice, const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo, VkDisplayPlaneCapabilities2KHR* pCapabilities) const {
|
||||
return _vkGetDisplayPlaneCapabilities2KHR(physicalDevice, pDisplayPlaneInfo, pCapabilities);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceFragmentShadingRatesKHR(VkPhysicalDevice physicalDevice, uint32_t* pFragmentShadingRateCount, VkPhysicalDeviceFragmentShadingRateKHR* pFragmentShadingRates) const {
|
||||
return _vkGetPhysicalDeviceFragmentShadingRatesKHR(physicalDevice, pFragmentShadingRateCount, pFragmentShadingRates);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceVideoEncodeQualityLevelInfoKHR* pQualityLevelInfo, VkVideoEncodeQualityLevelPropertiesKHR* pQualityLevelProperties) const {
|
||||
return _vkGetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR(physicalDevice, pQualityLevelInfo, pQualityLevelProperties);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkCooperativeMatrixPropertiesKHR* pProperties) const {
|
||||
return _vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR(physicalDevice, pPropertyCount, pProperties);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceCalibrateableTimeDomainsKHR(VkPhysicalDevice physicalDevice, uint32_t* pTimeDomainCount, VkTimeDomainKHR* pTimeDomains) const {
|
||||
return _vkGetPhysicalDeviceCalibrateableTimeDomainsKHR(physicalDevice, pTimeDomainCount, pTimeDomains);
|
||||
}
|
||||
VkResult vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback) const {
|
||||
return _vkCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);
|
||||
}
|
||||
void vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator) const {
|
||||
_vkDestroyDebugReportCallbackEXT(instance, callback, pAllocator);
|
||||
}
|
||||
void vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage) const {
|
||||
_vkDebugReportMessageEXT(instance, flags, objectType, object, location, messageCode, pLayerPrefix, pMessage);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceExternalImageFormatPropertiesNV(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkExternalMemoryHandleTypeFlagsNV externalHandleType, VkExternalImageFormatPropertiesNV* pExternalImageFormatProperties) const {
|
||||
return _vkGetPhysicalDeviceExternalImageFormatPropertiesNV(physicalDevice, format, type, tiling, usage, flags, externalHandleType, pExternalImageFormatProperties);
|
||||
}
|
||||
VkResult vkReleaseDisplayEXT(VkPhysicalDevice physicalDevice, VkDisplayKHR display) const {
|
||||
return _vkReleaseDisplayEXT(physicalDevice, display);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilities2EXT* pSurfaceCapabilities) const {
|
||||
return _vkGetPhysicalDeviceSurfaceCapabilities2EXT(physicalDevice, surface, pSurfaceCapabilities);
|
||||
}
|
||||
VkResult vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger) const {
|
||||
return _vkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
|
||||
}
|
||||
void vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, const VkAllocationCallbacks* pAllocator) const {
|
||||
_vkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
|
||||
}
|
||||
void vkSubmitDebugUtilsMessageEXT(VkInstance instance, VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData) const {
|
||||
_vkSubmitDebugUtilsMessageEXT(instance, messageSeverity, messageTypes, pCallbackData);
|
||||
}
|
||||
void vkGetPhysicalDeviceMultisamplePropertiesEXT(VkPhysicalDevice physicalDevice, VkSampleCountFlagBits samples, VkMultisamplePropertiesEXT* pMultisampleProperties) const {
|
||||
_vkGetPhysicalDeviceMultisamplePropertiesEXT(physicalDevice, samples, pMultisampleProperties);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(VkPhysicalDevice physicalDevice, uint32_t* pTimeDomainCount, VkTimeDomainKHR* pTimeDomains) const {
|
||||
return _vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(physicalDevice, pTimeDomainCount, pTimeDomains);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceToolPropertiesEXT(VkPhysicalDevice physicalDevice, uint32_t* pToolCount, VkPhysicalDeviceToolProperties* pToolProperties) const {
|
||||
return _vkGetPhysicalDeviceToolPropertiesEXT(physicalDevice, pToolCount, pToolProperties);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceCooperativeMatrixPropertiesNV(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkCooperativeMatrixPropertiesNV* pProperties) const {
|
||||
return _vkGetPhysicalDeviceCooperativeMatrixPropertiesNV(physicalDevice, pPropertyCount, pProperties);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceSupportedFramebufferMixedSamplesCombinationsNV(VkPhysicalDevice physicalDevice, uint32_t* pCombinationCount, VkFramebufferMixedSamplesCombinationNV* pCombinations) const {
|
||||
return _vkGetPhysicalDeviceSupportedFramebufferMixedSamplesCombinationsNV(physicalDevice, pCombinationCount, pCombinations);
|
||||
}
|
||||
VkResult vkCreateHeadlessSurfaceEXT(VkInstance instance, const VkHeadlessSurfaceCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) const {
|
||||
return _vkCreateHeadlessSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
|
||||
}
|
||||
VkResult vkAcquireDrmDisplayEXT(VkPhysicalDevice physicalDevice, int32_t drmFd, VkDisplayKHR display) const {
|
||||
return _vkAcquireDrmDisplayEXT(physicalDevice, drmFd, display);
|
||||
}
|
||||
VkResult vkGetDrmDisplayEXT(VkPhysicalDevice physicalDevice, int32_t drmFd, uint32_t connectorId, VkDisplayKHR* display) const {
|
||||
return _vkGetDrmDisplayEXT(physicalDevice, drmFd, connectorId, display);
|
||||
}
|
||||
VkResult vkGetPhysicalDeviceOpticalFlowImageFormatsNV(VkPhysicalDevice physicalDevice, const VkOpticalFlowImageFormatInfoNV* pOpticalFlowImageFormatInfo, uint32_t* pFormatCount, VkOpticalFlowImageFormatPropertiesNV* pImageFormatProperties) const {
|
||||
return _vkGetPhysicalDeviceOpticalFlowImageFormatsNV(physicalDevice, pOpticalFlowImageFormatInfo, pFormatCount, pImageFormatProperties);
|
||||
}
|
||||
|
||||
private:
|
||||
PFN_vkDestroyInstance _vkDestroyInstance;
|
||||
PFN_vkEnumeratePhysicalDevices _vkEnumeratePhysicalDevices;
|
||||
PFN_vkGetPhysicalDeviceFeatures _vkGetPhysicalDeviceFeatures;
|
||||
PFN_vkGetPhysicalDeviceFormatProperties _vkGetPhysicalDeviceFormatProperties;
|
||||
PFN_vkGetPhysicalDeviceImageFormatProperties _vkGetPhysicalDeviceImageFormatProperties;
|
||||
PFN_vkGetPhysicalDeviceProperties _vkGetPhysicalDeviceProperties;
|
||||
PFN_vkGetPhysicalDeviceQueueFamilyProperties _vkGetPhysicalDeviceQueueFamilyProperties;
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties _vkGetPhysicalDeviceMemoryProperties;
|
||||
PFN_vkGetInstanceProcAddr _vkGetInstanceProcAddr;
|
||||
PFN_vkGetDeviceProcAddr _vkGetDeviceProcAddr;
|
||||
PFN_vkCreateDevice _vkCreateDevice;
|
||||
PFN_vkEnumerateDeviceExtensionProperties _vkEnumerateDeviceExtensionProperties;
|
||||
PFN_vkEnumerateDeviceLayerProperties _vkEnumerateDeviceLayerProperties;
|
||||
PFN_vkGetPhysicalDeviceSparseImageFormatProperties _vkGetPhysicalDeviceSparseImageFormatProperties;
|
||||
PFN_vkEnumeratePhysicalDeviceGroups _vkEnumeratePhysicalDeviceGroups;
|
||||
PFN_vkGetPhysicalDeviceFeatures2 _vkGetPhysicalDeviceFeatures2;
|
||||
PFN_vkGetPhysicalDeviceProperties2 _vkGetPhysicalDeviceProperties2;
|
||||
PFN_vkGetPhysicalDeviceFormatProperties2 _vkGetPhysicalDeviceFormatProperties2;
|
||||
PFN_vkGetPhysicalDeviceImageFormatProperties2 _vkGetPhysicalDeviceImageFormatProperties2;
|
||||
PFN_vkGetPhysicalDeviceQueueFamilyProperties2 _vkGetPhysicalDeviceQueueFamilyProperties2;
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties2 _vkGetPhysicalDeviceMemoryProperties2;
|
||||
PFN_vkGetPhysicalDeviceSparseImageFormatProperties2 _vkGetPhysicalDeviceSparseImageFormatProperties2;
|
||||
PFN_vkGetPhysicalDeviceExternalBufferProperties _vkGetPhysicalDeviceExternalBufferProperties;
|
||||
PFN_vkGetPhysicalDeviceExternalFenceProperties _vkGetPhysicalDeviceExternalFenceProperties;
|
||||
PFN_vkGetPhysicalDeviceExternalSemaphoreProperties _vkGetPhysicalDeviceExternalSemaphoreProperties;
|
||||
PFN_vkGetPhysicalDeviceToolProperties _vkGetPhysicalDeviceToolProperties;
|
||||
PFN_vkDestroySurfaceKHR _vkDestroySurfaceKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceSupportKHR _vkGetPhysicalDeviceSurfaceSupportKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR _vkGetPhysicalDeviceSurfaceCapabilitiesKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR _vkGetPhysicalDeviceSurfaceFormatsKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR _vkGetPhysicalDeviceSurfacePresentModesKHR;
|
||||
PFN_vkGetPhysicalDevicePresentRectanglesKHR _vkGetPhysicalDevicePresentRectanglesKHR;
|
||||
PFN_vkGetPhysicalDeviceDisplayPropertiesKHR _vkGetPhysicalDeviceDisplayPropertiesKHR;
|
||||
PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR _vkGetPhysicalDeviceDisplayPlanePropertiesKHR;
|
||||
PFN_vkGetDisplayPlaneSupportedDisplaysKHR _vkGetDisplayPlaneSupportedDisplaysKHR;
|
||||
PFN_vkGetDisplayModePropertiesKHR _vkGetDisplayModePropertiesKHR;
|
||||
PFN_vkCreateDisplayModeKHR _vkCreateDisplayModeKHR;
|
||||
PFN_vkGetDisplayPlaneCapabilitiesKHR _vkGetDisplayPlaneCapabilitiesKHR;
|
||||
PFN_vkCreateDisplayPlaneSurfaceKHR _vkCreateDisplayPlaneSurfaceKHR;
|
||||
PFN_vkGetPhysicalDeviceVideoCapabilitiesKHR _vkGetPhysicalDeviceVideoCapabilitiesKHR;
|
||||
PFN_vkGetPhysicalDeviceVideoFormatPropertiesKHR _vkGetPhysicalDeviceVideoFormatPropertiesKHR;
|
||||
PFN_vkGetPhysicalDeviceFeatures2KHR _vkGetPhysicalDeviceFeatures2KHR;
|
||||
PFN_vkGetPhysicalDeviceProperties2KHR _vkGetPhysicalDeviceProperties2KHR;
|
||||
PFN_vkGetPhysicalDeviceFormatProperties2KHR _vkGetPhysicalDeviceFormatProperties2KHR;
|
||||
PFN_vkGetPhysicalDeviceImageFormatProperties2KHR _vkGetPhysicalDeviceImageFormatProperties2KHR;
|
||||
PFN_vkGetPhysicalDeviceQueueFamilyProperties2KHR _vkGetPhysicalDeviceQueueFamilyProperties2KHR;
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties2KHR _vkGetPhysicalDeviceMemoryProperties2KHR;
|
||||
PFN_vkGetPhysicalDeviceSparseImageFormatProperties2KHR _vkGetPhysicalDeviceSparseImageFormatProperties2KHR;
|
||||
PFN_vkEnumeratePhysicalDeviceGroupsKHR _vkEnumeratePhysicalDeviceGroupsKHR;
|
||||
PFN_vkGetPhysicalDeviceExternalBufferPropertiesKHR _vkGetPhysicalDeviceExternalBufferPropertiesKHR;
|
||||
PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR _vkGetPhysicalDeviceExternalSemaphorePropertiesKHR;
|
||||
PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR _vkGetPhysicalDeviceExternalFencePropertiesKHR;
|
||||
PFN_vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR _vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR;
|
||||
PFN_vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR _vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR _vkGetPhysicalDeviceSurfaceCapabilities2KHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceFormats2KHR _vkGetPhysicalDeviceSurfaceFormats2KHR;
|
||||
PFN_vkGetPhysicalDeviceDisplayProperties2KHR _vkGetPhysicalDeviceDisplayProperties2KHR;
|
||||
PFN_vkGetPhysicalDeviceDisplayPlaneProperties2KHR _vkGetPhysicalDeviceDisplayPlaneProperties2KHR;
|
||||
PFN_vkGetDisplayModeProperties2KHR _vkGetDisplayModeProperties2KHR;
|
||||
PFN_vkGetDisplayPlaneCapabilities2KHR _vkGetDisplayPlaneCapabilities2KHR;
|
||||
PFN_vkGetPhysicalDeviceFragmentShadingRatesKHR _vkGetPhysicalDeviceFragmentShadingRatesKHR;
|
||||
PFN_vkGetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR _vkGetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR;
|
||||
PFN_vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR _vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR;
|
||||
PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsKHR _vkGetPhysicalDeviceCalibrateableTimeDomainsKHR;
|
||||
PFN_vkCreateDebugReportCallbackEXT _vkCreateDebugReportCallbackEXT;
|
||||
PFN_vkDestroyDebugReportCallbackEXT _vkDestroyDebugReportCallbackEXT;
|
||||
PFN_vkDebugReportMessageEXT _vkDebugReportMessageEXT;
|
||||
PFN_vkGetPhysicalDeviceExternalImageFormatPropertiesNV _vkGetPhysicalDeviceExternalImageFormatPropertiesNV;
|
||||
PFN_vkReleaseDisplayEXT _vkReleaseDisplayEXT;
|
||||
PFN_vkGetPhysicalDeviceSurfaceCapabilities2EXT _vkGetPhysicalDeviceSurfaceCapabilities2EXT;
|
||||
PFN_vkCreateDebugUtilsMessengerEXT _vkCreateDebugUtilsMessengerEXT;
|
||||
PFN_vkDestroyDebugUtilsMessengerEXT _vkDestroyDebugUtilsMessengerEXT;
|
||||
PFN_vkSubmitDebugUtilsMessageEXT _vkSubmitDebugUtilsMessageEXT;
|
||||
PFN_vkGetPhysicalDeviceMultisamplePropertiesEXT _vkGetPhysicalDeviceMultisamplePropertiesEXT;
|
||||
PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT _vkGetPhysicalDeviceCalibrateableTimeDomainsEXT;
|
||||
PFN_vkGetPhysicalDeviceToolPropertiesEXT _vkGetPhysicalDeviceToolPropertiesEXT;
|
||||
PFN_vkGetPhysicalDeviceCooperativeMatrixPropertiesNV _vkGetPhysicalDeviceCooperativeMatrixPropertiesNV;
|
||||
PFN_vkGetPhysicalDeviceSupportedFramebufferMixedSamplesCombinationsNV _vkGetPhysicalDeviceSupportedFramebufferMixedSamplesCombinationsNV;
|
||||
PFN_vkCreateHeadlessSurfaceEXT _vkCreateHeadlessSurfaceEXT;
|
||||
PFN_vkAcquireDrmDisplayEXT _vkAcquireDrmDisplayEXT;
|
||||
PFN_vkGetDrmDisplayEXT _vkGetDrmDisplayEXT;
|
||||
PFN_vkGetPhysicalDeviceOpticalFlowImageFormatsNV _vkGetPhysicalDeviceOpticalFlowImageFormatsNV;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "VulkanLibrary.h"
|
||||
#include "VulkanInstance.h"
|
||||
|
||||
IntrusivePtr<VulkanInstance> VulkanLibrary::createInstance(const VulkanApplicationInfo& info, VkInstanceCreateFlags flags, const std::vector<std::string>& layers, const std::vector<std::string>& extensions, VkAllocationCallbacks* allocCallbacks) {
|
||||
|
||||
std::vector<const char*> _extensions;
|
||||
for (auto& ext : extensions) {
|
||||
_extensions.push_back(ext.c_str());
|
||||
}
|
||||
|
||||
std::vector<const char*> _layers;
|
||||
for (auto& layer : layers) {
|
||||
_layers.push_back(layer.c_str());
|
||||
}
|
||||
|
||||
VkInstanceCreateInfo instance_create_info = {
|
||||
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
&info,
|
||||
static_cast<uint32_t>(_layers.size()),
|
||||
(_layers.size() == 0 ? nullptr : &_layers[0]),
|
||||
static_cast<uint32_t>(_extensions.size()),
|
||||
(_extensions.size() == 0 ? nullptr : &_extensions[0])
|
||||
};
|
||||
|
||||
VkInstance instance;
|
||||
if (_functions.vkCreateInstance(&instance_create_info, allocCallbacks, &instance) != VK_SUCCESS) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new VulkanInstance(this, instance);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "VulkanFunctions.h"
|
||||
#include "VulkanCommon.h"
|
||||
#include "VulkanApplicationInfo.h"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "RefCountedObject.h"
|
||||
|
||||
class VulkanInstance;
|
||||
|
||||
class VulkanGlobalFunctions {
|
||||
public:
|
||||
#define VK_USE_GLOBAL_FUNCTION(name) PFN_##name name;
|
||||
VK_GLOBAL_FUNCTIONS
|
||||
#undef VK_USE_GLOBAL_FUNCTION
|
||||
};
|
||||
|
||||
class VulkanLibrary : public RefCountedObject {
|
||||
public:
|
||||
VulkanLibrary() {
|
||||
|
||||
}
|
||||
|
||||
const VulkanGlobalFunctions& functions() const {
|
||||
return _functions;
|
||||
}
|
||||
|
||||
std::vector<VkExtensionProperties> getSupportedExtensions(const char* layerName = nullptr) const {
|
||||
uint32_t count = 0;
|
||||
if ((_functions.vkEnumerateInstanceExtensionProperties(layerName, &count, nullptr) != VK_SUCCESS)) {
|
||||
throw std::runtime_error("Failed to enumerate extensions");
|
||||
}
|
||||
|
||||
std::vector<VkExtensionProperties> result(count);
|
||||
if ((_functions.vkEnumerateInstanceExtensionProperties(layerName, &count, &result[0]) != VK_SUCCESS)) {
|
||||
throw std::runtime_error("Failed to enumerate extensions");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<VkLayerProperties> getSupportedLayers() const {
|
||||
uint32_t count = 0;
|
||||
if ((_functions.vkEnumerateInstanceLayerProperties(&count, nullptr) != VK_SUCCESS)) {
|
||||
throw std::runtime_error("Failed to enumerate layers");
|
||||
}
|
||||
|
||||
std::vector<VkLayerProperties> result(count);
|
||||
if ((_functions.vkEnumerateInstanceLayerProperties(&count, &result[0]) != VK_SUCCESS)) {
|
||||
throw std::runtime_error("Failed to enumerate layers");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
IntrusivePtr<VulkanInstance> createInstance(const VulkanApplicationInfo& info, VkInstanceCreateFlags flags, const std::vector<std::string>& layers, const std::vector<std::string>& extensions, VkAllocationCallbacks* allocCallbacks = nullptr);
|
||||
|
||||
PFN_vkGetInstanceProcAddr getInstanceProcAddr;
|
||||
protected:
|
||||
VulkanGlobalFunctions _functions;
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user