Compare commits

..

3 Commits

Author SHA1 Message Date
abdelrahman 8e6f051955 Research shaders for compositor ops 2026-08-09 22:49:26 +01:00
abdelrahman e59865bff5 Fix slangc warnings 2026-08-09 20:46:14 +01:00
abdelrahman e206e4647b Clear screen to neutral gray 2026-08-09 20:45:36 +01:00
5 changed files with 1930 additions and 3 deletions
+5 -1
View File
@@ -8,7 +8,8 @@
struct BlitData { struct BlitData {
float4 rect; // NDC fit rect: x0, y0, x1, y1 float4 rect; // NDC fit rect: x0, y0, x1, y1
uint selected; uint selected;
uint pad[3]; uint mode; // 0 = sample texture, 1 = solid background
uint pad[2];
}; };
[[vk::push_constant]] [[vk::push_constant]]
@@ -33,5 +34,8 @@ VSOutput main(uint vertexIndex : SV_VertexID) {
[shader("fragment")] [shader("fragment")]
float4 main(VSOutput input) { float4 main(VSOutput input) {
if (blit.mode == 1) {
return float4(0.18, 0.18, 0.18, 1.0);
}
return textures[NonUniformResourceIndex(blit.selected)].Sample(input.UV); return textures[NonUniformResourceIndex(blit.selected)].Sample(input.UV);
} }
File diff suppressed because it is too large Load Diff
+59
View File
@@ -0,0 +1,59 @@
# Session Log — 2026-08-09
## Background colour change (blit shader)
- User requested changing the letterbox/pillarbox background from black to neutral grey.
- Initial attempt: changed the render pass clear color to `(0.5, 0.5, 0.5, 1.0)`. This
triggered the NVIDIA validation layer warning
`BestPractices-NVIDIA-ClearColor-NotCompressed` — SRGB fast clears only work
with 0.0 or 1.0 on NVIDIA tile-based GPUs.
- Reverted the clear color and implemented the proper solution: draw a fullscreen
grey quad in the fragment shader before the texture quad. The render pass clear
stays at 0.0 (fast-compressed).
- Added `mode` field to `BlitData` push constant. Mode 0 samples the texture, mode
1 outputs solid grey.
- User noted that a branch in the shader is free (no warp divergence since `mode`
is uniform per draw call). Agreed — no need for a separate clear pipeline.
- Changed grey from 0.5 to 0.18 (18% grey card, standard in photography/compositing).
- Fixed a Slang compilation warning by updating the profile from `spirv_1_4` to
`spirv_1_6` and explicitly declaring the required capabilities.
## Shader filter node research
- User requested research on: Gaussian blur, CDL, Laplacian, Sobel, sharpen,
posterize, pixelize, Kuwahara.
- Launched a research agent that produced `documents/research/shader-filters.md`
covering all filters with formulas, Slang pseudocode, parameter tables, and
performance notes.
## Design decisions made during review
1. **Colour space**: all intermediate textures are linear float
(`R16G16B16A16_SFLOAT`, `R32G32B32A32_SFLOAT` for Kuwahara tensor). sRGB images
are linearized once at load by the Read node. Final blit to sRGB swapchain
handles display encoding.
2. **Alpha**: premultiplied everywhere by default. Explicit Unpremult/Premult
nodes for operations that need unpremultiplied values (Nuke model).
3. **Edge handling**: per-node parameter, clamp-to-edge default, clamp-to-border
option. Affects sampler state, not shader branches.
4. **Premult has no parameters**: removed the empty push constant struct.
## Research document fixes
- Fixed a contradictory sentence about push constant sizes and CDL block size.
- Added Unpremult (§9) and Premult (§10) sections with full implementations.
- Added `edge_mode` field to all 5 spatial filter push constant blocks (Gaussian,
Laplacian, Sobel, Sharpen, Kuwahara).
- Restructured the implications section (§12) into open items vs resolved decisions.
- Expanded all mathematics sections with plain-language explanations suitable for
someone without a strong math background.
## Open items for next session
- Begin implementing the actual shader nodes in Prism
- Node system needs: per-pass resource signatures, scratch texture hooks, per-node
sampler choice, compile-time-bounded loop limits
- Classic Kuwahara is the recommended first implementation (single pass)
+9 -1
View File
@@ -33,7 +33,15 @@ vendor:
# Compile shaders from .slang to SPIR-V # Compile shaders from .slang to SPIR-V
shaders: shaders:
mkdir -p {{BUILDDIR}}/shaders mkdir -p {{BUILDDIR}}/shaders
{{VK_SDK}}/bin/slangc -target spirv -profile spirv_1_4 \ {{VK_SDK}}/bin/slangc -target spirv \
-profile spirv_1_6+\
SPV_GOOGLE_user_type+\
spvFragmentFullyCoveredEXT+\
spvDerivativeControl+\
spvImageQuery+\
spvImageGatherExtended+\
spvSparseResidency+\
spvMinLod \
-o {{BUILDDIR}}/shaders/blit.spv assets/blit.slang -o {{BUILDDIR}}/shaders/blit.spv assets/blit.slang
# Build all objects, then link # Build all objects, then link
+18 -1
View File
@@ -50,7 +50,8 @@ struct TextureResources {
struct BlitData { struct BlitData {
f32 rect[4]; // NDC fit rect: x0, y0, x1, y1 f32 rect[4]; // NDC fit rect: x0, y0, x1, y1
u32 selected; u32 selected;
u32 pad[3]; u32 mode; // 0 = sample texture, 1 = solid background
u32 pad[2];
}; };
// Typedefs for wapp arrays of our types // Typedefs for wapp arrays of our types
@@ -481,12 +482,28 @@ int main() {
prRhiCmdBindDescriptorSets(cb, PR_RHI_PIPELINE_BIND_POINT_GRAPHICS, prRhiCmdBindDescriptorSets(cb, PR_RHI_PIPELINE_BIND_POINT_GRAPHICS,
app.pipeline_layout, 0, sets); app.pipeline_layout, 0, sets);
// Draw background (fullscreen grey quad)
BlitData bg = {};
bg.rect[0] = -1.0f;
bg.rect[1] = -1.0f;
bg.rect[2] = 1.0f;
bg.rect[3] = 1.0f;
bg.selected = 0;
bg.mode = 1;
prRhiCmdPushConstants(cb, app.pipeline_layout,
(PrRhiShaderStage)(PR_RHI_SHADER_STAGE_VERTEX |
PR_RHI_SHADER_STAGE_FRAGMENT),
0, sizeof(BlitData), &bg);
prRhiCmdDraw(cb, 4, 1, 0, 0);
// Draw texture (contain-fit)
BlitData blit = {}; BlitData blit = {};
blit.rect[0] = fit_rect[0]; blit.rect[0] = fit_rect[0];
blit.rect[1] = fit_rect[1]; blit.rect[1] = fit_rect[1];
blit.rect[2] = fit_rect[2]; blit.rect[2] = fit_rect[2];
blit.rect[3] = fit_rect[3]; blit.rect[3] = fit_rect[3];
blit.selected = app.selected; blit.selected = app.selected;
blit.mode = 0;
prRhiCmdPushConstants(cb, app.pipeline_layout, prRhiCmdPushConstants(cb, app.pipeline_layout,
(PrRhiShaderStage)(PR_RHI_SHADER_STAGE_VERTEX | (PrRhiShaderStage)(PR_RHI_SHADER_STAGE_VERTEX |
PR_RHI_SHADER_STAGE_FRAGMENT), PR_RHI_SHADER_STAGE_FRAGMENT),