Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions libraries/omm-lib/shaders/omm_common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include "omm_platform.hlsli"
#include "omm.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"

/// Unrolled version of murmur hash that takes N integers as input (up to 8)
uint murmur_32_scramble(uint k)
Expand Down Expand Up @@ -115,12 +114,31 @@ float2 UnpackFP16Pair(uint packed)
return f16tof32(data);
}

TexCoords FetchTexCoords(Buffer<uint> indexBuffer, ByteAddressBuffer texCoordBuffer, uint primitiveIndex)
uint FetchInputIndex(ByteAddressBuffer indexBuffer, uint index)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to use a typed index buffer (Buffer) to allow the rendering API to handle the decoding logic via the SRV configuration. Did this approach not work in your integration for some reason?

{
const OmmIndexFormat indexFormat = (OmmIndexFormat)g_GlobalConstants.InputIndexFormat;
const uint indexOffsetInBytes = g_GlobalConstants.IndexOffset + index * g_GlobalConstants.InputIndexStride;

if (indexFormat == OmmIndexFormat::UINT_8)
{
const uint raw = indexBuffer.Load(indexOffsetInBytes & ~3u);
return (raw >> ((indexOffsetInBytes & 3u) << 3u)) & 0xFFu;
}
else if (indexFormat == OmmIndexFormat::UINT_16)
{
const uint raw = indexBuffer.Load(indexOffsetInBytes & ~3u);
return (raw >> ((indexOffsetInBytes & 2u) << 3u)) & 0xFFFFu;
}

return indexBuffer.Load(indexOffsetInBytes);
}

TexCoords FetchTexCoords(ByteAddressBuffer indexBuffer, ByteAddressBuffer texCoordBuffer, uint primitiveIndex)
{
uint3 indices;
indices.x = indexBuffer[g_GlobalConstants.IndexOffset + primitiveIndex * 3 + 0];
indices.y = indexBuffer[g_GlobalConstants.IndexOffset + primitiveIndex * 3 + 1];
indices.z = indexBuffer[g_GlobalConstants.IndexOffset + primitiveIndex * 3 + 2];
indices.x = FetchInputIndex(indexBuffer, primitiveIndex * 3 + 0);
indices.y = FetchInputIndex(indexBuffer, primitiveIndex * 3 + 1);
indices.z = FetchInputIndex(indexBuffer, primitiveIndex * 3 + 2);

float2 vertexUVs[3];

Expand Down Expand Up @@ -277,4 +295,4 @@ int GetOmmDescOffset(ByteAddressBuffer ommIndexBuffer, uint primitiveIndex)
}
}

#endif // OMM_COMMON_HLSLI
#endif // OMM_COMMON_HLSLI
3 changes: 1 addition & 2 deletions libraries/omm-lib/shaders/omm_compress.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include "omm_platform.hlsli"
#include "omm.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_compress.cs.resources.hlsli"

OMM_DECLARE_GLOBAL_CONSTANT_BUFFER
Expand Down Expand Up @@ -144,4 +143,4 @@ void main(uint3 tid : SV_DispatchThreadID)
u_vmArrayBuffer.Store(vmArrayOffset + 4 * (DwProcessCount * rasterItemLocalIdx + j), stateDW);
}
}
}
}
3 changes: 1 addition & 2 deletions libraries/omm-lib/shaders/omm_desc_patch.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include "omm_platform.hlsli"
#include "omm.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_desc_patch.cs.resources.hlsli"

OMM_DECLARE_GLOBAL_CONSTANT_BUFFER
Expand Down Expand Up @@ -197,4 +196,4 @@ void main(uint3 tid : SV_DispatchThreadID)
OMM_SUBRESOURCE_STORE(TempOmmIndexBuffer, 4 * dstPrimitiveIndex, ommDescIndex);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#define OMM_DECLARE_SUBRESOURCES \
OMM_SUBRESOURCE(RWByteAddressBuffer, TempOmmIndexBuffer, u_heap0) \
OMM_SUBRESOURCE(RWByteAddressBuffer, HashTableBuffer, u_heap0) \
OMM_SUBRESOURCE(ByteAddressBuffer, SpecialIndicesStateBuffer, t_heap1) \
OMM_SUBRESOURCE(ByteAddressBuffer, SpecialIndicesStateBuffer, t_heap1)

4 changes: 2 additions & 2 deletions libraries/omm-lib/shaders/omm_global_cb.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OMM_CONSTANTS_START(GlobalConstants) \
OMM_CONSTANT(uint, DoSetup) \
OMM_CONSTANT(uint, SamplerIndex) \
OMM_CONSTANT(uint, BakeResultBufferSize) \
OMM_CONSTANT(uint, Pad0) \
OMM_CONSTANT(uint, InputIndexStride) \
\
OMM_CONSTANT(float2, ViewportSize) \
OMM_CONSTANT(float2, InvViewportSize) \
Expand All @@ -39,7 +39,7 @@ OMM_CONSTANTS_START(GlobalConstants) \
OMM_CONSTANT(uint, TexCoordFormat) \
OMM_CONSTANT(uint, TexCoordOffset) \
OMM_CONSTANT(uint, TexCoordStride) \
OMM_CONSTANT(uint, Pad2) \
OMM_CONSTANT(uint, InputIndexFormat) \
\
OMM_CONSTANT(float, AlphaCutoff) \
OMM_CONSTANT(uint, AlphaCutoffLessEqual) \
Expand Down
12 changes: 0 additions & 12 deletions libraries/omm-lib/shaders/omm_global_samplers.hlsli

This file was deleted.

3 changes: 1 addition & 2 deletions libraries/omm-lib/shaders/omm_hash_table.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include "omm_platform.hlsli"
#include "omm.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_common.hlsli"

namespace hashTable
Expand Down Expand Up @@ -76,4 +75,4 @@ hashTable::Result FindOrInsertOMMEntry(TexCoords texCoords, uint subdivisionLeve
{
return hashTable::Result::Null;
}
}
}
3 changes: 1 addition & 2 deletions libraries/omm-lib/shaders/omm_index_write.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include "omm_platform.hlsli"
#include "omm.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_index_write.cs.resources.hlsli"

OMM_DECLARE_LOCAL_CONSTANT_BUFFER
Expand Down Expand Up @@ -62,4 +61,4 @@ void main(uint3 tid : SV_DispatchThreadID)
const uint ommIndex = OMM_SUBRESOURCE_LOAD(TempOmmIndexBuffer, 4 * tid.x);
u_ommIndexBuffer.Store(4 * tid.x, ommIndex);
}
}
}
3 changes: 1 addition & 2 deletions libraries/omm-lib/shaders/omm_init_buffers_cs.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

#include "omm_platform.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_init_buffers_cs.cs.resources.hlsli"

OMM_DECLARE_GLOBAL_CONSTANT_BUFFER
Expand Down Expand Up @@ -54,4 +53,4 @@ void main(uint3 tid : SV_DispatchThreadID)
u_ommIndexHistogramBuffer.Store(8 * index + 4, formatAndLevel);
}
}
}
}
3 changes: 1 addition & 2 deletions libraries/omm-lib/shaders/omm_init_buffers_gfx.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

#include "omm_platform.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_init_buffers_gfx.cs.resources.hlsli"

OMM_DECLARE_GLOBAL_CONSTANT_BUFFER
Expand Down Expand Up @@ -72,4 +71,4 @@ void main(uint3 tid : SV_DispatchThreadID)
u_ommIndexHistogramBuffer.Store(8 * index + 4, formatAndLevel);
}
}
}
}
40 changes: 23 additions & 17 deletions libraries/omm-lib/shaders/omm_platform.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,29 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

#if( COMPILER_FXC || COMPILER_DXC )

#define OMM_REGISTER(regName, bindingIndex) register(regName ## bindingIndex)

#define OMM_CONSTANTS_START(name) \
struct name {
#define OMM_CONSTANT( constantType, constantName ) constantType constantName;
#define OMM_CONSTANTS_END(name, registerIndex) \
}; \
ConstantBuffer<name> g_ ## name : register(b ## registerIndex);
ConstantBuffer<name> g_ ## name : OMM_REGISTER(b, registerIndex);

#define OMM_PUSH_CONSTANTS_START(name) struct name {
#define OMM_PUSH_CONSTANT( constantType, constantName ) constantType constantName;
#define OMM_PUSH_CONSTANTS_END(name, registerIndex) \
}; \
VK_PUSH_CONSTANT ConstantBuffer<name> g_ ## name : register(b ## registerIndex);
VK_PUSH_CONSTANT ConstantBuffer<name> g_ ## name : OMM_REGISTER(b, registerIndex);

#define OMM_INPUT_RESOURCE( resourceType, resourceName, regName, bindingIndex ) \
resourceType resourceName : register( regName ## bindingIndex );
resourceType resourceName : OMM_REGISTER(regName, bindingIndex);
#define OMM_OUTPUT_RESOURCE( resourceType, resourceName, regName, bindingIndex ) \
resourceType resourceName : register( regName ## bindingIndex );
resourceType resourceName : OMM_REGISTER(regName, bindingIndex);
#define OMM_SAMPLER( resourceType, resourceName, regName, bindingIndex ) \
resourceType resourceName : register( regName ## bindingIndex );
resourceType resourceName : OMM_REGISTER(regName, bindingIndex);
#define OMM_DECLARE_GLOBAL_SAMPLERS SamplerState s_samplers[] : OMM_REGISTER(s, 0);
#define OMM_GLOBAL_SAMPLER(samplerIndex) s_samplers[samplerIndex]

#define OMM_SUBRESOURCE( resourceType, alias, name ) \
static resourceType alias = name;
Expand All @@ -69,17 +73,19 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#define OMM_SUBRESOURCE_INTERLOCKEDADD(subResource, offset, value, original_value) subResource.InterlockedAdd(g_GlobalConstants.subResource##Offset + offset, value, original_value)
#define OMM_SUBRESOURCE_INTERLOCKEDMAX(subResource, offset, value, original_value) subResource.InterlockedMax(g_GlobalConstants.subResource##Offset + offset, value, original_value)

#elif( \
defined( OMM_INPUT_RESOURCE ) && \
defined( OMM_OUTPUT_RESOURCE ) && \
defined( OMM_SUBRESOURCE ) &&\
defined( OMM_CONSTANTS_START ) && \
defined( OMM_CONSTANT ) && \
defined( OMM_CONSTANTS_END ) && \
defined( OMM_PUSH_CONSTANTS_START ) && \
defined( OMM_PUSH_CONSTANT ) && \
defined( OMM_PUSH_CONSTANTS_END)
)
#elif defined( OMM_INPUT_RESOURCE ) && \
defined( OMM_OUTPUT_RESOURCE ) && \
defined( OMM_SAMPLER ) && \
defined( OMM_DECLARE_GLOBAL_SAMPLERS ) && \
defined( OMM_GLOBAL_SAMPLER ) && \
defined( OMM_SUBRESOURCE ) && \
defined( OMM_INPUT_SUBRESOURCE ) && \
defined( OMM_CONSTANTS_START ) && \
defined( OMM_CONSTANT ) && \
defined( OMM_CONSTANTS_END ) && \
defined( OMM_PUSH_CONSTANTS_START ) && \
defined( OMM_PUSH_CONSTANT ) && \
defined( OMM_PUSH_CONSTANTS_END )
// Custom engine that has already defined all the macros

#else
Expand Down Expand Up @@ -114,4 +120,4 @@ do \
\
} while (false)

#endif // include guard
#endif // include guard
3 changes: 1 addition & 2 deletions libraries/omm-lib/shaders/omm_post_build_info.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include "omm.hlsli"

#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_post_build_info.cs.resources.hlsli"

OMM_DECLARE_GLOBAL_CONSTANT_BUFFER
Expand All @@ -39,4 +38,4 @@ void main(uint3 tid : SV_DispatchThreadID)
u_postBuildInfo.Store(20, 0);
u_postBuildInfo.Store(24, 0);
u_postBuildInfo.Store(28, 0);
}
}
2 changes: 1 addition & 1 deletion libraries/omm-lib/shaders/omm_rasterize.cs.resources.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define OMM_DECLARE_INPUT_RESOURCES \
OMM_INPUT_RESOURCE(Texture2D<float4>, t_alphaTexture, t, 0) \
OMM_INPUT_RESOURCE(Buffer<uint>, t_indexBuffer, t, 1) \
OMM_INPUT_RESOURCE(ByteAddressBuffer, t_indexBuffer, t, 1) \
OMM_INPUT_RESOURCE(ByteAddressBuffer, t_texCoordBuffer, t, 2) \
OMM_INPUT_RESOURCE(ByteAddressBuffer, t_heap0, t, 3) \
OMM_INPUT_RESOURCE(ByteAddressBuffer, t_heap1, t, 4)
Expand Down
5 changes: 2 additions & 3 deletions libraries/omm-lib/shaders/omm_rasterize.gs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include "omm_platform.hlsli"
#include "omm.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_rasterize.gs.resources.hlsli"

OMM_DECLARE_GLOBAL_CONSTANT_BUFFER
Expand Down Expand Up @@ -74,7 +73,7 @@ void DoAABBTest(uint i_microTriIndex, triangle VSOutput Input[3])
float2 uv = float2(x, y) * g_GlobalConstants.InvTexSize;

const float2 halfTexel = 0;// 0.5 * g_GlobalConstants.InvTexSize;
const float4 alpha = t_alphaTexture.GatherAlpha(s_samplers[g_GlobalConstants.SamplerIndex], uv.xy + halfTexel, 0);
const float4 alpha = t_alphaTexture.GatherAlpha(OMM_GLOBAL_SAMPLER(g_GlobalConstants.SamplerIndex), uv.xy + halfTexel, 0);

const float min_a = min(alpha.x, min(alpha.y, min(alpha.z, alpha.w)));
const float max_a = max(alpha.x, max(alpha.y, max(alpha.z, alpha.w)));
Expand Down Expand Up @@ -162,4 +161,4 @@ void main(
}
#endif

}
}
2 changes: 1 addition & 1 deletion libraries/omm-lib/shaders/omm_rasterize.resources.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

#define OMM_DECLARE_INPUT_RESOURCES \
OMM_INPUT_RESOURCE(Texture2D<float4>, t_alphaTexture, t, 0) \
OMM_INPUT_RESOURCE(Buffer<uint>, t_indexBuffer, t, 1) \
OMM_INPUT_RESOURCE(ByteAddressBuffer, t_indexBuffer, t, 1) \
OMM_INPUT_RESOURCE(ByteAddressBuffer, t_texCoordBuffer, t, 2) \
OMM_INPUT_RESOURCE(ByteAddressBuffer, t_heap0, t, 3)

Expand Down
5 changes: 2 additions & 3 deletions libraries/omm-lib/shaders/omm_rasterize.vs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include "omm_platform.hlsli"
#include "omm.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_rasterize.vs.resources.hlsli"

OMM_DECLARE_GLOBAL_CONSTANT_BUFFER
Expand All @@ -38,7 +37,7 @@ void main(

// If we run linear sampling (with the precise method) a base state must always be present.
// We select the current
const float4 color = t_alphaTexture.SampleLevel(s_samplers[g_GlobalConstants.SamplerIndex], texCoord.xy, 0);
const float4 color = t_alphaTexture.SampleLevel(OMM_GLOBAL_SAMPLER(g_GlobalConstants.SamplerIndex), texCoord.xy, 0);
const float alpha = color[g_GlobalConstants.AlphaTextureChannel];

const OpacityState vertexState = (OpacityState) (g_GlobalConstants.AlphaCutoff < alpha ? (uint) OpacityState::Opaque : (uint) OpacityState::Transparent);
Expand All @@ -47,4 +46,4 @@ void main(
o_texCoord = texCoord;
o_vmStateAtVertex = (uint)vertexState;
o_posClip = raster::TexCoord_to_VS_SV_Position(texCoord);
}
}
5 changes: 2 additions & 3 deletions libraries/omm-lib/shaders/omm_rasterize_cs.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "omm_platform.hlsli"
#include "omm.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_rasterize.cs.resources.hlsli"

OMM_DECLARE_GLOBAL_CONSTANT_BUFFER
Expand Down Expand Up @@ -379,7 +378,7 @@ void main(uint3 tid : SV_DispatchThreadID)
bool isOpaque = false;
bool isTransparent = false;
{
const PRECISE float4 color = t_alphaTexture.SampleLevel(s_samplers[g_GlobalConstants.SamplerIndex], microTri.p[0].xy, 0);
const PRECISE float4 color = t_alphaTexture.SampleLevel(OMM_GLOBAL_SAMPLER(g_GlobalConstants.SamplerIndex), microTri.p[0].xy, 0);
#if IN_ALPHA_TEXTURE_CHANNEL == 0
const PRECISE float alpha = color.r;
#elif IN_ALPHA_TEXTURE_CHANNEL == 1
Expand Down Expand Up @@ -459,4 +458,4 @@ void main(uint3 tid : SV_DispatchThreadID)
const uint data = (state << (i << logBitsPerState));

u_vmArrayBuffer.InterlockedOr(ommArrayOffset + 4 * dwOffset, data);
}
}
5 changes: 2 additions & 3 deletions libraries/omm-lib/shaders/omm_rasterize_debug.ps.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include "omm_platform.hlsli"
#include "omm.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_rasterize.vs.resources.hlsli"

OMM_DECLARE_GLOBAL_CONSTANT_BUFFER
Expand Down Expand Up @@ -41,11 +40,11 @@ void main(

const float2 texCoord = raster::PS_SV_Position_to_TexCoord(i_svPosition);

const float4 color = t_alphaTexture.SampleLevel(s_samplers[g_GlobalConstants.SamplerIndex], texCoord.xy, 0);
const float4 color = t_alphaTexture.SampleLevel(OMM_GLOBAL_SAMPLER(g_GlobalConstants.SamplerIndex), texCoord.xy, 0);
const float alpha = color[g_GlobalConstants.AlphaTextureChannel];

//o_color = float4(alpha.rgb, 1);
o_color = float4(debugColor * alpha.xxx, 1);
//float NumLevels = (float)g_LocalConstants.SubdivisionLevel;
//o_color = float4(i_microTriIndex / NumLevels, i_microTriIndex / NumLevels, i_microTriIndex / NumLevels, 1);
}
}
3 changes: 1 addition & 2 deletions libraries/omm-lib/shaders/omm_rasterize_debug.vs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include "omm_platform.hlsli"
#include "omm.hlsli"
#include "omm_global_cb.hlsli"
#include "omm_global_samplers.hlsli"
#include "omm_rasterize.vs.resources.hlsli"

OMM_DECLARE_GLOBAL_CONSTANT_BUFFER
Expand All @@ -36,4 +35,4 @@ void main(

o_primitiveIndex = i_primitiveIndex;
o_posClip = raster::TexCoord_to_VS_SV_Position(texCoord);
}
}
Loading
Loading