Implemented image binding reflection
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
Now using image binding reflection for the KRCamera debug font texture
This commit is contained in:
@@ -533,6 +533,42 @@ bool KRPipeline::hasPushConstant(ShaderValue location) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool KRPipeline::setImageBindings(const std::vector<const KRReflectedObject*> objects)
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
for (int stage = 0; stage < static_cast<size_t>(ShaderStage::ShaderStageCount); stage++) {
|
||||||
|
StageInfo& stageInfo = m_stages[stage];
|
||||||
|
for (DescriptorSetInfo& descriptorSetInfo : stageInfo.descriptorSets) {
|
||||||
|
for (DescriptorBinding& binding : descriptorSetInfo.bindings) {
|
||||||
|
ImageDescriptorInfo* image = std::get_if<ImageDescriptorInfo>(&binding);
|
||||||
|
if (image) {
|
||||||
|
bool found = false;
|
||||||
|
const KRTextureBinding* binding = nullptr;
|
||||||
|
for (const KRReflectedObject* object : objects) {
|
||||||
|
KRSampler* sampler = nullptr;
|
||||||
|
if (object->getImageBinding(image->name, &binding, &sampler)) {
|
||||||
|
if (binding->isBound() && binding->get()->getStreamLevel() > kraken_stream_level::STREAM_LEVEL_OUT) {
|
||||||
|
image->texture = binding->get();
|
||||||
|
image->sampler = sampler;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
success = false;
|
||||||
|
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Image binding not found: %s", image->name.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
bool KRPipeline::setPushConstants(const std::vector<const KRReflectedObject*> objects)
|
bool KRPipeline::setPushConstants(const std::vector<const KRReflectedObject*> objects)
|
||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
@@ -642,31 +678,10 @@ void KRPipeline::updateDescriptorBinding()
|
|||||||
|
|
||||||
bool KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matModel)
|
bool KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matModel)
|
||||||
{
|
{
|
||||||
KRDirectionalLight* directionalLight = nullptr;
|
if (!setPushConstants(ri.reflectedObjects)) {
|
||||||
if (ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_LIGHTS && ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_GBUFFER && ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_OPAQUE && ri.renderPass->getType() != RenderPassType::RENDER_PASS_SHADOWMAP) {
|
|
||||||
if (!ri.directional_lights.empty())
|
|
||||||
{
|
|
||||||
directionalLight = ri.directional_lights.front();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
KRModelView modelView(ri.viewport, matModel, directionalLight);
|
|
||||||
|
|
||||||
ri.reflectedObjects.push_back(&modelView);
|
|
||||||
ri.reflectedObjects.push_back(ri.viewport);
|
|
||||||
ri.reflectedObjects.push_back(&ri.camera->settings);
|
|
||||||
|
|
||||||
bool success = setPushConstants(ri.reflectedObjects);
|
|
||||||
|
|
||||||
ri.reflectedObjects.pop_back();
|
|
||||||
ri.reflectedObjects.pop_back();
|
|
||||||
ri.reflectedObjects.pop_back();
|
|
||||||
|
|
||||||
setPushConstant(ShaderValue::absolute_time, getContext().getAbsoluteTime());
|
|
||||||
|
|
||||||
if (!success) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
setPushConstant(ShaderValue::absolute_time, getContext().getAbsoluteTime());
|
||||||
|
|
||||||
for (StageInfo& stageInfo : m_stages) {
|
for (StageInfo& stageInfo : m_stages) {
|
||||||
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
||||||
@@ -680,19 +695,44 @@ bool KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matM
|
|||||||
|
|
||||||
bool KRPipeline::bind(KRNode::RenderInfo& ri, const Matrix4& matModel)
|
bool KRPipeline::bind(KRNode::RenderInfo& ri, const Matrix4& matModel)
|
||||||
{
|
{
|
||||||
|
bool success = true;
|
||||||
|
KRDirectionalLight* directionalLight = nullptr;
|
||||||
|
if (ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_LIGHTS && ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_GBUFFER && ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_OPAQUE && ri.renderPass->getType() != RenderPassType::RENDER_PASS_SHADOWMAP) {
|
||||||
|
if (!ri.directional_lights.empty()) {
|
||||||
|
directionalLight = ri.directional_lights.front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KRModelView modelView(ri.viewport, matModel, directionalLight);
|
||||||
|
|
||||||
|
ri.reflectedObjects.push_back(&modelView);
|
||||||
|
ri.reflectedObjects.push_back(ri.viewport);
|
||||||
|
ri.reflectedObjects.push_back(&ri.camera->settings);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
success = updatePushConstants(ri, matModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
success = setImageBindings(ri.reflectedObjects);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success) {
|
||||||
updateDescriptorBinding();
|
updateDescriptorBinding();
|
||||||
updateDescriptorSets();
|
updateDescriptorSets();
|
||||||
bindDescriptorSets(ri.commandBuffer);
|
bindDescriptorSets(ri.commandBuffer);
|
||||||
if (!updatePushConstants(ri, matModel)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ri.pipeline != this) {
|
if (ri.pipeline != this) {
|
||||||
vkCmdBindPipeline(ri.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphicsPipeline);
|
vkCmdBindPipeline(ri.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphicsPipeline);
|
||||||
ri.pipeline = this;
|
ri.pipeline = this;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
ri.reflectedObjects.pop_back();
|
||||||
|
ri.reflectedObjects.pop_back();
|
||||||
|
ri.reflectedObjects.pop_back();
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRPipeline::updateDescriptorSets()
|
void KRPipeline::updateDescriptorSets()
|
||||||
|
|||||||
@@ -221,6 +221,7 @@ public:
|
|||||||
|
|
||||||
static const size_t kPushConstantCount = static_cast<size_t>(ShaderValue::NUM_SHADER_VALUES);
|
static const size_t kPushConstantCount = static_cast<size_t>(ShaderValue::NUM_SHADER_VALUES);
|
||||||
|
|
||||||
|
bool setImageBindings(const std::vector<const KRReflectedObject*> objects);
|
||||||
bool setPushConstants(const std::vector<const KRReflectedObject*> objects);
|
bool setPushConstants(const std::vector<const KRReflectedObject*> objects);
|
||||||
bool hasPushConstant(ShaderValue location) const;
|
bool hasPushConstant(ShaderValue location) const;
|
||||||
void setPushConstant(ShaderValue location, float value);
|
void setPushConstant(ShaderValue location, float value);
|
||||||
|
|||||||
@@ -308,3 +308,8 @@ bool KRReflectedObject::getShaderValue(ShaderValue value, KRResourceBinding* out
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KRReflectedObject::getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -33,9 +33,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
#include "hydra.h"
|
#include "hydra.h"
|
||||||
|
|
||||||
class KRResourceBinding;
|
class KRResourceBinding;
|
||||||
|
class KRSampler;
|
||||||
|
class KRTextureBinding;
|
||||||
|
|
||||||
enum class ShaderValueType : uint8_t
|
enum class ShaderValueType : uint8_t
|
||||||
{
|
{
|
||||||
@@ -221,6 +224,7 @@ class KRReflectedObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool getShaderValue(ShaderValue value, ShaderValueType type, void* output) const;
|
bool getShaderValue(ShaderValue value, ShaderValueType type, void* output) const;
|
||||||
|
virtual bool getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const;
|
||||||
protected:
|
protected:
|
||||||
virtual bool getShaderValue(ShaderValue value, bool* output) const;
|
virtual bool getShaderValue(ShaderValue value, bool* output) const;
|
||||||
virtual bool getShaderValue(ShaderValue value, int32_t* output) const;
|
virtual bool getShaderValue(ShaderValue value, int32_t* output) const;
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ KRCamera::KRCamera(KRScene& scene, std::string name)
|
|||||||
m_frame_times_filled = 0;
|
m_frame_times_filled = 0;
|
||||||
|
|
||||||
m_fade_color = Vector4::Zero();
|
m_fade_color = Vector4::Zero();
|
||||||
m_fontTexture.set("font");
|
|
||||||
|
|
||||||
m_debug_text_vbo_data.init(m_pContext->getMeshManager(), &m_debug_text_vertices, nullptr, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), true, KRMeshManager::KRVBOData::IMMEDIATE
|
m_debug_text_vbo_data.init(m_pContext->getMeshManager(), &m_debug_text_vertices, nullptr, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), true, KRMeshManager::KRVBOData::IMMEDIATE
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
@@ -146,7 +145,7 @@ void KRCamera::getResourceBindings(std::list<KRResourceBinding*>& bindings)
|
|||||||
|
|
||||||
void KRCamera::render(KRNode::RenderInfo& ri)
|
void KRCamera::render(KRNode::RenderInfo& ri)
|
||||||
{
|
{
|
||||||
KRScene& scene = getScene();
|
ri.reflectedObjects.push_back(this);
|
||||||
|
|
||||||
switch (ri.renderPass->getType()) {
|
switch (ri.renderPass->getType()) {
|
||||||
case RenderPassType::RENDER_PASS_FORWARD_OPAQUE:
|
case RenderPassType::RENDER_PASS_FORWARD_OPAQUE:
|
||||||
@@ -211,6 +210,9 @@ void KRCamera::render(KRNode::RenderInfo& ri)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ri.reflectedObjects.pop_back();
|
||||||
|
|
||||||
|
KRScene& scene = getScene();
|
||||||
scene.render(ri);
|
scene.render(ri);
|
||||||
|
|
||||||
switch (ri.renderPass->getType()) {
|
switch (ri.renderPass->getType()) {
|
||||||
@@ -479,6 +481,8 @@ void KRCamera::renderPost(RenderInfo& ri)
|
|||||||
|
|
||||||
void KRCamera::renderDebug(RenderInfo& ri)
|
void KRCamera::renderDebug(RenderInfo& ri)
|
||||||
{
|
{
|
||||||
|
settings.m_debug_text = "Font Test"; // FNIDME!! KIPG!! HACK!! Debug text debugging...
|
||||||
|
|
||||||
const char* szText = settings.m_debug_text.c_str();
|
const char* szText = settings.m_debug_text.c_str();
|
||||||
if (*szText == '\0') {
|
if (*szText == '\0') {
|
||||||
if (m_debug_text_vertices.getSize() > 0) {
|
if (m_debug_text_vertices.getSize() > 0) {
|
||||||
@@ -487,16 +491,6 @@ void KRCamera::renderDebug(RenderInfo& ri)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_fontTexture.isBound())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
KRTexture* fontTexture = m_fontTexture.get();
|
|
||||||
if (fontTexture->getStreamLevel() == kraken_stream_level::STREAM_LEVEL_OUT) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string debug_text;
|
std::string debug_text;
|
||||||
if (settings.debug_display != KRRenderSettings::KRENGINE_DEBUG_DISPLAY_NONE) {
|
if (settings.debug_display != KRRenderSettings::KRENGINE_DEBUG_DISPLAY_NONE) {
|
||||||
debug_text = getDebugText();;
|
debug_text = getDebugText();;
|
||||||
@@ -631,7 +625,6 @@ void KRCamera::renderDebug(RenderInfo& ri)
|
|||||||
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
|
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
|
||||||
KRPipeline* fontShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
|
KRPipeline* fontShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
|
||||||
|
|
||||||
fontShader->setImageBinding("fontTexture", fontTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
|
|
||||||
if (fontShader->bind(ri, Matrix4())) {
|
if (fontShader->bind(ri, Matrix4())) {
|
||||||
|
|
||||||
m_debug_text_vbo_data.bind(ri.commandBuffer);
|
m_debug_text_vbo_data.bind(ri.commandBuffer);
|
||||||
@@ -859,8 +852,17 @@ bool KRCamera::getShaderValue(ShaderValue value, hydra::Vector4* output) const
|
|||||||
default:
|
default:
|
||||||
return KRNode::getShaderValue(value, output);
|
return KRNode::getShaderValue(value, output);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KRCamera::getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const
|
||||||
|
{
|
||||||
|
if (name == "fontTexture") {
|
||||||
|
*binding = &m_fontTexture;
|
||||||
|
*sample = getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return KRNode::getImageBinding(name, binding, sample);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRCamera::alwaysStreamResources()
|
bool KRCamera::alwaysStreamResources()
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool getShaderValue(ShaderValue value, hydra::Vector4* output) const override;
|
bool getShaderValue(ShaderValue value, hydra::Vector4* output) const override;
|
||||||
|
bool getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createBuffers(int renderBufferWidth, int renderBufferHeight);
|
void createBuffers(int renderBufferWidth, int renderBufferHeight);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void KRResourceBinding::submitRequest(KRContext* context, std::list<KRResourceRe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KRResource* KRResourceBinding::get()
|
KRResource* KRResourceBinding::get() const
|
||||||
{
|
{
|
||||||
return m_resource;
|
return m_resource;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
|
|
||||||
void submitRequest(KRContext* context, std::list<KRResourceRequest>& resourceRequests, float lodCoverage = 0.f);
|
void submitRequest(KRContext* context, std::list<KRResourceRequest>& resourceRequests, float lodCoverage = 0.f);
|
||||||
|
|
||||||
KRResource* get();
|
KRResource* get() const;
|
||||||
void set(KRResource* resource);
|
void set(KRResource* resource);
|
||||||
void set(const std::string& name);
|
void set(const std::string& name);
|
||||||
bool isSet() const;
|
bool isSet() const;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ KRTextureBinding::KRTextureBinding(KRTexture::texture_usage_t usage)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KRTexture* KRTextureBinding::get()
|
KRTexture* KRTextureBinding::get() const
|
||||||
{
|
{
|
||||||
return static_cast<KRTexture*>(m_resource);
|
return static_cast<KRTexture*>(m_resource);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class KRTextureBinding : public KRResourceBinding
|
|||||||
public:
|
public:
|
||||||
KRTextureBinding(const std::string& name, KRTexture::texture_usage_t usage);
|
KRTextureBinding(const std::string& name, KRTexture::texture_usage_t usage);
|
||||||
KRTextureBinding(KRTexture::texture_usage_t usage);
|
KRTextureBinding(KRTexture::texture_usage_t usage);
|
||||||
KRTexture* get();
|
KRTexture* get() const;
|
||||||
|
|
||||||
bool bind(KRContext* context) override final;
|
bool bind(KRContext* context) override final;
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user