First runnable render loop
This commit is contained in:
@@ -146,7 +146,7 @@ VertexStreamComponent createVertexStream(uint32 size, aiVector2D* sourceData, Gf
|
||||
Gfx::PVertexBuffer vertexBuffer = graphics->createVertexBuffer(vbInfo);
|
||||
return VertexStreamComponent(vertexBuffer, 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32_SFLOAT);
|
||||
}
|
||||
void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, Array<PMaterialAsset> materials, Gfx::PGraphics graphics)
|
||||
void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, const Array<PMaterialAsset>& materials, Gfx::PGraphics graphics)
|
||||
{
|
||||
for (uint32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex)
|
||||
{
|
||||
@@ -176,7 +176,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMesh
|
||||
{
|
||||
//data.colorComponent = createVertexStream(mesh->mNumVertices, mesh->mColors[0], graphics);
|
||||
}
|
||||
vertexShaderInput->setData(data);
|
||||
vertexShaderInput->setData(std::move(data));
|
||||
vertexShaderInput->init(graphics);
|
||||
|
||||
Array<uint32> indices(mesh->mNumFaces * 3);
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
private:
|
||||
void loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials, Gfx::PGraphics graphics);
|
||||
void loadTextures(const aiScene* scene, Gfx::PGraphics graphics, const std::filesystem::path& meshPath);
|
||||
void loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, Array<PMaterialAsset> materials, Gfx::PGraphics graphics);
|
||||
void loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, const Array<PMaterialAsset>& materials, Gfx::PGraphics graphics);
|
||||
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels);
|
||||
|
||||
void import(const std::filesystem::path& path);
|
||||
|
||||
@@ -54,8 +54,8 @@ namespace Seele
|
||||
{
|
||||
_data = new T[other.allocated];
|
||||
assert(_data != nullptr);
|
||||
std::memcpy(_data, other._data, sizeof(T) * allocated);
|
||||
refreshIterators();
|
||||
std::copy(other.begin(), other.end(), beginIt);
|
||||
}
|
||||
Array(Array &&other) noexcept
|
||||
: allocated(std::move(other.allocated)), arraySize(std::move(other.arraySize))
|
||||
@@ -68,7 +68,7 @@ namespace Seele
|
||||
}
|
||||
Array &operator=(const Array &other) noexcept
|
||||
{
|
||||
if (*this != other)
|
||||
if (this != &other)
|
||||
{
|
||||
if (_data != nullptr)
|
||||
{
|
||||
@@ -77,14 +77,14 @@ namespace Seele
|
||||
allocated = other.allocated;
|
||||
arraySize = other.arraySize;
|
||||
_data = new T[other.allocated];
|
||||
std::memcpy(_data, other._data, sizeof(T) * allocated);
|
||||
refreshIterators();
|
||||
std::copy(other.begin(), other.end(), beginIt);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
Array &operator=(Array &&other) noexcept
|
||||
{
|
||||
if (*this != other)
|
||||
if (this != &other)
|
||||
{
|
||||
if (_data != nullptr)
|
||||
{
|
||||
@@ -94,6 +94,7 @@ namespace Seele
|
||||
arraySize = std::move(other.arraySize);
|
||||
_data = other._data;
|
||||
other._data = nullptr;
|
||||
refreshIterators();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,64 @@ public:
|
||||
tail = nullptr;
|
||||
beginIt = Iterator(root);
|
||||
endIt = Iterator(tail);
|
||||
size = 0;
|
||||
_size = 0;
|
||||
}
|
||||
List(const List& other)
|
||||
{
|
||||
//TODO: improve
|
||||
for(const auto& it : other)
|
||||
{
|
||||
add(it);
|
||||
}
|
||||
}
|
||||
List(List&& other)
|
||||
: root(std::move(other.root))
|
||||
, tail(std::move(other.tail))
|
||||
, beginIt(std::move(other.beginIt))
|
||||
, endIt(std::move(other.endIt))
|
||||
, _size(std::move(other._size))
|
||||
{
|
||||
}
|
||||
~List()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
List& operator=(const List& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
delete root;
|
||||
}
|
||||
if(tail != nullptr)
|
||||
{
|
||||
delete tail;
|
||||
}
|
||||
_size = 0;
|
||||
for(const auto& it : other)
|
||||
{
|
||||
add(it);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
List& operator=(List&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
root = other.root;
|
||||
tail = other.tail;
|
||||
beginIt = other.beginIt;
|
||||
endIt = other.endIt;
|
||||
_size = other._size;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename X>
|
||||
class IteratorBase
|
||||
{
|
||||
@@ -44,6 +96,29 @@ public:
|
||||
: node(i.node)
|
||||
{
|
||||
}
|
||||
IteratorBase(IteratorBase&& i)
|
||||
: node(std::move(i.node))
|
||||
{
|
||||
}
|
||||
~IteratorBase()
|
||||
{
|
||||
}
|
||||
IteratorBase& operator=(const IteratorBase& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = other.node;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
IteratorBase& operator=(IteratorBase&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = std::move(other.node);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
reference operator*() const
|
||||
{
|
||||
return node->data;
|
||||
@@ -129,7 +204,7 @@ public:
|
||||
Iterator insertedElement(tail);
|
||||
tail = newTail;
|
||||
refreshIterators();
|
||||
size++;
|
||||
_size++;
|
||||
return insertedElement;
|
||||
}
|
||||
Iterator add(T&& value)
|
||||
@@ -147,12 +222,12 @@ public:
|
||||
Iterator insertedElement(tail);
|
||||
tail = newTail;
|
||||
refreshIterators();
|
||||
size++;
|
||||
_size++;
|
||||
return insertedElement;
|
||||
}
|
||||
Iterator remove(Iterator pos)
|
||||
{
|
||||
size--;
|
||||
_size--;
|
||||
Node *prev = pos.node->prev;
|
||||
Node *next = pos.node->next;
|
||||
if (prev == nullptr)
|
||||
@@ -177,7 +252,7 @@ public:
|
||||
}
|
||||
Iterator insert(Iterator pos, const T &value)
|
||||
{
|
||||
size++;
|
||||
_size++;
|
||||
if (root == nullptr)
|
||||
{
|
||||
root = new Node();
|
||||
@@ -212,20 +287,28 @@ public:
|
||||
}
|
||||
bool empty()
|
||||
{
|
||||
return size == 0;
|
||||
return _size == 0;
|
||||
}
|
||||
uint32 length()
|
||||
uint32 size()
|
||||
{
|
||||
return size;
|
||||
return _size;
|
||||
}
|
||||
Iterator begin()
|
||||
{
|
||||
return beginIt;
|
||||
}
|
||||
const Iterator begin() const
|
||||
{
|
||||
return beginIt;
|
||||
}
|
||||
Iterator end()
|
||||
{
|
||||
return endIt;
|
||||
}
|
||||
const Iterator end() const
|
||||
{
|
||||
return endIt;
|
||||
}
|
||||
|
||||
private:
|
||||
void refreshIterators()
|
||||
@@ -237,6 +320,6 @@ private:
|
||||
Node *tail;
|
||||
Iterator beginIt;
|
||||
Iterator endIt;
|
||||
uint32 size;
|
||||
uint32 _size;
|
||||
};
|
||||
} // namespace Seele
|
||||
+117
-2
@@ -27,12 +27,28 @@ private:
|
||||
Pair<K, V> pair;
|
||||
Node *leftChild;
|
||||
Node *rightChild;
|
||||
Node()
|
||||
: leftChild(nullptr), rightChild(nullptr), pair(K(), V())
|
||||
{
|
||||
}
|
||||
Node(const K &key)
|
||||
: leftChild(nullptr), rightChild(nullptr), pair(key, V())
|
||||
{
|
||||
}
|
||||
Node()
|
||||
: leftChild(nullptr), rightChild(nullptr), pair(K(), V())
|
||||
Node(const Node& other)
|
||||
: pair(other.pair.key, other.pair.value)
|
||||
{
|
||||
if(other.leftChild != nullptr)
|
||||
{
|
||||
leftChild = new Node(*other.leftChild);
|
||||
}
|
||||
if(other.rightChild != nullptr)
|
||||
{
|
||||
rightChild = new Node(*other.rightChild);
|
||||
}
|
||||
}
|
||||
Node(Node&& other)
|
||||
: leftChild(std::move(other.leftChild)), rightChild(std::move(other.rightChild))
|
||||
{
|
||||
}
|
||||
~Node()
|
||||
@@ -46,6 +62,45 @@ private:
|
||||
delete rightChild;
|
||||
}
|
||||
}
|
||||
Node& operator=(const Node& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(leftChild != nullptr)
|
||||
{
|
||||
delete leftChild;
|
||||
}
|
||||
if(rightChild != nullptr)
|
||||
{
|
||||
delete rightChild;
|
||||
}
|
||||
if(other.leftChild != nullptr)
|
||||
{
|
||||
leftChild = new Node(*other.leftChild);
|
||||
}
|
||||
if(other.rightChild != nullptr)
|
||||
{
|
||||
rightChild = new Node(*other.rightChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
Node& operator=(Node&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(leftChild != nullptr)
|
||||
{
|
||||
delete leftChild;
|
||||
}
|
||||
if(rightChild != nullptr)
|
||||
{
|
||||
delete rightChild;
|
||||
}
|
||||
leftChild = std::move(other.leftChild);
|
||||
rightChild = std::move(other.rightChild);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -53,10 +108,48 @@ public:
|
||||
: root(nullptr), _size(0)
|
||||
{
|
||||
}
|
||||
Map(const Map& other)
|
||||
: root(new Node(*other.root)), _size(other._size)
|
||||
{
|
||||
refreshIterators();
|
||||
}
|
||||
Map(Map&& other)
|
||||
: root(std::move(other.root)), _size(other._size)
|
||||
{
|
||||
refreshIterators();
|
||||
}
|
||||
~Map()
|
||||
{
|
||||
delete root;
|
||||
}
|
||||
Map& operator=(const Map& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
delete root;
|
||||
}
|
||||
root = new Node(*other.root);
|
||||
_size = other.size;
|
||||
refreshIterators();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
Map& operator=(Map&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
delete root;
|
||||
}
|
||||
root = new Node(std::move(*other.root));
|
||||
_size = std::move(other._size);
|
||||
refreshIterators();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
@@ -78,6 +171,28 @@ public:
|
||||
: node(i.node), traversal(i.traversal)
|
||||
{
|
||||
}
|
||||
Iterator(Iterator&& i)
|
||||
: node(std::move(i.node)), traversal(std::move(i.traversal))
|
||||
{
|
||||
}
|
||||
Iterator& operator=(const Iterator& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = other.node; // No copy, since no ownership
|
||||
traversal = other.traversal;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
Iterator& operator=(Iterator&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = std::move(other.node);
|
||||
traversal = std::move(other.traversal);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
reference operator*() const
|
||||
{
|
||||
return node->pair;
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#include "MeshBatch.h"
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#define ENABLE_VALIDATION
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifndef ENABLE_VALIDATION
|
||||
#define ENABLE_VALIDATION 0
|
||||
#endif
|
||||
|
||||
namespace Seele
|
||||
@@ -483,7 +483,7 @@ public:
|
||||
virtual void setViewport(Gfx::PViewport viewport) = 0;
|
||||
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) = 0;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set) = 0;
|
||||
virtual void bindDescriptor(Array<Gfx::PDescriptorSet> sets) = 0;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) = 0;
|
||||
virtual void bindVertexBuffer(const Array<VertexInputStream>& streams) = 0;
|
||||
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) = 0;
|
||||
virtual void draw(const MeshBatchElement& data) = 0;
|
||||
|
||||
@@ -10,6 +10,7 @@ BasePassMeshProcessor::BasePassMeshProcessor(const PScene scene, Gfx::PViewport
|
||||
: MeshProcessor(scene, graphics)
|
||||
, target(viewport)
|
||||
, translucentBasePass(translucentBasePass)
|
||||
, cachedPrimitiveIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -23,7 +24,7 @@ void BasePassMeshProcessor::addMeshBatch(
|
||||
const Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
Array<Gfx::PDescriptorSet>& descriptorSets,
|
||||
int32 staticMeshId)
|
||||
{
|
||||
const PMaterialAsset material = batch.material;
|
||||
@@ -42,13 +43,12 @@ void BasePassMeshProcessor::addMeshBatch(
|
||||
}
|
||||
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand();
|
||||
renderCommand->setViewport(target);
|
||||
uint32 primitiveDescriptorIndex = 0;
|
||||
for(uint32 i = 0; i < batch.elements.size(); ++i)
|
||||
{
|
||||
pipelineLayout->addDescriptorLayout(2, material->getRenderMaterial()->getDescriptorLayout());
|
||||
pipelineLayout->create();
|
||||
descriptorSets[2] = material->getDescriptor();
|
||||
descriptorSets[3] = cachedPrimitiveSets[primitiveDescriptorIndex++];
|
||||
descriptorSets[3] = cachedPrimitiveSets[cachedPrimitiveIndex++];
|
||||
buildMeshDrawCommand(batch,
|
||||
// primitiveComponent,
|
||||
renderPass,
|
||||
@@ -74,6 +74,7 @@ void BasePassMeshProcessor::clearCommands()
|
||||
{
|
||||
renderCommands.clear();
|
||||
cachedPrimitiveSets.clear();
|
||||
cachedPrimitiveIndex = 0;
|
||||
}
|
||||
|
||||
BasePass::BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
|
||||
@@ -140,7 +141,6 @@ void BasePass::beginFrame()
|
||||
uniformUpdate.size = sizeof(LightEnv);
|
||||
uniformUpdate.data = (uint8*)&scene->getLightEnvironment();
|
||||
lightUniform->updateContents(uniformUpdate);
|
||||
descriptorSets[0]->beginFrame();
|
||||
descriptorSets[0]->updateBuffer(0, lightUniform);
|
||||
descriptorSets[0]->writeChanges();
|
||||
|
||||
@@ -155,7 +155,6 @@ void BasePass::beginFrame()
|
||||
uniformUpdate.size = sizeof(ScreenToViewParameter);
|
||||
uniformUpdate.data = (uint8*)&screenToViewParams;
|
||||
screenToViewParamBuffer->updateContents(uniformUpdate);
|
||||
descriptorSets[1]->beginFrame();
|
||||
descriptorSets[1]->updateBuffer(0, viewParamBuffer);
|
||||
descriptorSets[1]->updateBuffer(1, screenToViewParamBuffer);
|
||||
descriptorSets[1]->writeChanges();
|
||||
|
||||
@@ -16,13 +16,14 @@ public:
|
||||
const Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
Array<Gfx::PDescriptorSet>& descriptorSets,
|
||||
int32 staticMeshId = -1) override;
|
||||
Array<Gfx::PRenderCommand> getRenderCommands();
|
||||
void clearCommands();
|
||||
private:
|
||||
Array<Gfx::PRenderCommand> renderCommands;
|
||||
Array<Gfx::PDescriptorSet> cachedPrimitiveSets;
|
||||
uint32 cachedPrimitiveIndex;
|
||||
Gfx::PViewport target;
|
||||
uint8 translucentBasePass;
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ void MeshProcessor::buildMeshDrawCommand(
|
||||
const Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PRenderCommand drawCommand,
|
||||
Array<Gfx::PDescriptorSet> descriptors,
|
||||
const Array<Gfx::PDescriptorSet>& descriptors,
|
||||
Gfx::PVertexShader vertexShader,
|
||||
Gfx::PControlShader controlShader,
|
||||
Gfx::PEvaluationShader evaluationShader,
|
||||
|
||||
@@ -20,7 +20,7 @@ protected:
|
||||
const Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
Array<Gfx::PDescriptorSet>& descriptorSets,
|
||||
int32 staticMeshId = -1) = 0;
|
||||
void buildMeshDrawCommand(
|
||||
const MeshBatch& meshBatch,
|
||||
@@ -28,7 +28,7 @@ protected:
|
||||
const Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PRenderCommand drawCommand,
|
||||
Array<Gfx::PDescriptorSet> descriptors,
|
||||
const Array<Gfx::PDescriptorSet>& descriptors,
|
||||
Gfx::PVertexShader vertexShader,
|
||||
Gfx::PControlShader controlShader,
|
||||
Gfx::PEvaluationShader evaluationShader,
|
||||
|
||||
@@ -61,9 +61,9 @@ void StaticMeshVertexInput::init(Gfx::PGraphics graphics)
|
||||
initDeclaration(graphics, elements);
|
||||
}
|
||||
|
||||
void StaticMeshVertexInput::setData(StaticMeshDataType data)
|
||||
void StaticMeshVertexInput::setData(StaticMeshDataType&& data)
|
||||
{
|
||||
this->data = data;
|
||||
this->data = std::move(data);
|
||||
}
|
||||
|
||||
IMPLEMENT_VERTEX_INPUT_TYPE(StaticMeshVertexInput, "StaticMeshVertexInput");
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
StaticMeshVertexInput(std::string name);
|
||||
virtual ~StaticMeshVertexInput();
|
||||
virtual void init(Gfx::PGraphics graphics) override;
|
||||
void setData(StaticMeshDataType data);
|
||||
void setData(StaticMeshDataType&& data);
|
||||
private:
|
||||
StaticMeshDataType data;
|
||||
};
|
||||
|
||||
@@ -177,7 +177,7 @@ void SecondaryCmdBuffer::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
|
||||
VkDescriptorSet setHandle = descriptorSet.cast<DescriptorSet>()->getHandle();
|
||||
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr);
|
||||
}
|
||||
void SecondaryCmdBuffer::bindDescriptor(Array<Gfx::PDescriptorSet> descriptorSets)
|
||||
void SecondaryCmdBuffer::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets)
|
||||
{
|
||||
VkDescriptorSet* sets = new VkDescriptorSet[descriptorSets.size()];
|
||||
for(uint32 i = 0; i < descriptorSets.size(); ++i)
|
||||
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
virtual void setViewport(Gfx::PViewport viewport) override;
|
||||
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
|
||||
virtual void bindDescriptor(Array<Gfx::PDescriptorSet> descriptorSets) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
|
||||
virtual void bindVertexBuffer(const Array<VertexInputStream>& streams) override;
|
||||
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
|
||||
virtual void draw(const MeshBatchElement& data) override;
|
||||
|
||||
@@ -41,8 +41,6 @@ void DescriptorLayout::create()
|
||||
init::DescriptorSetLayoutCreateInfo(bindings.data(), bindings.size());
|
||||
VK_CHECK(vkCreateDescriptorSetLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle));
|
||||
|
||||
std::cout << "creating descriptorlayout " << layoutHandle << std::endl;
|
||||
|
||||
allocator = new DescriptorAllocator(graphics, *this);
|
||||
|
||||
boost::crc_32_type result;
|
||||
@@ -115,7 +113,6 @@ DescriptorSet::~DescriptorSet()
|
||||
|
||||
void DescriptorSet::beginFrame()
|
||||
{
|
||||
currentFrameSet = (currentFrameSet + 1) % Gfx::numFramesBuffered;
|
||||
}
|
||||
|
||||
void DescriptorSet::endFrame()
|
||||
@@ -125,41 +122,39 @@ void DescriptorSet::endFrame()
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer)
|
||||
{
|
||||
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
|
||||
UniformBuffer* cachedBuffer = reinterpret_cast<UniformBuffer*>(cachedData[currentFrameSet][binding]);
|
||||
UniformBuffer* cachedBuffer = reinterpret_cast<UniformBuffer*>(cachedData[Gfx::currentFrameIndex][binding]);
|
||||
if(vulkanBuffer->isDataEquals(cachedBuffer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
VkDescriptorBufferInfo bufferInfo = init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize());
|
||||
bufferInfos.add(bufferInfo);
|
||||
bufferInfos.add(init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize()));
|
||||
|
||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[currentFrameSet], VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, binding, &bufferInfos.back());
|
||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[Gfx::currentFrameIndex], VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, binding, &bufferInfos.back());
|
||||
writeDescriptors.add(writeDescriptor);
|
||||
|
||||
cachedData[currentFrameSet][binding] = vulkanBuffer.getHandle();
|
||||
cachedData[Gfx::currentFrameIndex][binding] = vulkanBuffer.getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer)
|
||||
{
|
||||
PStructuredBuffer vulkanBuffer = uniformBuffer.cast<StructuredBuffer>();
|
||||
StructuredBuffer* cachedBuffer = reinterpret_cast<StructuredBuffer*>(cachedData[currentFrameSet][binding]);
|
||||
StructuredBuffer* cachedBuffer = reinterpret_cast<StructuredBuffer*>(cachedData[Gfx::currentFrameIndex][binding]);
|
||||
if(vulkanBuffer.getHandle() == cachedBuffer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
VkDescriptorBufferInfo bufferInfo = init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize());
|
||||
bufferInfos.add(bufferInfo);
|
||||
bufferInfos.add(init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize()));
|
||||
|
||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[currentFrameSet], VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, binding, &bufferInfos.back());
|
||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[Gfx::currentFrameIndex], VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, binding, &bufferInfos.back());
|
||||
writeDescriptors.add(writeDescriptor);
|
||||
|
||||
cachedData[currentFrameSet][binding] = vulkanBuffer.getHandle();
|
||||
cachedData[Gfx::currentFrameIndex][binding] = vulkanBuffer.getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSamplerState samplerState)
|
||||
{
|
||||
PSamplerState vulkanSampler = samplerState.cast<SamplerState>();
|
||||
SamplerState* cachedSampler = reinterpret_cast<SamplerState*>(cachedData[currentFrameSet][binding]);
|
||||
SamplerState* cachedSampler = reinterpret_cast<SamplerState*>(cachedData[Gfx::currentFrameIndex][binding]);
|
||||
if(vulkanSampler.getHandle() == cachedSampler)
|
||||
{
|
||||
return;
|
||||
@@ -171,16 +166,16 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSamplerState samplerSt
|
||||
VK_IMAGE_LAYOUT_UNDEFINED);
|
||||
imageInfos.add(imageInfo);
|
||||
|
||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[currentFrameSet], VK_DESCRIPTOR_TYPE_SAMPLER, binding, &imageInfos.back());
|
||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[Gfx::currentFrameIndex], VK_DESCRIPTOR_TYPE_SAMPLER, binding, &imageInfos.back());
|
||||
writeDescriptors.add(writeDescriptor);
|
||||
|
||||
cachedData[currentFrameSet][binding] = vulkanSampler.getHandle();
|
||||
cachedData[Gfx::currentFrameIndex][binding] = vulkanSampler.getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSamplerState samplerState)
|
||||
{
|
||||
TextureHandle* vulkanTexture = TextureBase::cast(texture);
|
||||
TextureHandle* cachedTexture = reinterpret_cast<TextureHandle*>(cachedData[currentFrameSet][binding]);
|
||||
TextureHandle* cachedTexture = reinterpret_cast<TextureHandle*>(cachedData[Gfx::currentFrameIndex][binding]);
|
||||
if(vulkanTexture == cachedTexture)
|
||||
{
|
||||
return;
|
||||
@@ -197,14 +192,14 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
|
||||
imageInfo.sampler = vulkanSampler->sampler;
|
||||
}
|
||||
imageInfos.add(imageInfo);
|
||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[currentFrameSet], samplerState != nullptr ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, binding, &imageInfos.back());
|
||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[Gfx::currentFrameIndex], samplerState != nullptr ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, binding, &imageInfos.back());
|
||||
if (vulkanTexture->getUsage() & VK_IMAGE_USAGE_STORAGE_BIT)
|
||||
{
|
||||
writeDescriptor.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
|
||||
}
|
||||
writeDescriptors.add(writeDescriptor);
|
||||
|
||||
cachedData[currentFrameSet][binding] = vulkanTexture;
|
||||
cachedData[Gfx::currentFrameIndex][binding] = vulkanTexture;
|
||||
}
|
||||
|
||||
bool DescriptorSet::operator<(Gfx::PDescriptorSet other)
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
{
|
||||
return poolHandle;
|
||||
}
|
||||
inline DescriptorLayout getLayout() const
|
||||
inline DescriptorLayout& getLayout() const
|
||||
{
|
||||
return layout;
|
||||
}
|
||||
@@ -83,7 +83,7 @@ class DescriptorSet : public Gfx::DescriptorSet
|
||||
{
|
||||
public:
|
||||
DescriptorSet(PGraphics graphics, PDescriptorAllocator owner)
|
||||
: graphics(graphics), owner(owner), currentFrameSet(0)
|
||||
: graphics(graphics), owner(owner)
|
||||
{
|
||||
}
|
||||
virtual ~DescriptorSet();
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
virtual bool operator<(Gfx::PDescriptorSet other);
|
||||
inline VkDescriptorSet getHandle() const
|
||||
{
|
||||
return setHandle[currentFrameSet];
|
||||
return setHandle[Gfx::currentFrameIndex];
|
||||
}
|
||||
virtual uint32 getSetIndex() const
|
||||
{
|
||||
@@ -113,7 +113,6 @@ private:
|
||||
// would not work anyways, so casts should be safe
|
||||
Array<void*> cachedData[Gfx::numFramesBuffered];
|
||||
VkDescriptorSet setHandle[Gfx::numFramesBuffered];
|
||||
uint32 currentFrameSet;
|
||||
PDescriptorAllocator owner;
|
||||
PGraphics graphics;
|
||||
friend class DescriptorAllocator;
|
||||
|
||||
@@ -282,7 +282,8 @@ Array<const char *> Graphics::getRequiredExtensions()
|
||||
{
|
||||
extensions.add(glfwExtensions[i]);
|
||||
}
|
||||
#ifdef ENABLE_VALIDATION
|
||||
std::cout << ENABLE_VALIDATION << std::endl;
|
||||
#if ENABLE_VALIDATION
|
||||
extensions.add(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
||||
#endif // ENABLE_VALIDATION
|
||||
return extensions;
|
||||
@@ -308,7 +309,7 @@ void Graphics::initInstance(GraphicsInitializer initInfo)
|
||||
}
|
||||
info.enabledExtensionCount = (uint32)extensions.size();
|
||||
info.ppEnabledExtensionNames = extensions.data();
|
||||
#ifdef ENABLE_VALIDATION
|
||||
#if ENABLE_VALIDATION
|
||||
info.enabledLayerCount = (uint32)initInfo.layers.size();
|
||||
info.ppEnabledLayerNames = initInfo.layers.data();
|
||||
#else
|
||||
|
||||
@@ -55,6 +55,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
|
||||
createInfo.stageCount = 0;
|
||||
|
||||
VkPipelineTessellationStateCreateInfo tessInfo;
|
||||
std::memset(&tessInfo, 0, sizeof(VkPipelineTessellationStateCreateInfo));
|
||||
VkPipelineShaderStageCreateInfo stageInfos[5];
|
||||
std::memset(stageInfos, 0, sizeof(stageInfos));
|
||||
|
||||
@@ -119,7 +120,8 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
|
||||
Array<VkVertexInputAttributeDescription> attributes;
|
||||
Map<uint32, uint32> bindingToStream;
|
||||
Map<uint32, uint32> streamToBinding;
|
||||
std::memset(bindings.data(), 0, sizeof(VkVertexInputBindingDescription) * 16); // if default allocation size ever changes, this breaks
|
||||
assert(DEFAULT_ALLOC_SIZE == 16);
|
||||
std::memset(bindings.data(), 0, sizeof(VkVertexInputBindingDescription) * 16);
|
||||
std::memset(attributes.data(), 0, sizeof(VkVertexInputAttributeDescription) * 16);
|
||||
for(auto& element : vertexStreams)
|
||||
{
|
||||
|
||||
@@ -83,7 +83,6 @@ static Gfx::SeDescriptorType getTypeFromKind(slang::TypeReflection::Kind kind)
|
||||
|
||||
void Shader::create(const ShaderCreateInfo& createInfo)
|
||||
{
|
||||
std::cout << "--------------------------------" << std::endl;
|
||||
entryPointName = createInfo.entryPoint;
|
||||
static SlangSession* session = spCreateSession(NULL);
|
||||
|
||||
|
||||
@@ -138,6 +138,10 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
|
||||
// When loading a texture from a file, we will almost always use it as a texture map for fragment shaders
|
||||
changeLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
}
|
||||
if(usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
||||
{
|
||||
changeLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||
}
|
||||
|
||||
VkImageViewCreateInfo viewInfo =
|
||||
init::ImageViewCreateInfo();
|
||||
|
||||
@@ -47,7 +47,6 @@ void Material::compile()
|
||||
json j;
|
||||
stream >> j;
|
||||
materialName = j["name"].get<std::string>();
|
||||
std::cout << "Compiling material " << materialName << std::endl;
|
||||
//Shader file needs to conform to the slang standard, which prohibits _
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '_'), materialName.end());
|
||||
std::ofstream codeStream("./shaders/generated/"+materialName+".slang");
|
||||
|
||||
@@ -48,7 +48,7 @@ void MaterialAsset::updateDescriptorData()
|
||||
descriptorSet->writeChanges();
|
||||
}
|
||||
|
||||
Gfx::PDescriptorSet MaterialAsset::getDescriptor() const
|
||||
const Gfx::PDescriptorSet MaterialAsset::getDescriptor() const
|
||||
{
|
||||
return descriptorSet;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
|
||||
// This needs to be called while the descriptorset is unused
|
||||
void updateDescriptorData();
|
||||
Gfx::PDescriptorSet getDescriptor() const;
|
||||
const Gfx::PDescriptorSet getDescriptor() const;
|
||||
protected:
|
||||
//For now its simply the collection of parameters, since there is no point for expressions
|
||||
Array<PShaderParameter> parameters;
|
||||
|
||||
@@ -135,8 +135,8 @@ public:
|
||||
else
|
||||
{
|
||||
object = (RefObject<T> *)registeredObj->value;
|
||||
object->addRef();
|
||||
}
|
||||
object->addRef();
|
||||
}
|
||||
explicit RefPtr(RefObject<T> *other)
|
||||
: object(other)
|
||||
|
||||
@@ -33,7 +33,7 @@ void Scene::addActor(PActor actor)
|
||||
void Scene::addPrimitiveComponent(PPrimitiveComponent comp)
|
||||
{
|
||||
primitives.add(comp);
|
||||
for(auto batch : comp->staticMeshes)
|
||||
for(auto& batch : comp->staticMeshes)
|
||||
{
|
||||
PrimitiveUniformBuffer data;
|
||||
data.actorWorldPosition = Vector4(comp->getTransform().getPosition(), 1);
|
||||
|
||||
Reference in New Issue
Block a user