Adding texture views are first class primitives

This commit is contained in:
2025-07-04 17:36:40 +02:00
parent 85f88d79bd
commit b2cb8b42e4
26 changed files with 233 additions and 103 deletions
+4 -1
View File
@@ -163,6 +163,9 @@ float3 ImportanceSampleGGX(float2 Xi, float3 N, float roughness)
return normalize(sampleVec); return normalize(sampleVec);
} }
layout(push_constant)
ConstantBuffer<float> pRoughness;
[shader("pixel")] [shader("pixel")]
float4 computePrefilteredCubemap(float3 localPos : LOCALPOS) : SV_Target float4 computePrefilteredCubemap(float3 localPos : LOCALPOS) : SV_Target
{ {
@@ -176,7 +179,7 @@ float4 computePrefilteredCubemap(float3 localPos : LOCALPOS) : SV_Target
for(uint i = 0u; i < SAMPLE_COUNT; ++i) for(uint i = 0u; i < SAMPLE_COUNT; ++i)
{ {
float2 Xi = Hammersley(i, SAMPLE_COUNT); float2 Xi = Hammersley(i, SAMPLE_COUNT);
float3 H = ImportanceSampleGGX(Xi, N, roughness); float3 H = ImportanceSampleGGX(Xi, N, pRoughness);
float3 L = normalize(2.0 * dot(V, H) * H - V); float3 L = normalize(2.0 * dot(V, H) * H - V);
float NdotL = max(dot(N, L), 0.0); float NdotL = max(dot(N, L), 0.0);
+4 -4
View File
@@ -122,7 +122,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
Gfx::PDescriptorSet set = cubeRenderLayout->allocateDescriptorSet(); Gfx::PDescriptorSet set = cubeRenderLayout->allocateDescriptorSet();
set->updateConstants("view", 0, captureViews); set->updateConstants("view", 0, captureViews);
set->updateConstants("projection", 0, &captureProjection); set->updateConstants("projection", 0, &captureProjection);
set->updateTexture("equirectangularMap", 0, Gfx::PTexture2D(hdrTexture)); set->updateTexture("equirectangularMap", 0, hdrTexture->getDefaultView());
set->updateSampler("sampler", 0, cubeSampler); set->updateSampler("sampler", 0, cubeSampler);
set->writeChanges(); set->writeChanges();
Gfx::OTextureCube cubeMap = graphics->createTextureCube(TextureCreateInfo{ Gfx::OTextureCube cubeMap = graphics->createTextureCube(TextureCreateInfo{
@@ -135,7 +135,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
Gfx::RenderTargetLayout{ Gfx::RenderTargetLayout{
.colorAttachments = .colorAttachments =
{ {
Gfx::RenderTargetAttachment(cubeMap, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::RenderTargetAttachment(cubeMap->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE), Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE),
}, },
}, },
@@ -181,7 +181,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
}); });
Gfx::ORenderPass convolutionPass = graphics->createRenderPass( Gfx::ORenderPass convolutionPass = graphics->createRenderPass(
Gfx::RenderTargetLayout{ Gfx::RenderTargetLayout{
.colorAttachments = {Gfx::RenderTargetAttachment(convolutedMap, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, .colorAttachments = {Gfx::RenderTargetAttachment(convolutedMap->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED,
Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE)}, Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE)},
}, },
@@ -206,7 +206,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
set->updateConstants("view", 0, captureViews); set->updateConstants("view", 0, captureViews);
set->updateConstants("projection", 0, &captureProjection); set->updateConstants("projection", 0, &captureProjection);
set->updateSampler("sampler", 0, cubeSampler); set->updateSampler("sampler", 0, cubeSampler);
set->updateTexture("cubeMap", 0, Gfx::PTextureCube(cubeMap)); set->updateTexture("cubeMap", 0, cubeMap->getDefaultView());
set->writeChanges(); set->writeChanges();
graphics->beginRenderPass(convolutionPass); graphics->beginRenderPass(convolutionPass);
+2 -5
View File
@@ -52,12 +52,9 @@ class DescriptorPool {
DEFINE_REF(DescriptorPool) DEFINE_REF(DescriptorPool)
DECLARE_REF(UniformBuffer) DECLARE_REF(UniformBuffer)
DECLARE_REF(ShaderBuffer) DECLARE_REF(ShaderBuffer)
DECLARE_REF(Texture)
DECLARE_REF(Texture2D)
DECLARE_REF(Texture3D)
DECLARE_REF(TextureCube)
DECLARE_REF(Sampler) DECLARE_REF(Sampler)
DECLARE_REF(TopLevelAS) DECLARE_REF(TopLevelAS)
DECLARE_REF(TextureView)
class DescriptorSet { class DescriptorSet {
public: public:
DescriptorSet(PDescriptorLayout layout); DescriptorSet(PDescriptorLayout layout);
@@ -68,7 +65,7 @@ class DescriptorSet {
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer indexBuffer) = 0; virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer indexBuffer) = 0;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer indexBuffer) = 0; virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer indexBuffer) = 0;
virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) = 0; virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) = 0;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture texture) = 0; virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTextureView texture) = 0;
virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) = 0; virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) = 0;
bool operator<(PDescriptorSet other); bool operator<(PDescriptorSet other);
+8 -8
View File
@@ -128,8 +128,8 @@ void BasePass::beginFrame(const Component::Camera& cam, const Component::Transfo
skyboxDataSet->updateConstants("fogBlend", 0, &skyboxData.fogColor); skyboxDataSet->updateConstants("fogBlend", 0, &skyboxData.fogColor);
skyboxDataSet->writeChanges(); skyboxDataSet->writeChanges();
textureSet = textureLayout->allocateDescriptorSet(); textureSet = textureLayout->allocateDescriptorSet();
textureSet->updateTexture(SKYBOXDAY_NAME, 0, skybox.day); textureSet->updateTexture(SKYBOXDAY_NAME, 0, skybox.day->getDefaultView());
textureSet->updateTexture(SKYBOXNIGHT_NAME, 0, skybox.night); textureSet->updateTexture(SKYBOXNIGHT_NAME, 0, skybox.night->getDefaultView());
textureSet->updateSampler(SKYBOXSAMPLER_NAME, 0, skyboxSampler); textureSet->updateSampler(SKYBOXSAMPLER_NAME, 0, skyboxSampler);
textureSet->writeChanges(); textureSet->writeChanges();
} }
@@ -138,9 +138,9 @@ void BasePass::beginFrame(const Component::Camera& cam, const Component::Transfo
void BasePass::render() { void BasePass::render() {
graphics->beginDebugRegion("BasePass"); graphics->beginDebugRegion("BasePass");
opaqueCulling->updateBuffer(LIGHTINDEX_NAME, 0, oLightIndexList); opaqueCulling->updateBuffer(LIGHTINDEX_NAME, 0, oLightIndexList);
opaqueCulling->updateTexture(LIGHTGRID_NAME, 0, oLightGrid); opaqueCulling->updateTexture(LIGHTGRID_NAME, 0, oLightGrid->getDefaultView());
transparentCulling->updateBuffer(LIGHTINDEX_NAME, 0, tLightIndexList); transparentCulling->updateBuffer(LIGHTINDEX_NAME, 0, tLightIndexList);
transparentCulling->updateTexture(LIGHTGRID_NAME, 0, tLightGrid); transparentCulling->updateTexture(LIGHTGRID_NAME, 0, tLightGrid->getDefaultView());
opaqueCulling->writeChanges(); opaqueCulling->writeChanges();
transparentCulling->writeChanges(); transparentCulling->writeChanges();
@@ -421,21 +421,21 @@ void BasePass::publishOutputs() {
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, .usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT,
}); });
depthAttachment = Gfx::RenderTargetAttachment(Gfx::PTexture2D(basePassDepth), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, depthAttachment = Gfx::RenderTargetAttachment(basePassDepth->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED,
Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE); Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
msDepthAttachment = msDepthAttachment =
Gfx::RenderTargetAttachment(msBasePassDepth, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, Gfx::RenderTargetAttachment(msBasePassDepth->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE); Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE);
msDepthAttachment.clear.depthStencil.depth = 0.0f; msDepthAttachment.clear.depthStencil.depth = 0.0f;
colorAttachment = colorAttachment =
Gfx::RenderTargetAttachment(basePassColor, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, Gfx::RenderTargetAttachment(basePassColor->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE); Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
msColorAttachment = msColorAttachment =
Gfx::RenderTargetAttachment(msBasePassColor, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, Gfx::RenderTargetAttachment(msBasePassColor->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE); Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE);
msColorAttachment.clear.color.float32[0] = 0; msColorAttachment.clear.color.float32[0] = 0;
msColorAttachment.clear.color.float32[1] = 1; msColorAttachment.clear.color.float32[1] = 1;
@@ -156,7 +156,7 @@ void CachedDepthPass::publishOutputs() {
}; };
depthBuffer = graphics->createTexture2D(depthBufferInfo); depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment = depthAttachment =
Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, Gfx::RenderTargetAttachment(depthBuffer->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment); resources->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment);
@@ -168,7 +168,7 @@ void CachedDepthPass::publishOutputs() {
}; };
visibilityBuffer = graphics->createTexture2D(visibilityInfo); visibilityBuffer = graphics->createTexture2D(visibilityInfo);
visibilityAttachment = visibilityAttachment =
Gfx::RenderTargetAttachment(visibilityBuffer, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, Gfx::RenderTargetAttachment(visibilityBuffer->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("VISIBILITY", visibilityAttachment); resources->registerRenderPassOutput("VISIBILITY", visibilityAttachment);
query = graphics->createPipelineStatisticsQuery("CachedPipelineStatistics"); query = graphics->createPipelineStatisticsQuery("CachedPipelineStatistics");
@@ -75,12 +75,12 @@ void DepthCullingPass::render() {
{ {
graphics->beginDebugRegion("MipGeneration"); graphics->beginDebugRegion("MipGeneration");
query->beginQuery(); query->beginQuery();
depthAttachment.getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, depthAttachment.getTextureView()->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
depthMipBuffer->rotateBuffer(depthMipBuffer->getNumElements() * sizeof(uint32)); depthMipBuffer->rotateBuffer(depthMipBuffer->getNumElements() * sizeof(uint32));
set->updateTexture(DEPTHTEXTURE_NAME, 0, depthAttachment.getTexture()); set->updateTexture(DEPTHTEXTURE_NAME, 0, depthAttachment.getTextureView());
set->updateBuffer(DEPTHMIP_NAME, 0, depthMipBuffer); set->updateBuffer(DEPTHMIP_NAME, 0, depthMipBuffer);
set->writeChanges(); set->writeChanges();
@@ -115,7 +115,7 @@ void DepthCullingPass::render() {
depthMipBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, depthMipBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT); Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT);
depthAttachment.getTexture()->changeLayout( depthAttachment.getTextureView()->changeLayout(
Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, Gfx::SE_ACCESS_TRANSFER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, Gfx::SE_ACCESS_TRANSFER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT); Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
@@ -216,11 +216,11 @@ void DepthCullingPass::render() {
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "CullingEnd"); timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "CullingEnd");
query->endQuery(); query->endQuery();
// Sync depth read/write with compute read // Sync depth read/write with compute read
depthAttachment.getTexture()->pipelineBarrier( depthAttachment.getTextureView()->pipelineBarrier(
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
// Sync visibility write with compute read // Sync visibility write with compute read
visibilityAttachment.getTexture()->pipelineBarrier(Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, visibilityAttachment.getTextureView()->pipelineBarrier(Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
graphics->endDebugRegion(); graphics->endDebugRegion();
@@ -50,8 +50,8 @@ void LightCullingPass::render() {
cullingDescriptorSet->updateBuffer(TLIGHTINDEXCOUNTER_NAME, 0, tLightIndexCounter); cullingDescriptorSet->updateBuffer(TLIGHTINDEXCOUNTER_NAME, 0, tLightIndexCounter);
cullingDescriptorSet->updateBuffer(OLIGHTINDEXLIST_NAME, 0, oLightIndexList); cullingDescriptorSet->updateBuffer(OLIGHTINDEXLIST_NAME, 0, oLightIndexList);
cullingDescriptorSet->updateBuffer(TLIGHTINDEXLIST_NAME, 0, tLightIndexList); cullingDescriptorSet->updateBuffer(TLIGHTINDEXLIST_NAME, 0, tLightIndexList);
cullingDescriptorSet->updateTexture(OLIGHTGRID_NAME, 0, Gfx::PTexture2D(oLightGrid)); cullingDescriptorSet->updateTexture(OLIGHTGRID_NAME, 0, oLightGrid->getDefaultView());
cullingDescriptorSet->updateTexture(TLIGHTGRID_NAME, 0, Gfx::PTexture2D(tLightGrid)); cullingDescriptorSet->updateTexture(TLIGHTGRID_NAME, 0, tLightGrid->getDefaultView());
cullingDescriptorSet->writeChanges(); cullingDescriptorSet->writeChanges();
Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("CullingCommand"); Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("CullingCommand");
if (getGlobals().useLightCulling) { if (getGlobals().useLightCulling) {
@@ -221,7 +221,7 @@ void LightCullingPass::publishOutputs() {
void LightCullingPass::createRenderPass() { void LightCullingPass::createRenderPass() {
timestamps = resources->requestTimestampQuery("TIMESTAMPS"); timestamps = resources->requestTimestampQuery("TIMESTAMPS");
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH").getTexture(); depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH").getTextureView();
} }
void LightCullingPass::setupFrustums() { void LightCullingPass::setupFrustums() {
@@ -36,7 +36,7 @@ class LightCullingPass : public RenderPass {
Gfx::PDescriptorSet viewParamsSet; Gfx::PDescriptorSet viewParamsSet;
PLightEnvironment lightEnv; PLightEnvironment lightEnv;
Gfx::PTexture2D depthAttachment; Gfx::PTextureView depthAttachment;
constexpr static const char* DEPTHATTACHMENT_NAME = "depth"; constexpr static const char* DEPTHATTACHMENT_NAME = "depth";
Gfx::OShaderBuffer oLightIndexCounter; Gfx::OShaderBuffer oLightIndexCounter;
constexpr static const char* OLIGHTINDEXCOUNTER_NAME = "oLightIndexCounter"; constexpr static const char* OLIGHTINDEXCOUNTER_NAME = "oLightIndexCounter";
@@ -153,10 +153,10 @@ void RayTracingPass::render() {
}); });
Gfx::PDescriptorSet desc = paramsLayout->allocateDescriptorSet(); Gfx::PDescriptorSet desc = paramsLayout->allocateDescriptorSet();
desc->updateAccelerationStructure(TLAS_NAME, 0, tlas); desc->updateAccelerationStructure(TLAS_NAME, 0, tlas);
desc->updateTexture(ACCUMULATOR_NAME, 0, Gfx::PTexture2D(radianceAccumulator)); desc->updateTexture(ACCUMULATOR_NAME, 0, radianceAccumulator->getDefaultView());
desc->updateTexture(TEXTURE_NAME, 0, Gfx::PTexture2D(texture)); desc->updateTexture(TEXTURE_NAME, 0, texture->getDefaultView());
desc->updateBuffer(INDEXBUFFER_NAME, 0, StaticMeshVertexData::getInstance()->getIndexBuffer()); desc->updateBuffer(INDEXBUFFER_NAME, 0, StaticMeshVertexData::getInstance()->getIndexBuffer());
desc->updateTexture(SKYBOX_NAME, 0, skyBox); desc->updateTexture(SKYBOX_NAME, 0, skyBox->getDefaultView());
desc->updateSampler(SKYSAMPLER_NAME, 0, skyBoxSampler); desc->updateSampler(SKYSAMPLER_NAME, 0, skyBoxSampler);
desc->writeChanges(); desc->writeChanges();
@@ -210,7 +210,7 @@ void RayTracingPass::publishOutputs() {
texture->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, texture->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR); Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR);
resources->registerRenderPassOutput("BASEPASS_COLOR", Gfx::RenderTargetAttachment(texture, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, resources->registerRenderPassOutput("BASEPASS_COLOR", Gfx::RenderTargetAttachment(texture->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED,
Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)); Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
ShaderCompilationInfo compileInfo = { ShaderCompilationInfo compileInfo = {
.name = "RayGenMiss", .name = "RayGenMiss",
@@ -51,7 +51,7 @@ void ShadowPass::render() {
Array<Gfx::ORenderCommand> commands; Array<Gfx::ORenderCommand> commands;
renderPass = graphics->createRenderPass( renderPass = graphics->createRenderPass(
Gfx::RenderTargetLayout{ Gfx::RenderTargetLayout{
.depthAttachment = Gfx::RenderTargetAttachment(shadowMaps[shadowIndex], Gfx::SE_IMAGE_LAYOUT_UNDEFINED, .depthAttachment = Gfx::RenderTargetAttachment(shadowMaps[shadowIndex]->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED,
Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE), Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE),
@@ -129,7 +129,7 @@ void ToneMappingPass::beginFrame(const Component::Camera& cam, const Component::
void ToneMappingPass::render() { void ToneMappingPass::render() {
graphics->beginDebugRegion("ToneMapping"); graphics->beginDebugRegion("ToneMapping");
hdrInputTexture.getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, hdrInputTexture.getTextureView()->changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
@@ -139,7 +139,7 @@ void ToneMappingPass::render() {
histogramSet->updateConstants("inverseLogLumRange", 0, &inverseLogLumRange); histogramSet->updateConstants("inverseLogLumRange", 0, &inverseLogLumRange);
histogramSet->updateConstants("timeCoeff", 0, &timeCoeff); histogramSet->updateConstants("timeCoeff", 0, &timeCoeff);
histogramSet->updateConstants("numPixels", 0, &numPixels); histogramSet->updateConstants("numPixels", 0, &numPixels);
histogramSet->updateTexture("hdrImage", 0, hdrInputTexture.getTexture()); histogramSet->updateTexture("hdrImage", 0, hdrInputTexture.getTextureView());
histogramSet->updateBuffer("histogram", 0, histogramBuffer); histogramSet->updateBuffer("histogram", 0, histogramBuffer);
histogramSet->updateBuffer("averageLuminance", 0, luminanceBuffer); histogramSet->updateBuffer("averageLuminance", 0, luminanceBuffer);
histogramSet->writeChanges(); histogramSet->writeChanges();
@@ -172,7 +172,7 @@ void ToneMappingPass::render() {
tonemappingSet->updateConstants("slope", 0, &slope); tonemappingSet->updateConstants("slope", 0, &slope);
tonemappingSet->updateConstants("power", 0, &power); tonemappingSet->updateConstants("power", 0, &power);
tonemappingSet->updateConstants("sat", 0, &sat); tonemappingSet->updateConstants("sat", 0, &sat);
tonemappingSet->updateTexture("hdrInputTexture", 0, hdrInputTexture.getTexture()); tonemappingSet->updateTexture("hdrInputTexture", 0, hdrInputTexture.getTextureView());
tonemappingSet->updateSampler("hdrSampler", 0, sampler); tonemappingSet->updateSampler("hdrSampler", 0, sampler);
tonemappingSet->updateBuffer("averageLuminance", 0, luminanceBuffer); tonemappingSet->updateBuffer("averageLuminance", 0, luminanceBuffer);
tonemappingSet->writeChanges(); tonemappingSet->writeChanges();
+3 -3
View File
@@ -87,7 +87,7 @@ void UIPass::beginFrame(const Component::Camera& cam, const Component::Transform
textDescriptorSet->updateBuffer(GLYPHINSTANCE_NAME, 0, glyphInstanceBuffer); textDescriptorSet->updateBuffer(GLYPHINSTANCE_NAME, 0, glyphInstanceBuffer);
textDescriptorSet->updateSampler(GLYPHSAMPLER_NAME, 0, glyphSampler); textDescriptorSet->updateSampler(GLYPHSAMPLER_NAME, 0, glyphSampler);
for (uint32 i = 0; i < usedTextures.size(); ++i) { for (uint32 i = 0; i < usedTextures.size(); ++i) {
textDescriptorSet->updateTexture(TEXTURES_NAME, i, usedTextures[i]); textDescriptorSet->updateTexture(TEXTURES_NAME, i, usedTextures[i]->getDefaultView());
} }
textDescriptorSet->writeChanges(); textDescriptorSet->writeChanges();
@@ -100,7 +100,7 @@ void UIPass::beginFrame(const Component::Camera& cam, const Component::Transform
uiDescriptorSet->updateBuffer(ELEMENT_NAME, 0, elementBuffer); uiDescriptorSet->updateBuffer(ELEMENT_NAME, 0, elementBuffer);
uiDescriptorSet->updateSampler(GLYPHSAMPLER_NAME, 0, glyphSampler); uiDescriptorSet->updateSampler(GLYPHSAMPLER_NAME, 0, glyphSampler);
for (uint32 i = 0; i < usedTextures.size(); ++i) { for (uint32 i = 0; i < usedTextures.size(); ++i) {
uiDescriptorSet->updateTexture(TEXTURES_NAME, i, usedTextures[i]); uiDescriptorSet->updateTexture(TEXTURES_NAME, i, usedTextures[i]->getDefaultView());
} }
uiDescriptorSet->writeChanges(); uiDescriptorSet->writeChanges();
} }
@@ -132,7 +132,7 @@ void UIPass::createRenderPass() {
depthBuffer = graphics->createTexture2D(depthBufferInfo); depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment = depthAttachment =
Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, Gfx::RenderTargetAttachment(depthBuffer->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment.clear.depthStencil.depth = 0; depthAttachment.clear.depthStencil.depth = 0;
@@ -23,7 +23,7 @@ void VisibilityPass::render() {
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
visibilityDescriptor->reset(); visibilityDescriptor->reset();
visibilitySet = visibilityDescriptor->allocateDescriptorSet(); visibilitySet = visibilityDescriptor->allocateDescriptorSet();
visibilitySet->updateTexture(VISIBILITY_NAME, 0, visibilityAttachment.getTexture()); visibilitySet->updateTexture(VISIBILITY_NAME, 0, visibilityAttachment.getTextureView());
visibilitySet->updateBuffer(CULLINGBUFFER_NAME, 0, cullingBuffer); visibilitySet->updateBuffer(CULLINGBUFFER_NAME, 0, cullingBuffer);
visibilitySet->writeChanges(); visibilitySet->writeChanges();
+1 -7
View File
@@ -3,19 +3,13 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Gfx; using namespace Seele::Gfx;
RenderTargetAttachment::RenderTargetAttachment(PTexture2D texture, SeImageLayout initialLayout, SeImageLayout finalLayout, RenderTargetAttachment::RenderTargetAttachment(PTextureView texture, SeImageLayout initialLayout, SeImageLayout finalLayout,
SeAttachmentLoadOp loadOp, SeAttachmentStoreOp storeOp, SeAttachmentLoadOp stencilLoadOp, SeAttachmentLoadOp loadOp, SeAttachmentStoreOp storeOp, SeAttachmentLoadOp stencilLoadOp,
SeAttachmentStoreOp stencilStoreOp) SeAttachmentStoreOp stencilStoreOp)
: componentFlags(0), texture(texture), initialLayout(initialLayout), finalLayout(finalLayout), : componentFlags(0), texture(texture), initialLayout(initialLayout), finalLayout(finalLayout),
loadOp(loadOp), loadOp(loadOp),
storeOp(storeOp), stencilLoadOp(stencilLoadOp), stencilStoreOp(stencilStoreOp) {} storeOp(storeOp), stencilLoadOp(stencilLoadOp), stencilStoreOp(stencilStoreOp) {}
RenderTargetAttachment::RenderTargetAttachment(PTextureCube texture, SeImageLayout initialLayout, SeImageLayout finalLayout,
SeAttachmentLoadOp loadOp, SeAttachmentStoreOp storeOp, SeAttachmentLoadOp stencilLoadOp,
SeAttachmentStoreOp stencilStoreOp)
: componentFlags(0), texture(texture), initialLayout(initialLayout), finalLayout(finalLayout), loadOp(loadOp),
storeOp(storeOp), stencilLoadOp(stencilLoadOp), stencilStoreOp(stencilStoreOp) {}
RenderTargetAttachment::RenderTargetAttachment(PViewport viewport, SeImageLayout initialLayout, SeImageLayout finalLayout, RenderTargetAttachment::RenderTargetAttachment(PViewport viewport, SeImageLayout initialLayout, SeImageLayout finalLayout,
SeAttachmentLoadOp loadOp, SeAttachmentStoreOp storeOp, SeAttachmentLoadOp stencilLoadOp, SeAttachmentLoadOp loadOp, SeAttachmentStoreOp storeOp, SeAttachmentLoadOp stencilLoadOp,
SeAttachmentStoreOp stencilStoreOp) SeAttachmentStoreOp stencilStoreOp)
+5 -10
View File
@@ -9,12 +9,7 @@ namespace Gfx {
class RenderTargetAttachment { class RenderTargetAttachment {
public: public:
RenderTargetAttachment() {} RenderTargetAttachment() {}
RenderTargetAttachment(PTexture2D texture, SeImageLayout initialLayout, SeImageLayout finalLayout, RenderTargetAttachment(PTextureView texture, SeImageLayout initialLayout, SeImageLayout finalLayout,
SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_LOAD,
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE);
RenderTargetAttachment(PTextureCube texture, SeImageLayout initialLayout, SeImageLayout finalLayout,
SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_LOAD, SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_LOAD,
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE, SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE, SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
@@ -25,10 +20,10 @@ class RenderTargetAttachment {
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE, SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE); SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE);
~RenderTargetAttachment(); ~RenderTargetAttachment();
void setTexture(PTexture _texture) { texture = _texture; } void setTextureView(PTextureView _texture) { texture = _texture; }
PTexture getTexture() const { PTextureView getTextureView() const {
if (viewport != nullptr) { if (viewport != nullptr) {
return PTexture(viewport->getOwner()->getBackBuffer()); return PTextureView(viewport->getOwner()->getBackBuffer()->getDefaultView());
} }
return texture; return texture;
} }
@@ -73,7 +68,7 @@ class RenderTargetAttachment {
SeColorComponentFlags componentFlags = 0; SeColorComponentFlags componentFlags = 0;
protected: protected:
PTexture texture = nullptr; PTextureView texture = nullptr;
PViewport viewport = nullptr; PViewport viewport = nullptr;
SeImageLayout initialLayout = SE_IMAGE_LAYOUT_UNDEFINED; SeImageLayout initialLayout = SE_IMAGE_LAYOUT_UNDEFINED;
SeImageLayout finalLayout = SE_IMAGE_LAYOUT_UNDEFINED; SeImageLayout finalLayout = SE_IMAGE_LAYOUT_UNDEFINED;
+4
View File
@@ -4,6 +4,10 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Gfx; using namespace Seele::Gfx;
TextureView::TextureView() {}
TextureView::~TextureView() {}
Texture::Texture(QueueFamilyMapping mapping) : QueueOwnedResource(mapping) {} Texture::Texture(QueueFamilyMapping mapping) : QueueOwnedResource(mapping) {}
Texture::~Texture() {} Texture::~Texture() {}
+29
View File
@@ -3,6 +3,25 @@
namespace Seele { namespace Seele {
namespace Gfx { namespace Gfx {
class TextureView {
public:
TextureView();
virtual ~TextureView();
virtual SeFormat getFormat() const = 0;
virtual uint32 getWidth() const = 0;
virtual uint32 getHeight() const = 0;
virtual uint32 getDepth() const = 0;
virtual uint32 getNumLayers() const = 0;
virtual SeSampleCountFlags getNumSamples() const = 0;
virtual uint32 getMipLevels() const = 0;
virtual void changeLayout(SeImageLayout newLayout, SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess,
SePipelineStageFlags dstStage) = 0;
virtual void pipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, SePipelineStageFlags dstStage) = 0;
private:
};
DEFINE_REF(TextureView)
class Texture : public QueueOwnedResource { class Texture : public QueueOwnedResource {
public: public:
Texture(QueueFamilyMapping mapping); Texture(QueueFamilyMapping mapping);
@@ -12,12 +31,16 @@ class Texture : public QueueOwnedResource {
virtual uint32 getWidth() const = 0; virtual uint32 getWidth() const = 0;
virtual uint32 getHeight() const = 0; virtual uint32 getHeight() const = 0;
virtual uint32 getDepth() const = 0; virtual uint32 getDepth() const = 0;
virtual uint32 getNumLayers() const = 0;
virtual SeSampleCountFlags getNumSamples() const = 0; virtual SeSampleCountFlags getNumSamples() const = 0;
virtual uint32 getMipLevels() const = 0; virtual uint32 getMipLevels() const = 0;
virtual void changeLayout(SeImageLayout newLayout, SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, virtual void changeLayout(SeImageLayout newLayout, SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess,
SePipelineStageFlags dstStage) = 0; SePipelineStageFlags dstStage) = 0;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) = 0; virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) = 0;
virtual void generateMipmaps() = 0; virtual void generateMipmaps() = 0;
virtual PTextureView getDefaultView() const = 0;
virtual OTextureView createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount) = 0;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(QueueType newOwner) = 0; virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
@@ -41,7 +64,9 @@ class Texture2D : public Texture {
virtual void changeLayout(SeImageLayout newLayout, SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, virtual void changeLayout(SeImageLayout newLayout, SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess,
SePipelineStageFlags dstStage) = 0; SePipelineStageFlags dstStage) = 0;
virtual void generateMipmaps() = 0; virtual void generateMipmaps() = 0;
virtual PTextureView getDefaultView() const = 0;
virtual OTextureView createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount) = 0;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(QueueType newOwner) = 0; virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
@@ -65,6 +90,8 @@ class Texture3D : public Texture {
virtual void changeLayout(SeImageLayout newLayout, SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, virtual void changeLayout(SeImageLayout newLayout, SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess,
SePipelineStageFlags dstStage) = 0; SePipelineStageFlags dstStage) = 0;
virtual void generateMipmaps() = 0; virtual void generateMipmaps() = 0;
virtual PTextureView getDefaultView() const = 0;
virtual OTextureView createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount) = 0;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
@@ -89,6 +116,8 @@ class TextureCube : public Texture {
virtual void changeLayout(SeImageLayout newLayout, SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, virtual void changeLayout(SeImageLayout newLayout, SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess,
SePipelineStageFlags dstStage) = 0; SePipelineStageFlags dstStage) = 0;
virtual void generateMipmaps() = 0; virtual void generateMipmaps() = 0;
virtual PTextureView getDefaultView() const = 0;
virtual OTextureView createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount) = 0;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
+4 -4
View File
@@ -325,11 +325,11 @@ void DescriptorSet::updateSampler(const std::string& mappingName, uint32 index,
boundResources[binding][index] = vulkanSampler->getHandle(); boundResources[binding][index] = vulkanSampler->getHandle();
} }
void DescriptorSet::updateTexture(const std::string& mappingName, uint32 index, Gfx::PTexture texture) { void DescriptorSet::updateTexture(const std::string& mappingName, uint32 index, Gfx::PTextureView texture) {
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle(); PTextureView vulkanTexture = texture.cast<TextureView>();
const auto& map = owner->getLayout()->mappings[mappingName]; const auto& map = owner->getLayout()->mappings[mappingName];
uint32 binding = map.binding; uint32 binding = map.binding;
if (boundResources[binding][index] == vulkanTexture->getHandle()) { if (boundResources[binding][index] == vulkanTexture->getSource()) {
return; return;
} }
@@ -350,7 +350,7 @@ void DescriptorSet::updateTexture(const std::string& mappingName, uint32 index,
.pImageInfo = &imageInfos.back(), .pImageInfo = &imageInfos.back(),
}); });
boundResources[binding][index] = vulkanTexture->getHandle(); boundResources[binding][index] = vulkanTexture->getSource();
} }
void DescriptorSet::updateAccelerationStructure(const std::string& mappingName, uint32 index, Gfx::PTopLevelAS as) { void DescriptorSet::updateAccelerationStructure(const std::string& mappingName, uint32 index, Gfx::PTopLevelAS as) {
+1 -1
View File
@@ -64,7 +64,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer indexBuffer) override; virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer indexBuffer) override;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer indexBuffer) override; virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer indexBuffer) override;
virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) override; virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) override;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture texture) override; virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTextureView texture) override;
virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) override; virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) override;
constexpr VkDescriptorSet getHandle() const { return setHandle; } constexpr VkDescriptorSet getHandle() const { return setHandle; }
+7 -7
View File
@@ -17,7 +17,7 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render
uint32 height = 0; uint32 height = 0;
uint32 layers = 0; uint32 layers = 0;
for (auto inputAttachment : layout.inputAttachments) { for (auto inputAttachment : layout.inputAttachments) {
PTextureBase vkInputAttachment = inputAttachment.getTexture().cast<TextureBase>(); PTextureView vkInputAttachment = inputAttachment.getTextureView();
attachments.add(vkInputAttachment->getView()); attachments.add(vkInputAttachment->getView());
description.inputAttachments[description.numInputAttachments++] = vkInputAttachment->getView(); description.inputAttachments[description.numInputAttachments++] = vkInputAttachment->getView();
width = std::max(width, vkInputAttachment->getWidth()); width = std::max(width, vkInputAttachment->getWidth());
@@ -25,7 +25,7 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render
layers = std::max(layers, vkInputAttachment->getNumLayers()); layers = std::max(layers, vkInputAttachment->getNumLayers());
} }
for (auto colorAttachment : layout.colorAttachments) { for (auto colorAttachment : layout.colorAttachments) {
PTextureBase vkColorAttachment = colorAttachment.getTexture().cast<TextureBase>(); PTextureView vkColorAttachment = colorAttachment.getTextureView();
attachments.add(vkColorAttachment->getView()); attachments.add(vkColorAttachment->getView());
description.colorAttachments[description.numColorAttachments++] = vkColorAttachment->getView(); description.colorAttachments[description.numColorAttachments++] = vkColorAttachment->getView();
width = std::max(width, vkColorAttachment->getWidth()); width = std::max(width, vkColorAttachment->getWidth());
@@ -33,23 +33,23 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render
layers = std::max(layers, vkColorAttachment->getNumLayers()); layers = std::max(layers, vkColorAttachment->getNumLayers());
} }
for (auto resolveAttachment : layout.resolveAttachments) { for (auto resolveAttachment : layout.resolveAttachments) {
PTextureBase vkResolveAttachment = resolveAttachment.getTexture().cast<TextureBase>(); PTextureView vkResolveAttachment = resolveAttachment.getTextureView();
attachments.add(vkResolveAttachment->getView()); attachments.add(vkResolveAttachment->getView());
description.resolveAttachments[description.numResolveAttachments++] = vkResolveAttachment->getView(); description.resolveAttachments[description.numResolveAttachments++] = vkResolveAttachment->getView();
width = std::max(width, vkResolveAttachment->getWidth()); width = std::max(width, vkResolveAttachment->getWidth());
height = std::max(height, vkResolveAttachment->getHeight()); height = std::max(height, vkResolveAttachment->getHeight());
layers = std::max(layers, vkResolveAttachment->getNumLayers()); layers = std::max(layers, vkResolveAttachment->getNumLayers());
} }
if (layout.depthAttachment.getTexture() != nullptr) { if (layout.depthAttachment.getTextureView() != nullptr) {
PTextureBase vkDepthAttachment = layout.depthAttachment.getTexture().cast<TextureBase>(); PTextureView vkDepthAttachment = layout.depthAttachment.getTextureView();
attachments.add(vkDepthAttachment->getView()); attachments.add(vkDepthAttachment->getView());
description.depthAttachment = vkDepthAttachment->getView(); description.depthAttachment = vkDepthAttachment->getView();
width = std::max(width, vkDepthAttachment->getWidth()); width = std::max(width, vkDepthAttachment->getWidth());
height = std::max(height, vkDepthAttachment->getHeight()); height = std::max(height, vkDepthAttachment->getHeight());
layers = std::max(layers, vkDepthAttachment->getNumLayers()); layers = std::max(layers, vkDepthAttachment->getNumLayers());
} }
if (layout.depthResolveAttachment.getTexture() != nullptr) { if (layout.depthResolveAttachment.getTextureView() != nullptr) {
PTextureBase vkDepthAttachment = layout.depthResolveAttachment.getTexture().cast<TextureBase>(); PTextureView vkDepthAttachment = layout.depthResolveAttachment.getTextureView();
attachments.add(vkDepthAttachment->getView()); attachments.add(vkDepthAttachment->getView());
description.depthResolveAttachment = vkDepthAttachment->getView(); description.depthResolveAttachment = vkDepthAttachment->getView();
width = std::max(width, vkDepthAttachment->getWidth()); width = std::max(width, vkDepthAttachment->getWidth());
+22 -22
View File
@@ -22,7 +22,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra
uint32 attachmentCounter = 0; uint32 attachmentCounter = 0;
for (auto& inputAttachment : layout.inputAttachments) { for (auto& inputAttachment : layout.inputAttachments) {
PTexture2D image = inputAttachment.getTexture().cast<Texture2D>(); PTextureView image = inputAttachment.getTextureView();
VkAttachmentDescription2& desc = attachments.add() = { VkAttachmentDescription2& desc = attachments.add() = {
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2, .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2,
.pNext = nullptr, .pNext = nullptr,
@@ -74,7 +74,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra
.pNext = nullptr, .pNext = nullptr,
.flags = 0, .flags = 0,
.format = cast(resolveAttachment.getFormat()), .format = cast(resolveAttachment.getFormat()),
.samples = (VkSampleCountFlagBits)resolveAttachment.getTexture()->getNumSamples(), .samples = (VkSampleCountFlagBits)resolveAttachment.getTextureView()->getNumSamples(),
.loadOp = cast(resolveAttachment.getLoadOp()), .loadOp = cast(resolveAttachment.getLoadOp()),
.storeOp = cast(resolveAttachment.getStoreOp()), .storeOp = cast(resolveAttachment.getStoreOp()),
.stencilLoadOp = cast(resolveAttachment.getStencilLoadOp()), .stencilLoadOp = cast(resolveAttachment.getStencilLoadOp()),
@@ -95,8 +95,8 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra
.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
}; };
} }
if (layout.depthAttachment.getTexture() != nullptr) { if (layout.depthAttachment.getTextureView() != nullptr) {
PTexture2D image = layout.depthAttachment.getTexture().cast<Texture2D>(); PTextureView image = layout.depthAttachment.getTextureView();
attachments.add() = { attachments.add() = {
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2, .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2,
.pNext = nullptr, .pNext = nullptr,
@@ -123,8 +123,8 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra
.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, .layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
}; };
} }
if (layout.depthResolveAttachment.getTexture() != nullptr) { if (layout.depthResolveAttachment.getTextureView() != nullptr) {
PTexture2D image = layout.depthResolveAttachment.getTexture().cast<Texture2D>(); PTextureView image = layout.depthResolveAttachment.getTextureView();
attachments.add() = { attachments.add() = {
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2, .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2,
.pNext = nullptr, .pNext = nullptr,
@@ -159,7 +159,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra
}; };
VkSubpassDescription2 subPassDesc = { VkSubpassDescription2 subPassDesc = {
.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2, .sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2,
.pNext = layout.depthResolveAttachment.getTexture() != nullptr ? &depthResolve : nullptr, .pNext = layout.depthResolveAttachment.getTextureView() != nullptr ? &depthResolve : nullptr,
.flags = 0, .flags = 0,
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
.viewMask = viewMasks[0], .viewMask = viewMasks[0],
@@ -168,7 +168,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra
.colorAttachmentCount = (uint32)colorRefs.size(), .colorAttachmentCount = (uint32)colorRefs.size(),
.pColorAttachments = colorRefs.data(), .pColorAttachments = colorRefs.data(),
.pResolveAttachments = resolveRefs.size() > 0 ? resolveRefs.data() : nullptr, .pResolveAttachments = resolveRefs.size() > 0 ? resolveRefs.data() : nullptr,
.pDepthStencilAttachment = layout.depthAttachment.getTexture() != nullptr ? &depthRef : nullptr, .pDepthStencilAttachment = layout.depthAttachment.getTextureView() != nullptr ? &depthRef : nullptr,
}; };
Array<VkSubpassDependency2> dep; Array<VkSubpassDependency2> dep;
for (const auto& d : dependencies) { for (const auto& d : dependencies) {
@@ -217,23 +217,23 @@ RenderPass::~RenderPass() {
uint32 RenderPass::getFramebufferHash() { uint32 RenderPass::getFramebufferHash() {
FramebufferDescription description; FramebufferDescription description;
for (auto& inputAttachment : layout.inputAttachments) { for (auto& inputAttachment : layout.inputAttachments) {
PTextureBase tex = inputAttachment.getTexture().cast<TextureBase>(); PTextureView tex = inputAttachment.getTextureView();
description.inputAttachments[description.numInputAttachments++] = tex->getView(); description.inputAttachments[description.numInputAttachments++] = tex->getView();
} }
for (auto& colorAttachment : layout.colorAttachments) { for (auto& colorAttachment : layout.colorAttachments) {
PTextureBase tex = colorAttachment.getTexture().cast<TextureBase>(); PTextureView tex = colorAttachment.getTextureView();
description.colorAttachments[description.numColorAttachments++] = tex->getView(); description.colorAttachments[description.numColorAttachments++] = tex->getView();
} }
for (auto& resolveAttachment : layout.resolveAttachments) { for (auto& resolveAttachment : layout.resolveAttachments) {
PTextureBase tex = resolveAttachment.getTexture().cast<TextureBase>(); PTextureView tex = resolveAttachment.getTextureView();
description.resolveAttachments[description.numResolveAttachments++] = tex->getView(); description.resolveAttachments[description.numResolveAttachments++] = tex->getView();
} }
if (layout.depthAttachment.getTexture() != nullptr) { if (layout.depthAttachment.getTextureView() != nullptr) {
PTextureBase tex = layout.depthAttachment.getTexture().cast<TextureBase>(); PTextureView tex = layout.depthAttachment.getTextureView();
description.depthAttachment = tex->getView(); description.depthAttachment = tex->getView();
} }
if (layout.depthResolveAttachment.getTexture() != nullptr) { if (layout.depthResolveAttachment.getTextureView() != nullptr) {
PTextureBase tex = layout.depthResolveAttachment.getTexture().cast<TextureBase>(); PTextureView tex = layout.depthResolveAttachment.getTextureView();
description.depthResolveAttachment = tex->getView(); description.depthResolveAttachment = tex->getView();
} }
return CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32()); return CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32());
@@ -241,23 +241,23 @@ uint32 RenderPass::getFramebufferHash() {
void RenderPass::endRenderPass() { void RenderPass::endRenderPass() {
for (auto& inputAttachment : layout.inputAttachments) { for (auto& inputAttachment : layout.inputAttachments) {
PTextureBase tex = inputAttachment.getTexture().cast<TextureBase>(); PTextureView tex = inputAttachment.getTextureView();
tex->setLayout(inputAttachment.getFinalLayout()); tex->setLayout(inputAttachment.getFinalLayout());
} }
for (auto& colorAttachment : layout.colorAttachments) { for (auto& colorAttachment : layout.colorAttachments) {
PTextureBase tex = colorAttachment.getTexture().cast<TextureBase>(); PTextureView tex = colorAttachment.getTextureView();
tex->setLayout(colorAttachment.getFinalLayout()); tex->setLayout(colorAttachment.getFinalLayout());
} }
for (auto& resolveAttachment : layout.resolveAttachments) { for (auto& resolveAttachment : layout.resolveAttachments) {
PTextureBase tex = resolveAttachment.getTexture().cast<TextureBase>(); PTextureView tex = resolveAttachment.getTextureView();
tex->setLayout(resolveAttachment.getFinalLayout()); tex->setLayout(resolveAttachment.getFinalLayout());
} }
if (layout.depthAttachment.getTexture() != nullptr) { if (layout.depthAttachment.getTextureView() != nullptr) {
PTextureBase tex = layout.depthAttachment.getTexture().cast<TextureBase>(); PTextureView tex = layout.depthAttachment.getTextureView();
tex->setLayout(layout.depthAttachment.getFinalLayout()); tex->setLayout(layout.depthAttachment.getFinalLayout());
} }
if (layout.depthResolveAttachment.getTexture() != nullptr) { if (layout.depthResolveAttachment.getTextureView() != nullptr) {
PTextureBase tex = layout.depthResolveAttachment.getTexture().cast<TextureBase>(); PTextureView tex = layout.depthResolveAttachment.getTextureView();
tex->setLayout(layout.depthResolveAttachment.getFinalLayout()); tex->setLayout(layout.depthResolveAttachment.getFinalLayout());
} }
} }
+77 -5
View File
@@ -28,11 +28,65 @@ VkImageAspectFlags getAspectFromFormat(Gfx::SeFormat format) {
} }
} }
TextureView::TextureView(PTextureHandle source, VkImageView view) : source(source), view(view) {}
TextureView::~TextureView() {}
Gfx::SeFormat TextureView::getFormat() const { return source->format; }
uint32 TextureView::getWidth() const { return source->width; }
uint32 TextureView::getHeight() const { return source->height; }
uint32 TextureView::getDepth() const { return source->depth; }
uint32 TextureView::getNumLayers() const { return source->layerCount; }
Gfx::SeSampleCountFlags TextureView::getNumSamples() const { return source->samples; }
uint32 TextureView::getMipLevels() const { return source->mipLevels; }
Gfx::SeImageLayout TextureView::getLayout() const { return source->layout; }
void TextureView::pipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess,
VkPipelineStageFlags dstStage) {
return source->pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
}
void TextureView::changeLayout(Gfx::SeImageLayout newLayout, VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) {
return source->changeLayout(newLayout, srcAccess, srcStage, dstAccess, dstStage);
}
void TextureView::setLayout(Gfx::SeImageLayout layout) { source->layout = layout; }
Gfx::OTextureView TextureHandle::createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount) {
VkImageView view;
VkImageViewCreateInfo createInfo = {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.image = image,
.viewType = viewType,
.format = cast(format),
.subresourceRange =
{
.aspectMask = aspect,
.baseMipLevel = baseMipLevel,
.levelCount = levelCount,
.baseArrayLayer = baseArrayLayer,
.layerCount = layerCount,
},
};
vkCreateImageView(graphics->getDevice(), &createInfo, nullptr, &view);
return new TextureView(this, view);
}
TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage) TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage)
: CommandBoundResource(graphics, createInfo.name), image(existingImage), imageView(VK_NULL_HANDLE), allocation(nullptr), : CommandBoundResource(graphics, createInfo.name), image(existingImage), imageView(VK_NULL_HANDLE), allocation(nullptr),
owner(createInfo.sourceData.owner), width(createInfo.width), height(createInfo.height), depth(createInfo.depth), owner(createInfo.sourceData.owner), width(createInfo.width), height(createInfo.height), depth(createInfo.depth),
layerCount(createInfo.elements), mipLevels(1), samples(createInfo.samples), format(createInfo.format), layerCount(createInfo.elements), mipLevels(1), samples(createInfo.samples), format(createInfo.format), usage(createInfo.usage),
usage(createInfo.usage), layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED), aspect(getAspectFromFormat(createInfo.format)), ownsImage(false) { layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED), aspect(getAspectFromFormat(createInfo.format)), viewType(viewType), ownsImage(false) {
if (createInfo.useMip) { if (createInfo.useMip) {
mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1; mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1;
} }
@@ -151,7 +205,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
graphics->getDestructionManager()->queueResourceForDestruction(std::move(stagingAlloc)); graphics->getDestructionManager()->queueResourceForDestruction(std::move(stagingAlloc));
} }
} }
VkImageView view;
VkImageViewCreateInfo viewInfo = { VkImageViewCreateInfo viewInfo = {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
@@ -167,11 +221,11 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
}, },
}; };
VK_CHECK(vkCreateImageView(graphics->getDevice(), &viewInfo, nullptr, &imageView)); VK_CHECK(vkCreateImageView(graphics->getDevice(), &viewInfo, nullptr, &view));
imageView = new TextureView(this, view);
} }
TextureHandle::~TextureHandle() { TextureHandle::~TextureHandle() {
vkDestroyImageView(graphics->getDevice(), imageView, nullptr);
if (ownsImage) { if (ownsImage) {
vmaDestroyImage(graphics->getAllocator(), image, allocation); vmaDestroyImage(graphics->getAllocator(), image, allocation);
} }
@@ -422,6 +476,12 @@ void Texture2D::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<
void Texture2D::generateMipmaps() { TextureBase::generateMipmaps(); } void Texture2D::generateMipmaps() { TextureBase::generateMipmaps(); }
Gfx::PTextureView Texture2D::getDefaultView() const { return PTextureView(handle->imageView); }
Gfx::OTextureView Texture2D::createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount) {
return handle->createTextureView(baseMipLevel, levelCount, baseArrayLayer, layerCount);
}
void Texture2D::executeOwnershipBarrier(Gfx::QueueType newOwner) { TextureBase::transferOwnership(newOwner); } void Texture2D::executeOwnershipBarrier(Gfx::QueueType newOwner) { TextureBase::transferOwnership(newOwner); }
void Texture2D::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess, void Texture2D::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess,
@@ -445,6 +505,12 @@ void Texture3D::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<
void Texture3D::generateMipmaps() { TextureBase::generateMipmaps(); } void Texture3D::generateMipmaps() { TextureBase::generateMipmaps(); }
Gfx::PTextureView Texture3D::getDefaultView() const { return PTextureView(handle->imageView); }
Gfx::OTextureView Texture3D::createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount) {
return handle->createTextureView(baseMipLevel, levelCount, baseArrayLayer, layerCount);
}
void Texture3D::executeOwnershipBarrier(Gfx::QueueType newOwner) { TextureBase::transferOwnership(newOwner); } void Texture3D::executeOwnershipBarrier(Gfx::QueueType newOwner) { TextureBase::transferOwnership(newOwner); }
void Texture3D::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess, void Texture3D::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess,
@@ -469,6 +535,12 @@ void TextureCube::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Arra
void TextureCube::generateMipmaps() { TextureBase::generateMipmaps(); } void TextureCube::generateMipmaps() { TextureBase::generateMipmaps(); }
Gfx::PTextureView TextureCube::getDefaultView() const { return PTextureView(handle->imageView); }
Gfx::OTextureView TextureCube::createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount) {
return handle->createTextureView(baseMipLevel, levelCount, baseArrayLayer, layerCount);
}
void TextureCube::executeOwnershipBarrier(Gfx::QueueType newOwner) { TextureBase::transferOwnership(newOwner); } void TextureCube::executeOwnershipBarrier(Gfx::QueueType newOwner) { TextureBase::transferOwnership(newOwner); }
void TextureCube::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess, void TextureCube::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess,
+37 -2
View File
@@ -8,6 +8,32 @@
namespace Seele { namespace Seele {
namespace Vulkan { namespace Vulkan {
DECLARE_REF(TextureHandle)
class TextureView : public Gfx::TextureView {
public:
TextureView(PTextureHandle source, VkImageView view);
virtual ~TextureView();
virtual Gfx::SeFormat getFormat() const override;
virtual uint32 getWidth() const override;
virtual uint32 getHeight() const override;
virtual uint32 getDepth() const override;
virtual uint32 getNumLayers() const override;
virtual Gfx::SeSampleCountFlags getNumSamples() const override;
virtual uint32 getMipLevels() const override;
virtual void pipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) override;
virtual void changeLayout(Gfx::SeImageLayout newLayout, VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess,
VkPipelineStageFlags dstStage) override;
VkImageView getView() const { return view; }
Gfx::SeImageLayout getLayout() const;
PTextureHandle getSource() const { return source; }
void setLayout(Gfx::SeImageLayout layout);
private:
PTextureHandle source;
VkImageView view;
friend class TextureBase;
};
DEFINE_REF(TextureView)
class TextureHandle : public CommandBoundResource { class TextureHandle : public CommandBoundResource {
public: public:
TextureHandle(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage); TextureHandle(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage);
@@ -18,8 +44,10 @@ class TextureHandle : public CommandBoundResource {
VkPipelineStageFlags dstStage); VkPipelineStageFlags dstStage);
void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer); void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer);
void generateMipmaps(); void generateMipmaps();
Gfx::OTextureView createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount);
VkImage image; VkImage image;
VkImageView imageView; OTextureView imageView;
VmaAllocation allocation; VmaAllocation allocation;
Gfx::QueueType owner; Gfx::QueueType owner;
uint32 width; uint32 width;
@@ -32,6 +60,7 @@ class TextureHandle : public CommandBoundResource {
Gfx::SeImageUsageFlags usage; Gfx::SeImageUsageFlags usage;
Gfx::SeImageLayout layout; Gfx::SeImageLayout layout;
VkImageAspectFlags aspect; VkImageAspectFlags aspect;
VkImageViewType viewType;
uint8 ownsImage; uint8 ownsImage;
}; };
DEFINE_REF(TextureHandle) DEFINE_REF(TextureHandle)
@@ -50,7 +79,7 @@ class TextureBase {
uint32 getNumLayers() const { return handle->layerCount; } uint32 getNumLayers() const { return handle->layerCount; }
PTextureHandle getHandle() const { return handle; } PTextureHandle getHandle() const { return handle; }
VkImage getImage() const { return handle->image; }; VkImage getImage() const { return handle->image; };
VkImageView getView() const { return handle->imageView; }; VkImageView getView() const { return handle->imageView->view; };
constexpr Gfx::SeImageLayout getLayout() const { return handle->layout; } constexpr Gfx::SeImageLayout getLayout() const { return handle->layout; }
void setLayout(Gfx::SeImageLayout val) { handle->layout = val; } void setLayout(Gfx::SeImageLayout val) { handle->layout = val; }
constexpr VkImageAspectFlags getAspect() const { return handle->aspect; } constexpr VkImageAspectFlags getAspect() const { return handle->aspect; }
@@ -91,6 +120,8 @@ class Texture2D : public Gfx::Texture2D, public TextureBase {
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override; Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override; virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
virtual void generateMipmaps() override; virtual void generateMipmaps() override;
virtual Gfx::PTextureView getDefaultView() const override;
virtual Gfx::OTextureView createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount) override;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
@@ -115,6 +146,8 @@ class Texture3D : public Gfx::Texture3D, public TextureBase {
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override; Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override; virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
virtual void generateMipmaps() override; virtual void generateMipmaps() override;
virtual Gfx::PTextureView getDefaultView() const override;
virtual Gfx::OTextureView createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount) override;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
@@ -139,6 +172,8 @@ class TextureCube : public Gfx::TextureCube, public TextureBase {
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override; Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override; virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
virtual void generateMipmaps() override; virtual void generateMipmaps() override;
virtual Gfx::PTextureView getDefaultView() const override;
virtual Gfx::OTextureView createTextureView(uint32 baseMipLevel, uint32 levelCount, uint32 baseArrayLayer, uint32 layerCount) override;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
+1 -1
View File
@@ -78,7 +78,7 @@ void Material::updateDescriptor() {
set = layout->allocateDescriptorSet(); set = layout->allocateDescriptorSet();
for (uint32 i = 0; i < textures.size(); ++i) { for (uint32 i = 0; i < textures.size(); ++i) {
if (textures[i] != nullptr) { if (textures[i] != nullptr) {
set->updateTexture("textures", i, textures[i]); set->updateTexture("textures", i, textures[i]->getDefaultView());
} }
} }
for (uint32 i = 0; i < samplers.size(); ++i) { for (uint32 i = 0; i < samplers.size(); ++i) {
+2 -2
View File
@@ -122,11 +122,11 @@ void LightEnvironment::commit() {
uint32 numDirectionalLights = (uint32)dirs.size(); uint32 numDirectionalLights = (uint32)dirs.size();
set->updateConstants("numDirectionalLights", 0, &numDirectionalLights); set->updateConstants("numDirectionalLights", 0, &numDirectionalLights);
set->updateBuffer("directionalLights", 0, directionalLights); set->updateBuffer("directionalLights", 0, directionalLights);
set->updateTexture("shadowMap", 0, Gfx::PTexture2D(shadowMaps[0])); set->updateTexture("shadowMap", 0, shadowMaps[0]->getDefaultView());
set->updateSampler("shadowSampler", 0, Gfx::PSampler(shadowSamplers[0])); set->updateSampler("shadowSampler", 0, Gfx::PSampler(shadowSamplers[0]));
set->updateConstants("numPointLights", 0, &numPointLights); set->updateConstants("numPointLights", 0, &numPointLights);
set->updateBuffer("pointLights", 0, pointLights); set->updateBuffer("pointLights", 0, pointLights);
set->updateTexture("irradianceMap", 0, environment->getIrradianceMap()); set->updateTexture("irradianceMap", 0, environment->getIrradianceMap()->getDefaultView());
set->updateSampler("irradianceSampler", 0, environmentSampler); set->updateSampler("irradianceSampler", 0, environmentSampler);
set->writeChanges(); set->writeChanges();
} }
+1
View File
@@ -4,6 +4,7 @@
#include "Component/Transform.h" #include "Component/Transform.h"
#include "Graphics/Buffer.h" #include "Graphics/Buffer.h"
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Graphics/Texture.h"
namespace Seele { namespace Seele {
DECLARE_REF(EnvironmentMapAsset) DECLARE_REF(EnvironmentMapAsset)