First runnable render loop
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user