Surface handles are now indirect.
This commit is contained in:
@@ -60,6 +60,7 @@ KRContext::KRContext(const KrInitializeInfo* initializeInfo)
|
||||
, m_vulkanInstance(VK_NULL_HANDLE)
|
||||
, m_resourceMapSize(initializeInfo->resourceMapSize)
|
||||
, m_topDeviceHandle(0)
|
||||
, m_topSurfaceHandle(0)
|
||||
{
|
||||
m_resourceMap = (KRResource **)malloc(sizeof(KRResource*) * m_resourceMapSize);
|
||||
memset(m_resourceMap, 0, m_resourceMapSize * sizeof(KRResource*));
|
||||
@@ -808,6 +809,7 @@ KRContext::destroySurfaces()
|
||||
|
||||
}
|
||||
m_surfaces.clear();
|
||||
m_surfaceHandleMap.clear();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1068,9 +1070,12 @@ KrResult KRContext::createWindowSurface(const KrCreateWindowSurfaceInfo* createW
|
||||
}
|
||||
}
|
||||
|
||||
m_surfaces.insert(std::pair<KrSurfaceHandle, SurfaceInfo>(createWindowSurfaceInfo->surfaceHandle, info));
|
||||
KrSurfaceHandle surfaceHandle = ++m_topSurfaceHandle;
|
||||
m_surfaces.insert(std::pair<KrSurfaceHandle, SurfaceInfo>(surfaceHandle, info));
|
||||
|
||||
m_pPipelineManager->createPipelines(deviceInfo->logicalDevice); // TODO - Support multiple surfaces. Device needs to be passed in.
|
||||
m_surfaceHandleMap.insert(std::pair<KrSurfaceMapIndex, KrSurfaceHandle>(createWindowSurfaceInfo->surfaceHandle, surfaceHandle));
|
||||
|
||||
m_pPipelineManager->createPipelines(surfaceHandle);
|
||||
|
||||
return KR_SUCCESS;
|
||||
#else
|
||||
@@ -1087,7 +1092,15 @@ KrResult KRContext::deleteWindowSurface(const KrDeleteWindowSurfaceInfo* deleteW
|
||||
if (m_vulkanInstance == VK_NULL_HANDLE) {
|
||||
return KR_ERROR_VULKAN_REQUIRED;
|
||||
}
|
||||
auto itr = m_surfaces.find(deleteWindowSurfaceInfo->surfaceHandle);
|
||||
|
||||
auto handleItr = m_surfaceHandleMap.find(deleteWindowSurfaceInfo->surfaceHandle);
|
||||
if (handleItr == m_surfaceHandleMap.end()) {
|
||||
return KR_ERROR_NOT_FOUND;
|
||||
}
|
||||
KrSurfaceHandle surfaceHandle = (*handleItr).second;
|
||||
m_surfaceHandleMap.erase(handleItr);
|
||||
|
||||
auto itr = m_surfaces.find(surfaceHandle);
|
||||
if (itr == m_surfaces.end()) {
|
||||
return KR_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
static void activateStreamerContext();
|
||||
static void activateRenderContext();
|
||||
|
||||
typedef int KrDeviceHandle;
|
||||
|
||||
typedef struct {
|
||||
VkPhysicalDevice device;
|
||||
VkDevice logicalDevice;
|
||||
@@ -141,7 +141,6 @@ public:
|
||||
VkQueue computeQueue;
|
||||
} DeviceInfo;
|
||||
|
||||
typedef int KrSurfaceHandle;
|
||||
typedef struct {
|
||||
KrSurfaceHandle surfaceHandle;
|
||||
KrDeviceHandle deviceHandle;
|
||||
@@ -209,9 +208,6 @@ private:
|
||||
|
||||
unordered_multimap<std::string, KRResource*> m_resources;
|
||||
|
||||
|
||||
unordered_map<KrSurfaceHandle, SurfaceInfo> m_surfaces;
|
||||
|
||||
std::thread m_presentationThread;
|
||||
void presentationThreadFunc();
|
||||
std::atomic<bool> m_stop;
|
||||
@@ -219,6 +215,11 @@ private:
|
||||
|
||||
unordered_map<KrDeviceHandle, DeviceInfo> m_devices;
|
||||
KrDeviceHandle m_topDeviceHandle;
|
||||
|
||||
unordered_map<KrSurfaceHandle, SurfaceInfo> m_surfaces;
|
||||
KrDeviceHandle m_topSurfaceHandle;
|
||||
|
||||
unordered_map<KrSurfaceMapIndex, KrSurfaceHandle> m_surfaceHandleMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -234,6 +234,9 @@ typedef enum {
|
||||
STREAM_LEVEL_IN_HQ
|
||||
} kraken_stream_level;
|
||||
|
||||
typedef int KrDeviceHandle;
|
||||
typedef int KrSurfaceHandle;
|
||||
|
||||
#include "KRBehavior.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -109,14 +109,15 @@ const char *KRPipeline::KRENGINE_UNIFORM_NAMES[] = {
|
||||
"fade_color", // KRENGINE_UNIFORM_FADE_COLOR
|
||||
};
|
||||
|
||||
KRPipeline::KRPipeline(KRContext& context, VkDevice& device, const char* szKey, const std::vector<KRShader*>& shaders)
|
||||
KRPipeline::KRPipeline(KRContext& context, KrSurfaceHandle surfaceHandle, const char* szKey, const std::vector<KRShader*>& shaders)
|
||||
: KRContextObject(context)
|
||||
, m_iProgram(0) // not used for Vulkan
|
||||
{
|
||||
m_pipelineLayout = nullptr;
|
||||
m_graphicsPipeline = nullptr;
|
||||
m_renderPass = nullptr;
|
||||
KRContext::SurfaceInfo& surface = m_pContext->GetSurfaceInfo(1); // TODO - Support multiple surfaces
|
||||
KRContext::SurfaceInfo& surface = m_pContext->GetSurfaceInfo(surfaceHandle);
|
||||
KRContext::DeviceInfo& device = m_pContext->GetDeviceInfo(surface.deviceHandle);
|
||||
|
||||
strcpy(m_szKey, szKey);
|
||||
|
||||
@@ -127,7 +128,7 @@ KRPipeline::KRPipeline(KRContext& context, VkDevice& device, const char* szKey,
|
||||
|
||||
for (KRShader* shader : shaders) {
|
||||
VkShaderModule shaderModule;
|
||||
if (!shader->createShaderModule(device, shaderModule)) {
|
||||
if (!shader->createShaderModule(device.logicalDevice, shaderModule)) {
|
||||
// failed! TODO - Error handling
|
||||
}
|
||||
VkPipelineShaderStageCreateInfo& stageInfo = stages[stage_count++];
|
||||
@@ -169,7 +170,7 @@ KRPipeline::KRPipeline(KRContext& context, VkDevice& device, const char* szKey,
|
||||
renderPassInfo.subpassCount = 1;
|
||||
renderPassInfo.pSubpasses = &subpass;
|
||||
|
||||
if (vkCreateRenderPass(device, &renderPassInfo, nullptr, &m_renderPass) != VK_SUCCESS) {
|
||||
if (vkCreateRenderPass(device.logicalDevice, &renderPassInfo, nullptr, &m_renderPass) != VK_SUCCESS) {
|
||||
// failed! TODO - Error handling
|
||||
}
|
||||
|
||||
@@ -254,7 +255,7 @@ KRPipeline::KRPipeline(KRContext& context, VkDevice& device, const char* szKey,
|
||||
pipelineLayoutInfo.pushConstantRangeCount = 0;
|
||||
pipelineLayoutInfo.pPushConstantRanges = nullptr;
|
||||
|
||||
if (vkCreatePipelineLayout(device, &pipelineLayoutInfo, nullptr, &m_pipelineLayout) != VK_SUCCESS) {
|
||||
if (vkCreatePipelineLayout(device.logicalDevice, &pipelineLayoutInfo, nullptr, &m_pipelineLayout) != VK_SUCCESS) {
|
||||
// failed! TODO - Error handling
|
||||
}
|
||||
|
||||
@@ -276,7 +277,7 @@ KRPipeline::KRPipeline(KRContext& context, VkDevice& device, const char* szKey,
|
||||
pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
|
||||
pipelineInfo.basePipelineIndex = -1;
|
||||
|
||||
if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &m_graphicsPipeline) != VK_SUCCESS) {
|
||||
if (vkCreateGraphicsPipelines(device.logicalDevice, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &m_graphicsPipeline) != VK_SUCCESS) {
|
||||
// Failed! TODO - Error handling
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class KRShader;
|
||||
|
||||
class KRPipeline : public KRContextObject {
|
||||
public:
|
||||
KRPipeline(KRContext& context, VkDevice& device, const char* szKey, const std::vector<KRShader*>& shaders);
|
||||
KRPipeline(KRContext& context, KrSurfaceHandle surfaceHandle, const char* szKey, const std::vector<KRShader*>& shaders);
|
||||
KRPipeline(KRContext &context, char *szKey, std::string options, std::string vertShaderSource, const std::string fragShaderSource);
|
||||
virtual ~KRPipeline();
|
||||
const char *getKey() const;
|
||||
|
||||
@@ -62,7 +62,7 @@ KRPipelineManager::~KRPipelineManager() {
|
||||
#endif // ANDROID
|
||||
}
|
||||
|
||||
void KRPipelineManager::createPipelines(VkDevice& device)
|
||||
void KRPipelineManager::createPipelines(KrSurfaceHandle surface)
|
||||
{
|
||||
{
|
||||
// simple_blit
|
||||
@@ -70,7 +70,7 @@ void KRPipelineManager::createPipelines(VkDevice& device)
|
||||
std::vector<KRShader*> shaders;
|
||||
shaders.push_back(m_pContext->getShaderManager()->get(pipeline_name + ".vert", "spv"));
|
||||
shaders.push_back(m_pContext->getShaderManager()->get(pipeline_name + ".frag", "spv"));
|
||||
KRPipeline* pipeline = new KRPipeline(*m_pContext, device, pipeline_name.c_str(), shaders);
|
||||
KRPipeline* pipeline = new KRPipeline(*m_pContext, surface, pipeline_name.c_str(), shaders);
|
||||
std::pair<std::string, std::vector<int> > key;
|
||||
key.first = pipeline_name;
|
||||
m_pipelines[key] = pipeline;
|
||||
|
||||
@@ -51,7 +51,7 @@ class KRPipelineManager : public KRContextObject {
|
||||
public:
|
||||
KRPipelineManager(KRContext &context);
|
||||
virtual ~KRPipelineManager();
|
||||
void createPipelines(VkDevice& device);
|
||||
void createPipelines(KrSurfaceHandle surface);
|
||||
|
||||
KRPipeline *getPipeline(const std::string &pipeline_name, KRCamera *pCamera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user