From f933aa1c7677a7668ce19648283ee72d8803e2ec Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Thu, 24 Oct 2024 16:13:37 +0100 Subject: [PATCH] Moved some bit field helper functions to common code To be shared between DXBC and DXIL Debugger BitwiseReverseLSB16 PopCount --- renderdoc/driver/shaders/dxbc/dx_debug.cpp | 19 +++++++++++++++++++ renderdoc/driver/shaders/dxbc/dx_debug.h | 3 +++ renderdoc/driver/shaders/dxbc/dxbc_debug.cpp | 19 ------------------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/renderdoc/driver/shaders/dxbc/dx_debug.cpp b/renderdoc/driver/shaders/dxbc/dx_debug.cpp index c87dd0b0f..48e71360f 100644 --- a/renderdoc/driver/shaders/dxbc/dx_debug.cpp +++ b/renderdoc/driver/shaders/dxbc/dx_debug.cpp @@ -412,6 +412,25 @@ float flush_denorm(const float f) return ret; } +uint32_t BitwiseReverseLSB16(uint32_t x) +{ + // Reverse the bits in x, then discard the lower half + // https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel + x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1); + x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2); + x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4); + x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8); + return x << 16; +} + +uint32_t PopCount(uint32_t x) +{ + // https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel + x = x - ((x >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + return (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; +} + void get_sample_position(uint32_t sampleIndex, uint32_t sampleCount, float *position) { // assume standard sample pattern - this might not hold in all cases diff --git a/renderdoc/driver/shaders/dxbc/dx_debug.h b/renderdoc/driver/shaders/dxbc/dx_debug.h index cd787f442..90725fe9f 100644 --- a/renderdoc/driver/shaders/dxbc/dx_debug.h +++ b/renderdoc/driver/shaders/dxbc/dx_debug.h @@ -117,5 +117,8 @@ float round_ne(float x); double round_ne(double x); float flush_denorm(const float f); +uint32_t BitwiseReverseLSB16(uint32_t x); +uint32_t PopCount(uint32_t x); + void get_sample_position(uint32_t sampleIndex, uint32_t sampleCount, float *position); }; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp index 87142098d..d459aa8af 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp @@ -1639,25 +1639,6 @@ ShaderVariable ThreadState::GetSrc(const Operand &oper, const Operation &op, boo return v; } -static uint32_t BitwiseReverseLSB16(uint32_t x) -{ - // Reverse the bits in x, then discard the lower half - // https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel - x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1); - x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2); - x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4); - x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8); - return x << 16; -} - -static uint32_t PopCount(uint32_t x) -{ - // https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel - x = x - ((x >> 1) & 0x55555555); - x = (x & 0x33333333) + ((x >> 2) & 0x33333333); - return (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; -} - void FlattenSingleVariable(const rdcstr &cbufferName, uint32_t byteOffset, const rdcstr &basename, const ShaderVariable &v, rdcarray &outvars, rdcarray &sourcevars)