diff --git a/02-Cubes/cubes.cpp b/02-Cubes/cubes.cpp index 4654096..ab6dee9 100644 --- a/02-Cubes/cubes.cpp +++ b/02-Cubes/cubes.cpp @@ -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" } diff --git a/03-Imgui/imgui.cpp b/03-Imgui/imgui.cpp index 1b3bf3b..8822aaf 100644 --- a/03-Imgui/imgui.cpp +++ b/03-Imgui/imgui.cpp @@ -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 } ); diff --git a/04-Deferred/deferred.cpp b/04-Deferred/deferred.cpp index bf323fa..d382791 100644 --- a/04-Deferred/deferred.cpp +++ b/04-Deferred/deferred.cpp @@ -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" } diff --git a/05-XR/xr.cpp b/05-XR/xr.cpp index ec97cd0..2cb04c6 100644 --- a/05-XR/xr.cpp +++ b/05-XR/xr.cpp @@ -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" } diff --git a/06-Asteroids/asteroids.cpp b/06-Asteroids/asteroids.cpp index c0fc333..a80de82 100644 --- a/06-Asteroids/asteroids.cpp +++ b/06-Asteroids/asteroids.cpp @@ -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 } ); diff --git a/07-Mipmap/mipmap.cpp b/07-Mipmap/mipmap.cpp index 76ec148..c2693c5 100644 --- a/07-Mipmap/mipmap.cpp +++ b/07-Mipmap/mipmap.cpp @@ -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" } diff --git a/09-BindlessTexturing/bindlesstexturing.cpp b/09-BindlessTexturing/bindlesstexturing.cpp index 3f17227..fe7d6c1 100644 --- a/09-BindlessTexturing/bindlesstexturing.cpp +++ b/09-BindlessTexturing/bindlesstexturing.cpp @@ -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; @@ -66,6 +66,7 @@ struct BindlessTexturing : public ExampleFramework { }, { .binding = 1, + .count = 512, .type = RGL::BindingType::SampledImage, .stageFlags = RGL::BindingVisibility::Fragment, }, @@ -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 { @@ -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(); @@ -217,6 +240,9 @@ struct BindlessTexturing : public ExampleFramework { } void sampleshutdown() final { + tx1.reset(); + tx2.reset(); + tx3.reset(); renderPass.reset(); depthTexture.reset(); indexBuffer.reset(); @@ -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" } diff --git a/09-BindlessTexturing/btex.frag b/09-BindlessTexturing/btex.frag index 838ef17..be6445d 100644 --- a/09-BindlessTexturing/btex.frag +++ b/09-BindlessTexturing/btex.frag @@ -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); } diff --git a/09-BindlessTexturing/btex.vert b/09-BindlessTexturing/btex.vert index b79cf80..b24afdd 100644 --- a/09-BindlessTexturing/btex.vert +++ b/09-BindlessTexturing/btex.vert @@ -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; } diff --git a/09-BindlessTexturing/tx29.png b/09-BindlessTexturing/tx29.png new file mode 100644 index 0000000..a2bc17c Binary files /dev/null and b/09-BindlessTexturing/tx29.png differ diff --git a/09-BindlessTexturing/tx34.png b/09-BindlessTexturing/tx34.png new file mode 100644 index 0000000..85c0d02 Binary files /dev/null and b/09-BindlessTexturing/tx34.png differ diff --git a/09-BindlessTexturing/tx39.png b/09-BindlessTexturing/tx39.png new file mode 100644 index 0000000..811212d Binary files /dev/null and b/09-BindlessTexturing/tx39.png differ diff --git a/deps/RGL b/deps/RGL index 2df1b38..a83433f 160000 --- a/deps/RGL +++ b/deps/RGL @@ -1 +1 @@ -Subproject commit 2df1b38ce3b427c5e6854b3ede1fd52ff4f6a089 +Subproject commit a83433f75398941255bd3657bab8356a01ad2d02