Skip to content

Commit

Permalink
Add bindless texturing sample
Browse files Browse the repository at this point in the history
update samples to use optimizedClearValue
  • Loading branch information
Ravbug committed Jul 4, 2024
1 parent 3bd715e commit acf7d96
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions 02-Cubes/cubes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct Cubes : public ExampleFramework {
.aspect = {.HasDepth = true},
.width = (uint32_t)width,
.height = (uint32_t)height,
.optimizedClearValue = {1},
.format = RGL::TextureFormat::D32SFloat,
.debugName = "Depth Texture"
}
Expand Down
1 change: 1 addition & 0 deletions 03-Imgui/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct ImGuiDemo : public ExampleFramework {
.aspect = {.HasDepth = true},
.width = (uint32_t)width,
.height = (uint32_t)height,
.optimizedClearValue = {1},
.format = RGL::TextureFormat::D32SFloat
}
);
Expand Down
1 change: 1 addition & 0 deletions 04-Deferred/deferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct Deferred : public ExampleFramework {
.aspect = {.HasDepth = true},
.width = (uint32_t)width,
.height = (uint32_t)height,
.optimizedClearValue = {1},
.format = RGL::TextureFormat::D32SFloat,
.debugName = "Depth Texture"
}
Expand Down
1 change: 1 addition & 0 deletions 05-XR/xr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ struct XR : public ExampleFramework {
.aspect = {.HasDepth = true},
.width = (uint32_t)width,
.height = (uint32_t)height,
.optimizedClearValue = {1},
.format = RGL::TextureFormat::D32SFloat,
.debugName = "Depth Texture"
}
Expand Down
1 change: 1 addition & 0 deletions 06-Asteroids/asteroids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct Asteroids : public ExampleFramework {
.aspect = {.HasDepth = true},
.width = (uint32_t)width,
.height = (uint32_t)height,
.optimizedClearValue = {1},
.format = RGL::TextureFormat::D32SFloat
}
);
Expand Down
1 change: 1 addition & 0 deletions 07-Mipmap/mipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ struct Mipmap : public ExampleFramework {
.aspect = {.HasDepth = true},
.width = (uint32_t)width,
.height = (uint32_t)height,
.optimizedClearValue = {1},
.format = RGL::TextureFormat::D32SFloat,
.debugName = "Depth Texture"
}
Expand Down
29 changes: 28 additions & 1 deletion 09-BindlessTexturing/bindlesstexturing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct BindlessTexturing : public ExampleFramework {

RGLCommandBufferPtr commandBuffer;
RGLBufferPtr vertexBuffer, indexBuffer;
RGLTexturePtr depthTexture;
RGLTexturePtr depthTexture, tx1, tx2, tx3;
RGLSamplerPtr sampler;
RGLRenderPipelinePtr renderPipeline;
RGLRenderPassPtr renderPass;
Expand Down Expand Up @@ -66,6 +66,7 @@ struct BindlessTexturing : public ExampleFramework {
},
{
.binding = 1,
.count = 512,
.type = RGL::BindingType::SampledImage,
.stageFlags = RGL::BindingVisibility::Fragment,
},
Expand Down Expand Up @@ -170,6 +171,24 @@ struct BindlessTexturing : public ExampleFramework {
commandBuffer = commandQueue->CreateCommandBuffer();
camera.position.z = 10;
camera.position.y = 0.3;

auto loadTx = [this](const std::string_view name, RGLTexturePtr& tx) {
auto imagedata = LoadImage(name);

tx = device->CreateTextureWithData(RGL::TextureConfig{
.usage = {.TransferDestination = true, .Sampled = true},
.aspect = {.HasColor = true},
.width = imagedata.width,
.height = imagedata.height,
.format = RGL::TextureFormat::RGBA8_Unorm
},
imagedata.bytes
);
};
loadTx("tx29.png",tx1);
loadTx("tx34.png",tx2);
loadTx("tx39.png",tx3);

}

void tick() final {
Expand Down Expand Up @@ -198,10 +217,14 @@ struct BindlessTexturing : public ExampleFramework {
.extent = {nextImgSize.width, nextImgSize.height}
});

auto heapStart = device->GetGlobalBindlessTextureHeap();

commandBuffer->BindRenderPipeline(renderPipeline);
commandBuffer->SetVertexBytes(ubo, 0);
commandBuffer->SetVertexBuffer(vertexBuffer);
commandBuffer->SetIndexBuffer(indexBuffer);
commandBuffer->SetFragmentSampler(sampler,0);
commandBuffer->SetFragmentTexture(heapStart, 1); // expose all the textures
commandBuffer->DrawIndexed(std::size(BasicObjects::Quad::indices));

commandBuffer->EndRendering();
Expand All @@ -217,6 +240,9 @@ struct BindlessTexturing : public ExampleFramework {
}

void sampleshutdown() final {
tx1.reset();
tx2.reset();
tx3.reset();
renderPass.reset();
depthTexture.reset();
indexBuffer.reset();
Expand All @@ -233,6 +259,7 @@ struct BindlessTexturing : public ExampleFramework {
.aspect = {.HasDepth = true},
.width = (uint32_t)width,
.height = (uint32_t)height,
.optimizedClearValue = {1},
.format = RGL::TextureFormat::D32SFloat,
.debugName = "Depth Texture"
}
Expand Down
6 changes: 5 additions & 1 deletion 09-BindlessTexturing/btex.frag
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#extension GL_EXT_nonuniform_qualifier : enable

layout(binding = 0) uniform sampler g_sampler;
layout(binding = 1) uniform texture2D textures[];

layout(location = 0) in vec2 uv;
layout(location = 1) in flat uint instance;
layout(location = 0) out vec4 outcolor;
void main(){

outcolor = vec4(1,1,0,1);
outcolor = vec4(texture(sampler2D(textures[instance], g_sampler),uv).rgb,1);
}
4 changes: 4 additions & 0 deletions 09-BindlessTexturing/btex.vert
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ layout(location = 0) in vec2 inPosition;
layout(location = 1) in vec2 inUV;

layout(location = 0) out vec2 outUV;
layout(location = 1) out flat uint instance;

void main(){

instance = gl_InstanceID;

gl_Position = ubo.viewProj * vec4(inPosition, 0, 1);
outUV = inUV;
}
Binary file added 09-BindlessTexturing/tx29.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 09-BindlessTexturing/tx34.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 09-BindlessTexturing/tx39.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit acf7d96

Please sign in to comment.