This commit is contained in:
Chuck Walbourn 2022-02-21 10:11:54 -08:00
Родитель 42a24f23ed
Коммит c5c08f6115
54 изменённых файлов: 1428 добавлений и 1423 удалений

Просмотреть файл

@ -190,7 +190,7 @@ namespace
return 0;
}
uint32_t tag = GetFormatTag(wfx);
const uint32_t tag = GetFormatTag(wfx);
switch (tag)
{
case WAVE_FORMAT_PCM:
@ -911,7 +911,7 @@ void AudioEngine::Impl::AllocateVoice(
char buff[64] = {};
auto wfmt = reinterpret_cast<WAVEFORMATEX*>(buff);
uint32_t tag = GetFormatTag(wfx);
const uint32_t tag = GetFormatTag(wfx);
switch (tag)
{
case WAVE_FORMAT_PCM:
@ -980,7 +980,7 @@ void AudioEngine::Impl::AllocateVoice(
throw std::runtime_error("Too many instance voices");
}
UINT32 vflags = (flags & SoundEffectInstance_NoSetPitch) ? XAUDIO2_VOICE_NOPITCH : 0u;
const UINT32 vflags = (flags & SoundEffectInstance_NoSetPitch) ? XAUDIO2_VOICE_NOPITCH : 0u;
HRESULT hr;
if (flags & SoundEffectInstance_Use3D)

Просмотреть файл

@ -211,7 +211,7 @@ void DynamicSoundEffectInstance::Impl::SubmitBuffer(const uint8_t* pAudioData, u
void DynamicSoundEffectInstance::Impl::OnUpdate()
{
DWORD result = WaitForSingleObjectEx(mBufferEvent.get(), 0, FALSE);
const DWORD result = WaitForSingleObjectEx(mBufferEvent.get(), 0, FALSE);
switch (result)
{
case WAIT_TIMEOUT:

Просмотреть файл

@ -179,9 +179,9 @@ bool DirectX::IsValid(_In_ const WAVEFORMATEX* wfx) noexcept
return false;
}
int nHeaderBytes = 7 /*MSADPCM_HEADER_LENGTH*/ * wfx->nChannels;
int nBitsPerFrame = 4 /*MSADPCM_BITS_PER_SAMPLE*/ * wfx->nChannels;
int nPcmFramesPerBlock = (wfx->nBlockAlign - nHeaderBytes) * 8 / nBitsPerFrame + 2;
const int nHeaderBytes = 7 /*MSADPCM_HEADER_LENGTH*/ * wfx->nChannels;
const int nBitsPerFrame = 4 /*MSADPCM_BITS_PER_SAMPLE*/ * wfx->nChannels;
const int nPcmFramesPerBlock = (wfx->nBlockAlign - nHeaderBytes) * 8 / nBitsPerFrame + 2;
if (wfadpcm->wSamplesPerBlock != nPcmFramesPerBlock)
{
@ -468,7 +468,7 @@ bool DirectX::IsValid(_In_ const WAVEFORMATEX* wfx) noexcept
if (wfex->dwChannelMask)
{
auto channelBits = ChannelsSpecifiedInMask(wfex->dwChannelMask);
auto const channelBits = ChannelsSpecifiedInMask(wfex->dwChannelMask);
if (channelBits != wfx->nChannels)
{
DebugTrace("ERROR: WAVEFORMATEXTENSIBLE: nChannels=%u but ChannelMask has %u bits set\n",
@ -511,7 +511,7 @@ void DirectX::CreateIntegerPCM(
int channels,
int sampleBits) noexcept
{
int blockAlign = channels * sampleBits / 8;
const int blockAlign = channels * sampleBits / 8;
wfx->wFormatTag = WAVE_FORMAT_PCM;
wfx->nChannels = static_cast<WORD>(channels);
@ -531,7 +531,7 @@ void DirectX::CreateFloatPCM(
int sampleRate,
int channels) noexcept
{
int blockAlign = channels * 4;
const int blockAlign = channels * 4;
wfx->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
wfx->nChannels = static_cast<WORD>(channels);
@ -566,7 +566,7 @@ void DirectX::CreateADPCM(
throw std::invalid_argument("ADPCMWAVEFORMAT");
}
int blockAlign = (7 /*MSADPCM_HEADER_LENGTH*/) * channels
const int blockAlign = (7 /*MSADPCM_HEADER_LENGTH*/) * channels
+ (samplesPerBlock - 2) * (4 /* MSADPCM_BITS_PER_SAMPLE */) * channels / 8;
wfx->wFormatTag = WAVE_FORMAT_ADPCM;

Просмотреть файл

@ -95,12 +95,15 @@ public:
#endif
}
HRESULT Initialize(_In_ AudioEngine* engine, _Inout_ std::unique_ptr<uint8_t[]>& wavData,
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
#ifdef DIRECTX_ENABLE_SEEK_TABLES
_In_reads_opt_(seekCount) const uint32_t* seekTable, size_t seekCount,
#endif
uint32_t loopStart, uint32_t loopLength) noexcept;
HRESULT Initialize(
_In_ const AudioEngine* engine,
_Inout_ std::unique_ptr<uint8_t[]>& wavData,
_In_ const WAVEFORMATEX* wfx,
_In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
#ifdef DIRECTX_ENABLE_SEEK_TABLES
_In_reads_opt_(seekCount) const uint32_t* seekTable, size_t seekCount,
#endif
uint32_t loopStart, uint32_t loopLength) noexcept;
void Play(float volume, float pitch, float pan);
@ -176,12 +179,15 @@ private:
_Use_decl_annotations_
HRESULT SoundEffect::Impl::Initialize(AudioEngine* engine, std::unique_ptr<uint8_t[]>& wavData,
const WAVEFORMATEX* wfx, const uint8_t* startAudio, size_t audioBytes,
#ifdef DIRECTX_ENABLE_SEEK_TABLES
const uint32_t* seekTable, size_t seekCount,
#endif
uint32_t loopStart, uint32_t loopLength) noexcept
HRESULT SoundEffect::Impl::Initialize(
const AudioEngine* engine,
std::unique_ptr<uint8_t[]>& wavData,
const WAVEFORMATEX* wfx,
const uint8_t* startAudio, size_t audioBytes,
#ifdef DIRECTX_ENABLE_SEEK_TABLES
const uint32_t* seekTable, size_t seekCount,
#endif
uint32_t loopStart, uint32_t loopLength) noexcept
{
if (!engine || !IsValid(wfx) || !startAudio || !audioBytes || !wavData)
return E_INVALIDARG;
@ -191,96 +197,96 @@ HRESULT SoundEffect::Impl::Initialize(AudioEngine* engine, std::unique_ptr<uint8
switch (GetFormatTag(wfx))
{
case WAVE_FORMAT_PCM:
case WAVE_FORMAT_IEEE_FLOAT:
case WAVE_FORMAT_ADPCM:
// Take ownership of the buffer
mWavData.reset(wavData.release());
case WAVE_FORMAT_PCM:
case WAVE_FORMAT_IEEE_FLOAT:
case WAVE_FORMAT_ADPCM:
// Take ownership of the buffer
mWavData.reset(wavData.release());
// WARNING: We assume the wfx and startAudio parameters are pointers into the wavData memory buffer
mWaveFormat = wfx;
mStartAudio = startAudio;
break;
// WARNING: We assume the wfx and startAudio parameters are pointers into the wavData memory buffer
mWaveFormat = wfx;
mStartAudio = startAudio;
break;
#ifdef DIRECTX_ENABLE_XWMA
#ifdef DIRECTX_ENABLE_XWMA
case WAVE_FORMAT_WMAUDIO2:
case WAVE_FORMAT_WMAUDIO3:
if (!seekCount || !seekTable)
{
DebugTrace("ERROR: SoundEffect format xWMA requires seek table\n");
return E_FAIL;
}
if (seekCount > UINT32_MAX)
return E_INVALIDARG;
// Take ownership of the buffer
mWavData.reset(wavData.release());
// WARNING: We assume the wfx, startAudio, and mSeekTable parameters are pointers into the wavData memory buffer
mWaveFormat = wfx;
mStartAudio = startAudio;
mSeekCount = static_cast<uint32_t>(seekCount);
mSeekTable = seekTable;
break;
#endif // xWMA
#ifdef DIRECTX_ENABLE_XMA2
case WAVE_FORMAT_XMA2:
if (!seekCount || !seekTable)
{
DebugTrace("ERROR: SoundEffect format XMA2 requires seek table\n");
return E_FAIL;
}
if (seekCount > UINT32_MAX)
return E_INVALIDARG;
{
HRESULT hr = ApuAlloc(&mXMAMemory, nullptr,
static_cast<UINT32>(audioBytes), SHAPE_XMA_INPUT_BUFFER_ALIGNMENT);
if (FAILED(hr))
{
DebugTrace("ERROR: ApuAlloc failed. Did you allocate a large enough heap with ApuCreateHeap for all your XMA wave data?\n");
return hr;
}
}
memcpy(mXMAMemory, startAudio, audioBytes);
mStartAudio = reinterpret_cast<const uint8_t*>(mXMAMemory);
mWavData.reset(new (std::nothrow) uint8_t[sizeof(XMA2WAVEFORMATEX) + (seekCount * sizeof(uint32_t))]);
if (!mWavData)
return E_OUTOFMEMORY;
memcpy(mWavData.get(), wfx, sizeof(XMA2WAVEFORMATEX));
mWaveFormat = reinterpret_cast<WAVEFORMATEX*>(mWavData.get());
// XMA seek table is Big-Endian
{
auto dest = reinterpret_cast<uint32_t*>(mWavData.get() + sizeof(XMA2WAVEFORMATEX));
for (size_t k = 0; k < seekCount; ++k)
{
dest[k] = _byteswap_ulong(seekTable[k]);
}
}
mSeekCount = static_cast<uint32_t>(seekCount);
mSeekTable = reinterpret_cast<const uint32_t*>(mWavData.get() + sizeof(XMA2WAVEFORMATEX));
wavData.reset();
break;
#endif // XMA2
default:
case WAVE_FORMAT_WMAUDIO2:
case WAVE_FORMAT_WMAUDIO3:
if (!seekCount || !seekTable)
{
DebugTrace("ERROR: SoundEffect encountered an unsupported format tag (%u)\n", wfx->wFormatTag);
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
DebugTrace("ERROR: SoundEffect format xWMA requires seek table\n");
return E_FAIL;
}
if (seekCount > UINT32_MAX)
return E_INVALIDARG;
// Take ownership of the buffer
mWavData.reset(wavData.release());
// WARNING: We assume the wfx, startAudio, and mSeekTable parameters are pointers into the wavData memory buffer
mWaveFormat = wfx;
mStartAudio = startAudio;
mSeekCount = static_cast<uint32_t>(seekCount);
mSeekTable = seekTable;
break;
#endif // xWMA
#ifdef DIRECTX_ENABLE_XMA2
case WAVE_FORMAT_XMA2:
if (!seekCount || !seekTable)
{
DebugTrace("ERROR: SoundEffect format XMA2 requires seek table\n");
return E_FAIL;
}
if (seekCount > UINT32_MAX)
return E_INVALIDARG;
{
HRESULT hr = ApuAlloc(&mXMAMemory, nullptr,
static_cast<UINT32>(audioBytes), SHAPE_XMA_INPUT_BUFFER_ALIGNMENT);
if (FAILED(hr))
{
DebugTrace("ERROR: ApuAlloc failed. Did you allocate a large enough heap with ApuCreateHeap for all your XMA wave data?\n");
return hr;
}
}
memcpy(mXMAMemory, startAudio, audioBytes);
mStartAudio = reinterpret_cast<const uint8_t*>(mXMAMemory);
mWavData.reset(new (std::nothrow) uint8_t[sizeof(XMA2WAVEFORMATEX) + (seekCount * sizeof(uint32_t))]);
if (!mWavData)
return E_OUTOFMEMORY;
memcpy(mWavData.get(), wfx, sizeof(XMA2WAVEFORMATEX));
mWaveFormat = reinterpret_cast<WAVEFORMATEX*>(mWavData.get());
// XMA seek table is Big-Endian
{
auto dest = reinterpret_cast<uint32_t*>(mWavData.get() + sizeof(XMA2WAVEFORMATEX));
for (size_t k = 0; k < seekCount; ++k)
{
dest[k] = _byteswap_ulong(seekTable[k]);
}
}
mSeekCount = static_cast<uint32_t>(seekCount);
mSeekTable = reinterpret_cast<const uint32_t*>(mWavData.get() + sizeof(XMA2WAVEFORMATEX));
wavData.reset();
break;
#endif // XMA2
default:
{
DebugTrace("ERROR: SoundEffect encountered an unsupported format tag (%u)\n", wfx->wFormatTag);
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
}
mAudioBytes = static_cast<uint32_t>(audioBytes);
@ -311,7 +317,7 @@ void SoundEffect::Impl::Play(float volume, float pitch, float pan)
if (pitch != 0.f)
{
float fr = XAudio2SemitonesToFrequencyRatio(pitch * 12.f);
const float fr = XAudio2SemitonesToFrequencyRatio(pitch * 12.f);
HRESULT hr = voice->SetFrequencyRatio(fr);
ThrowIfFailed(hr);
@ -337,7 +343,7 @@ void SoundEffect::Impl::Play(float volume, float pitch, float pan)
buffer.pContext = this;
#ifdef DIRECTX_ENABLE_XWMA
uint32_t tag = GetFormatTag(mWaveFormat);
const uint32_t tag = GetFormatTag(mWaveFormat);
if (tag == WAVE_FORMAT_WMAUDIO2 || tag == WAVE_FORMAT_WMAUDIO3)
{
XAUDIO2_BUFFER_WMA wmaBuffer = {};
@ -517,7 +523,7 @@ size_t SoundEffect::GetSampleDuration() const noexcept
auto adpcmFmt = reinterpret_cast<const ADPCMWAVEFORMAT*>(pImpl->mWaveFormat);
uint64_t duration = uint64_t(pImpl->mAudioBytes / adpcmFmt->wfx.nBlockAlign) * adpcmFmt->wSamplesPerBlock;
unsigned int partial = pImpl->mAudioBytes % adpcmFmt->wfx.nBlockAlign;
const unsigned int partial = pImpl->mAudioBytes % adpcmFmt->wfx.nBlockAlign;
if (partial)
{
if (partial >= (7u * adpcmFmt->wfx.nChannels))
@ -562,7 +568,7 @@ size_t SoundEffect::GetSampleDurationMS() const noexcept
if (!pImpl->mWaveFormat || !pImpl->mWaveFormat->nSamplesPerSec)
return 0;
uint64_t samples = GetSampleDuration();
const uint64_t samples = GetSampleDuration();
return static_cast<size_t>((samples * 1000) / pImpl->mWaveFormat->nSamplesPerSec);
}
@ -585,7 +591,7 @@ bool SoundEffect::FillSubmitBuffer(_Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_B
buffer.LoopBegin = pImpl->mLoopStart;
buffer.LoopLength = pImpl->mLoopLength;
uint32_t tag = GetFormatTag(pImpl->mWaveFormat);
const uint32_t tag = GetFormatTag(pImpl->mWaveFormat);
if (tag == WAVE_FORMAT_WMAUDIO2 || tag == WAVE_FORMAT_WMAUDIO3)
{
wmaBuffer.PacketCount = pImpl->mSeekCount;

Просмотреть файл

@ -209,7 +209,7 @@ void SoundEffectInstance::Impl::Play(bool loop)
auto wfx = (mWaveBank) ? mWaveBank->GetFormat(mIndex, reinterpret_cast<WAVEFORMATEX*>(buff), sizeof(buff))
: mEffect->GetFormat();
size_t length = (mWaveBank) ? mWaveBank->GetSampleSizeInBytes(mIndex) : mEffect->GetSampleSizeInBytes();
const size_t length = (mWaveBank) ? mWaveBank->GetSampleSizeInBytes(mIndex) : mEffect->GetSampleSizeInBytes();
DebugTrace("\tFormat Tag %u, %u channels, %u-bit, %u Hz, %zu bytes\n",
wfx->wFormatTag, wfx->nChannels, wfx->wBitsPerSample, wfx->nSamplesPerSec, length);

Просмотреть файл

@ -39,16 +39,16 @@ using namespace DirectX;
namespace
{
const size_t DVD_SECTOR_SIZE = 2048;
const size_t ADVANCED_FORMAT_SECTOR_SIZE = 4096;
const size_t MAX_BUFFER_COUNT = 3;
constexpr size_t DVD_SECTOR_SIZE = 2048;
constexpr size_t ADVANCED_FORMAT_SECTOR_SIZE = 4096;
constexpr size_t MAX_BUFFER_COUNT = 3;
#ifdef DIRECTX_ENABLE_SEEK_TABLES
const size_t MAX_STREAMING_SEEK_PACKETS = 2048;
constexpr size_t MAX_STREAMING_SEEK_PACKETS = 2048;
#endif
#ifdef DIRECTX_ENABLE_XMA2
const size_t XMA2_64KBLOCKINBYTES = 65536;
constexpr size_t XMA2_64KBLOCKINBYTES = 65536;
struct apu_deleter { void operator()(void* p) noexcept { if (p) ApuFree(p); } };
#endif
@ -401,7 +401,7 @@ HRESULT SoundStreamInstance::Impl::AllocateStreamingBuffers(const WAVEFORMATEX*
if (!wfx)
return E_INVALIDARG;
uint32_t tag = GetFormatTag(wfx);
const uint32_t tag = GetFormatTag(wfx);
size_t packetSize = ComputeAsyncPacketSize(wfx, tag, mAsyncAlign);
if (!packetSize)
@ -511,7 +511,7 @@ HRESULT SoundStreamInstance::Impl::ReadBuffers() noexcept
HANDLE async = mWaveBank->GetAsyncHandle();
uint32_t readBuffer = mCurrentDiskReadBuffer;
const uint32_t readBuffer = mCurrentDiskReadBuffer;
for (uint32_t j = 0; j < MAX_BUFFER_COUNT; ++j)
{
uint32_t entry = (j + readBuffer) % uint32_t(MAX_BUFFER_COUNT);
@ -519,7 +519,7 @@ HRESULT SoundStreamInstance::Impl::ReadBuffers() noexcept
{
if (mCurrentPosition < mLengthInBytes)
{
auto cbValid = static_cast<uint32_t>(std::min(mPacketSize, mLengthInBytes - mCurrentPosition));
auto const cbValid = static_cast<uint32_t>(std::min(mPacketSize, mLengthInBytes - mCurrentPosition));
mPackets[entry].valid = cbValid;
mPackets[entry].audioBytes = 0;
@ -528,7 +528,7 @@ HRESULT SoundStreamInstance::Impl::ReadBuffers() noexcept
if (!ReadFile(async, mPackets[entry].buffer, uint32_t(mPacketSize), nullptr, &mPackets[entry].request))
{
DWORD error = GetLastError();
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
{
#ifdef _DEBUG
@ -573,9 +573,9 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
{
DWORD cb = 0;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
BOOL result = GetOverlappedResultEx(async, &mPackets[j].request, &cb, 0, FALSE);
const BOOL result = GetOverlappedResultEx(async, &mPackets[j].request, &cb, 0, FALSE);
#else
BOOL result = GetOverlappedResult(async, &mPackets[j].request, &cb, FALSE);
const BOOL result = GetOverlappedResult(async, &mPackets[j].request, &cb, FALSE);
#endif
if (result)
{
@ -583,7 +583,7 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
}
else
{
DWORD error = GetLastError();
const DWORD error = GetLastError();
if (error != ERROR_IO_INCOMPLETE)
{
ThrowIfFailed(HRESULT_FROM_WIN32(error));
@ -625,7 +625,7 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
// Compute how many bytes at the start of our current packet are the tail of the partial block.
thisFrameStitch = mBlockAlign - prevFrameStitch;
uint32_t k = (mCurrentPlayBuffer + MAX_BUFFER_COUNT - 1) % MAX_BUFFER_COUNT;
const uint32_t k = (mCurrentPlayBuffer + MAX_BUFFER_COUNT - 1) % MAX_BUFFER_COUNT;
if (mPackets[k].state == State::READY || mPackets[k].state == State::PLAYING)
{
// Compute how many bytes at the start of the previous packet were the tail of the previous stitch block.
@ -633,7 +633,7 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
prevFrameStitchOffset = (prevFrameStitchOffset > 0) ? (mBlockAlign - prevFrameStitchOffset) : 0u;
// Point to the start of the partial block's head in the previous packet.
auto prevBuffer = mPackets[k].buffer + prevFrameStitchOffset + mPackets[k].audioBytes;
const auto *prevBuffer = mPackets[k].buffer + prevFrameStitchOffset + mPackets[k].audioBytes;
// Merge the the head partial block in the previous packet with the tail partial block at the start of our packet.
memcpy(buffer, prevBuffer, prevFrameStitch);
@ -659,7 +659,7 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
wmaBuf.pDecodedPacketCumulativeBytes = mSeekTableCopy;
wmaBuf.PacketCount = 1;
uint32_t seekOffset = (mPackets[k].startPosition + prevFrameStitchOffset + mPackets[k].audioBytes) / mBlockAlign;
const uint32_t seekOffset = (mPackets[k].startPosition + prevFrameStitchOffset + mPackets[k].audioBytes) / mBlockAlign;
assert(seekOffset > 0);
mSeekTableCopy[0] = mSeekTable[seekOffset] - mSeekTable[seekOffset - 1];
@ -697,7 +697,7 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
wmaBuf.PacketCount = valid / mBlockAlign;
uint32_t seekOffset = mPackets[mCurrentPlayBuffer].startPosition / mBlockAlign;
const uint32_t seekOffset = mPackets[mCurrentPlayBuffer].startPosition / mBlockAlign;
if (seekOffset > MAX_STREAMING_SEEK_PACKETS)
{
DebugTrace("ERROR: xWMA packet seek count exceeds %zu\n", MAX_STREAMING_SEEK_PACKETS);
@ -835,7 +835,7 @@ bool SoundStreamInstance::IsLooped() const noexcept
SoundState SoundStreamInstance::GetState() noexcept
{
SoundState state = pImpl->mBase.GetState(pImpl->mEndStream);
const SoundState state = pImpl->mBase.GetState(pImpl->mEndStream);
if (state == STOPPED)
{
pImpl->mPlaying = false;

Просмотреть файл

@ -123,7 +123,7 @@ namespace
if (header->tag == tag)
return header;
auto offset = header->size + sizeof(RIFFChunk);
auto const offset = header->size + sizeof(RIFFChunk);
ptr += offset;
}

Просмотреть файл

@ -72,7 +72,7 @@ public:
}
}
HRESULT Initialize(_In_ AudioEngine* engine, _In_z_ const wchar_t* wbFileName) noexcept;
HRESULT Initialize(_In_ const AudioEngine* engine, _In_z_ const wchar_t* wbFileName) noexcept;
void Play(unsigned int index, float volume, float pitch, float pan);
@ -138,7 +138,7 @@ public:
_Use_decl_annotations_
HRESULT WaveBank::Impl::Initialize(AudioEngine* engine, const wchar_t* wbFileName) noexcept
HRESULT WaveBank::Impl::Initialize(const AudioEngine* engine, const wchar_t* wbFileName) noexcept
{
if (!engine || !wbFileName)
return E_INVALIDARG;
@ -197,7 +197,7 @@ void WaveBank::Impl::Play(unsigned int index, float volume, float pitch, float p
if (pitch != 0.f)
{
float fr = XAudio2SemitonesToFrequencyRatio(pitch * 12.f);
const float fr = XAudio2SemitonesToFrequencyRatio(pitch * 12.f);
hr = voice->SetFrequencyRatio(fr);
ThrowIfFailed(hr);
@ -298,7 +298,7 @@ void WaveBank::Play(unsigned int index, float volume, float pitch, float pan)
void WaveBank::Play(_In_z_ const char* name)
{
unsigned int index = pImpl->mReader.Find(name);
const unsigned int index = pImpl->mReader.Find(name);
if (index == unsigned(-1))
{
DebugTrace("WARNING: Name '%hs' not found in wave bank, one-shot not triggered\n", name);
@ -311,7 +311,7 @@ void WaveBank::Play(_In_z_ const char* name)
void WaveBank::Play(_In_z_ const char* name, float volume, float pitch, float pan)
{
unsigned int index = pImpl->mReader.Find(name);
const unsigned int index = pImpl->mReader.Find(name);
if (index == unsigned(-1))
{
DebugTrace("WARNING: Name '%hs' not found in wave bank, one-shot not triggered\n", name);
@ -354,7 +354,7 @@ std::unique_ptr<SoundEffectInstance> WaveBank::CreateInstance(unsigned int index
std::unique_ptr<SoundEffectInstance> WaveBank::CreateInstance(_In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags)
{
unsigned int index = pImpl->mReader.Find(name);
const unsigned int index = pImpl->mReader.Find(name);
if (index == unsigned(-1))
{
// We don't throw an exception here as titles often simply ignore missing assets rather than fail
@ -397,7 +397,7 @@ std::unique_ptr<SoundStreamInstance> WaveBank::CreateStreamInstance(unsigned int
std::unique_ptr<SoundStreamInstance> WaveBank::CreateStreamInstance(_In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags)
{
unsigned int index = pImpl->mReader.Find(name);
const unsigned int index = pImpl->mReader.Find(name);
if (index == unsigned(-1))
{
// We don't throw an exception here as titles often simply ignore missing assets rather than fail

Просмотреть файл

@ -176,7 +176,7 @@ namespace
1280
};
uint32_t dwBlockAlignIndex = wBlockAlign & 0x1F;
const uint32_t dwBlockAlignIndex = wBlockAlign & 0x1F;
if (dwBlockAlignIndex < 17)
return aWMABlockAlign[dwBlockAlignIndex];
}
@ -198,8 +198,8 @@ namespace
case TAG_ADPCM:
{
uint32_t blockAlign = BlockAlign();
uint32_t samplesPerAdpcmBlock = AdpcmSamplesPerBlock();
const uint32_t blockAlign = BlockAlign();
const uint32_t samplesPerAdpcmBlock = AdpcmSamplesPerBlock();
return blockAlign * nSamplesPerSec / samplesPerAdpcmBlock;
}
@ -217,7 +217,7 @@ namespace
};
// bitrate = entry * 8
uint32_t dwBytesPerSecIndex = wBlockAlign >> 5;
const uint32_t dwBytesPerSecIndex = wBlockAlign >> 5;
if (dwBytesPerSecIndex < 7)
return aWMAAvgBytesPerSec[dwBytesPerSecIndex];
}
@ -229,7 +229,7 @@ namespace
DWORD AdpcmSamplesPerBlock() const noexcept
{
uint32_t nBlockAlign = (wBlockAlign + ADPCM_BLOCKALIGN_CONVERSION_OFFSET) * nChannels;
const uint32_t nBlockAlign = (wBlockAlign + ADPCM_BLOCKALIGN_CONVERSION_OFFSET) * nChannels;
return nBlockAlign * 2 / uint32_t(nChannels) - 12;
}
@ -349,7 +349,7 @@ namespace
case MINIWAVEFORMAT::TAG_ADPCM:
{
uint32_t duration = (length / data.CompactFormat.BlockAlign()) * data.CompactFormat.AdpcmSamplesPerBlock();
uint32_t partial = length % data.CompactFormat.BlockAlign();
const uint32_t partial = length % data.CompactFormat.BlockAlign();
if (partial)
{
if (partial >= (7u * data.CompactFormat.nChannels))
@ -361,7 +361,7 @@ namespace
case MINIWAVEFORMAT::TAG_WMA:
if (seekTable)
{
uint32_t seekCount = *seekTable;
const uint32_t seekCount = *seekTable;
if (seekCount > 0)
{
return seekTable[seekCount] / uint32_t(2 * data.CompactFormat.nChannels);
@ -372,7 +372,7 @@ namespace
case MINIWAVEFORMAT::TAG_XMA:
if (seekTable)
{
uint32_t seekCount = *seekTable;
const uint32_t seekCount = *seekTable;
if (seekCount > 0)
{
return seekTable[seekCount];
@ -394,7 +394,7 @@ namespace
if (!seekTable || index >= data.dwEntryCount)
return nullptr;
uint32_t seekSize = header.Segments[HEADER::SEGIDX_SEEKTABLES].dwLength;
const uint32_t seekSize = header.Segments[HEADER::SEGIDX_SEEKTABLES].dwLength;
if ((index * sizeof(uint32_t)) > seekSize)
return nullptr;
@ -544,7 +544,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
bool wait = false;
if (!ReadFile(hFile.get(), &m_header, sizeof(m_header), nullptr, &request))
{
DWORD error = GetLastError();
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
return HRESULT_FROM_WIN32(error);
wait = true;
@ -574,7 +574,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
return E_FAIL;
}
bool be = (m_header.dwSignature == HEADER::BE_SIGNATURE);
const bool be = (m_header.dwSignature == HEADER::BE_SIGNATURE);
if (be)
{
DebugTrace("INFO: \"%ls\" is a big-endian (Xbox 360) wave bank\n", szFileName);
@ -594,7 +594,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
wait = false;
if (!ReadFile(hFile.get(), &m_data, sizeof(m_data), nullptr, &request))
{
DWORD error = GetLastError();
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
return HRESULT_FROM_WIN32(error);
wait = true;
@ -657,14 +657,14 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
}
}
DWORD metadataBytes = m_header.Segments[HEADER::SEGIDX_ENTRYMETADATA].dwLength;
const DWORD metadataBytes = m_header.Segments[HEADER::SEGIDX_ENTRYMETADATA].dwLength;
if (metadataBytes != (m_data.dwEntryCount * m_data.dwEntryMetaDataElementSize))
{
return E_FAIL;
}
// Load names
DWORD namesBytes = m_header.Segments[HEADER::SEGIDX_ENTRYNAMES].dwLength;
const DWORD namesBytes = m_header.Segments[HEADER::SEGIDX_ENTRYNAMES].dwLength;
if (namesBytes > 0)
{
if (namesBytes >= (m_data.dwEntryNameElementSize * m_data.dwEntryCount))
@ -680,7 +680,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
wait = false;
if (!ReadFile(hFile.get(), temp.get(), namesBytes, nullptr, &request))
{
DWORD error = GetLastError();
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
return HRESULT_FROM_WIN32(error);
wait = true;
@ -704,7 +704,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
for (uint32_t j = 0; j < m_data.dwEntryCount; ++j)
{
DWORD n = m_data.dwEntryNameElementSize * j;
const DWORD n = m_data.dwEntryNameElementSize * j;
char name[64] = {};
strncpy_s(name, &temp[n], sizeof(name));
@ -733,7 +733,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
wait = false;
if (!ReadFile(hFile.get(), m_entries.get(), metadataBytes, nullptr, &request))
{
DWORD error = GetLastError();
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
return HRESULT_FROM_WIN32(error);
wait = true;
@ -772,7 +772,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
}
// Load seek tables (XMA2 / xWMA)
DWORD seekLen = m_header.Segments[HEADER::SEGIDX_SEEKTABLES].dwLength;
const DWORD seekLen = m_header.Segments[HEADER::SEGIDX_SEEKTABLES].dwLength;
if (seekLen > 0)
{
m_seekData.reset(new (std::nothrow) uint8_t[seekLen]);
@ -786,7 +786,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
wait = false;
if (!ReadFile(hFile.get(), m_seekData.get(), seekLen, nullptr, &request))
{
DWORD error = GetLastError();
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
return HRESULT_FROM_WIN32(error);
wait = true;
@ -818,7 +818,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
}
}
DWORD waveLen = m_header.Segments[HEADER::SEGIDX_ENTRYWAVEDATA].dwLength;
const DWORD waveLen = m_header.Segments[HEADER::SEGIDX_ENTRYWAVEDATA].dwLength;
if (!waveLen)
{
return HRESULT_FROM_WIN32(ERROR_NO_DATA);
@ -907,7 +907,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
if (!ReadFile(hFile.get(), dest, waveLen, nullptr, &m_request))
{
DWORD error = GetLastError();
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
return HRESULT_FROM_WIN32(error);
}
@ -1232,7 +1232,7 @@ HRESULT WaveBankReader::Impl::GetMetadata(uint32_t index, Metadata& metadata) co
if (m_data.dwFlags & BANKDATA::TYPE_STREAMING)
{
uint64_t offset = uint64_t(metadata.offsetBytes) + uint64_t(m_header.Segments[HEADER::SEGIDX_ENTRYWAVEDATA].dwOffset);
const uint64_t offset = uint64_t(metadata.offsetBytes) + uint64_t(m_header.Segments[HEADER::SEGIDX_ENTRYWAVEDATA].dwOffset);
if (offset > UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
@ -1256,9 +1256,9 @@ bool WaveBankReader::Impl::UpdatePrepared() noexcept
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
DWORD bytes;
BOOL result = GetOverlappedResultEx(m_async, &m_request, &bytes, 0, FALSE);
const BOOL result = GetOverlappedResultEx(m_async, &m_request, &bytes, 0, FALSE);
#else
bool result = HasOverlappedIoCompleted(&m_request);
const bool result = HasOverlappedIoCompleted(&m_request);
#endif
if (result)
{

Просмотреть файл

@ -479,10 +479,10 @@ namespace DirectX
void XM_CALLCONV SetOrientationFromQuaternion(FXMVECTOR quat) noexcept
{
XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat);
const XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat);
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientFront), forward);
XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat);
const XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat);
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientTop), up);
}
@ -491,10 +491,10 @@ namespace DirectX
{
if (dt > 0.f)
{
XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast<const XMFLOAT3*>(&Position));
const XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast<const XMFLOAT3*>(&Position));
XMVECTOR vDelta = XMVectorSubtract(newPos, lastPos);
XMVECTOR vt = XMVectorReplicate(dt);
const XMVECTOR vt = XMVectorReplicate(dt);
XMVECTOR v = XMVectorDivide(vDelta, vt);
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&Velocity), v);
@ -573,10 +573,10 @@ namespace DirectX
void XM_CALLCONV SetOrientationFromQuaternion(FXMVECTOR quat) noexcept
{
XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat);
const XMVECTOR forward = XMVector3Rotate(g_XMIdentityR2, quat);
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientFront), forward);
XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat);
const XMVECTOR up = XMVector3Rotate(g_XMIdentityR1, quat);
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientTop), up);
}
@ -585,10 +585,10 @@ namespace DirectX
{
if (dt > 0.f)
{
XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast<const XMFLOAT3*>(&Position));
const XMVECTOR lastPos = XMLoadFloat3(reinterpret_cast<const XMFLOAT3*>(&Position));
XMVECTOR vDelta = XMVectorSubtract(newPos, lastPos);
XMVECTOR vt = XMVectorReplicate(dt);
const XMVECTOR vt = XMVectorReplicate(dt);
XMVECTOR v = XMVectorDivide(vDelta, vt);
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&Velocity), v);

Просмотреть файл

@ -142,8 +142,8 @@ namespace DirectX
// Special overload of Allocate that aligns to D3D12 constant buffer alignment requirements
template<typename T> GraphicsResource AllocateConstant()
{
const size_t alignment = D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT;
const size_t alignedSize = (sizeof(T) + alignment - 1) & ~(alignment - 1);
constexpr size_t alignment = D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT;
constexpr size_t alignedSize = (sizeof(T) + alignment - 1) & ~(alignment - 1);
return Allocate(alignedSize, alignment);
}
template<typename T> GraphicsResource AllocateConstant(const T& setData)

Просмотреть файл

@ -413,7 +413,7 @@ namespace DirectX
if (key <= 0xfe)
{
auto ptr = reinterpret_cast<const uint32_t*>(this);
unsigned int bf = 1u << (key & 0x1f);
const unsigned int bf = 1u << (key & 0x1f);
return (ptr[(key >> 5)] & bf) != 0;
}
return false;
@ -424,7 +424,7 @@ namespace DirectX
if (key <= 0xfe)
{
auto ptr = reinterpret_cast<const uint32_t*>(this);
unsigned int bf = 1u << (key & 0x1f);
const unsigned int bf = 1u << (key & 0x1f);
return (ptr[(key >> 5)] & bf) == 0;
}
return false;

Просмотреть файл

@ -527,7 +527,7 @@ namespace DirectX
if (materialIndex >= materials.size())
return handle;
int textureIndex = materials[materialIndex].diffuseTextureIndex;
const int textureIndex = materials[materialIndex].diffuseTextureIndex;
if (textureIndex == -1)
return handle;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -188,14 +188,14 @@ AlphaTestEffect::Impl::Impl(
// Create root signature.
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
CD3DX12_DESCRIPTOR_RANGE textureRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
CD3DX12_DESCRIPTOR_RANGE textureSamplerRange(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSamplerRange(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
CD3DX12_ROOT_PARAMETER rootParameters[RootParameterIndex::RootParameterCount] = {};
rootParameters[RootParameterIndex::TextureSRV].InitAsDescriptorTable(1, &textureRange, D3D12_SHADER_VISIBILITY_PIXEL);
@ -229,14 +229,14 @@ AlphaTestEffect::Impl::Impl(
}
// Create pipeline state.
int sp = GetPipelineStatePermutation(effectFlags);
const int sp = GetPipelineStatePermutation(effectFlags);
assert(sp >= 0 && sp < AlphaTestEffectTraits::ShaderPermutationCount);
_Analysis_assume_(sp >= 0 && sp < AlphaTestEffectTraits::ShaderPermutationCount);
int vi = EffectBase<AlphaTestEffectTraits>::VertexShaderIndices[sp];
const int vi = EffectBase<AlphaTestEffectTraits>::VertexShaderIndices[sp];
assert(vi >= 0 && vi < AlphaTestEffectTraits::VertexShaderCount);
_Analysis_assume_(vi >= 0 && vi < AlphaTestEffectTraits::VertexShaderCount);
int pi = EffectBase<AlphaTestEffectTraits>::PixelShaderIndices[sp];
const int pi = EffectBase<AlphaTestEffectTraits>::PixelShaderIndices[sp];
assert(pi >= 0 && pi < AlphaTestEffectTraits::PixelShaderCount);
_Analysis_assume_(pi >= 0 && pi < AlphaTestEffectTraits::PixelShaderCount);
@ -292,10 +292,10 @@ void AlphaTestEffect::Impl::Apply(_In_ ID3D12GraphicsCommandList* commandList)
if (dirtyFlags & EffectDirtyFlags::AlphaTest)
{
// Convert reference alpha from 8 bit integer to 0-1 float format.
auto reference = static_cast<float>(referenceAlpha) / 255.0f;
auto const reference = static_cast<float>(referenceAlpha) / 255.0f;
// Comparison tolerance of half the 8 bit integer precision.
const float threshold = 0.5f / 255.0f;
constexpr float threshold = 0.5f / 255.0f;
// What to do if the alpha comparison passes or fails. Positive accepts the pixel, negative clips it.
static const XMVECTORF32 selectIfTrue = { { { 1, -1 } } };

Просмотреть файл

@ -437,11 +437,11 @@ BasicEffect::Impl::Impl(
// Create root signature.
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
// Create root parameters and initialize first (constants)
CD3DX12_ROOT_PARAMETER rootParameters[RootParameterIndex::RootParameterCount] = {};
@ -453,8 +453,8 @@ BasicEffect::Impl::Impl(
if (textureEnabled)
{
// Include texture and srv
CD3DX12_DESCRIPTOR_RANGE textureSRV(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
CD3DX12_DESCRIPTOR_RANGE textureSampler(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSRV(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSampler(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
rootParameters[RootParameterIndex::TextureSRV].InitAsDescriptorTable(1, &textureSRV, D3D12_SHADER_VISIBILITY_PIXEL);
rootParameters[RootParameterIndex::TextureSampler].InitAsDescriptorTable(1, &textureSampler, D3D12_SHADER_VISIBILITY_PIXEL);
@ -476,14 +476,14 @@ BasicEffect::Impl::Impl(
assert(mRootSignature != nullptr);
// Create pipeline state.
int sp = GetPipelineStatePermutation(effectFlags);
const int sp = GetPipelineStatePermutation(effectFlags);
assert(sp >= 0 && sp < BasicEffectTraits::ShaderPermutationCount);
_Analysis_assume_(sp >= 0 && sp < BasicEffectTraits::ShaderPermutationCount);
int vi = EffectBase<BasicEffectTraits>::VertexShaderIndices[sp];
const int vi = EffectBase<BasicEffectTraits>::VertexShaderIndices[sp];
assert(vi >= 0 && vi < BasicEffectTraits::VertexShaderCount);
_Analysis_assume_(vi >= 0 && vi < BasicEffectTraits::VertexShaderCount);
int pi = EffectBase<BasicEffectTraits>::PixelShaderIndices[sp];
const int pi = EffectBase<BasicEffectTraits>::PixelShaderIndices[sp];
assert(pi >= 0 && pi < BasicEffectTraits::PixelShaderCount);
_Analysis_assume_(pi >= 0 && pi < BasicEffectTraits::PixelShaderCount);

Просмотреть файл

@ -249,16 +249,16 @@ BasicPostProcess::Impl::Impl(_In_ ID3D12Device* device, const RenderTargetState&
// Create root signature.
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
CD3DX12_DESCRIPTOR_RANGE textureSRVs(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSRVs(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
// Same as CommonStates::StaticLinearClamp
CD3DX12_STATIC_SAMPLER_DESC sampler(
const CD3DX12_STATIC_SAMPLER_DESC sampler(
0, // register
D3D12_FILTER_MIN_MAG_MIP_LINEAR,
D3D12_TEXTURE_ADDRESS_MODE_CLAMP,
@ -300,7 +300,7 @@ BasicPostProcess::Impl::Impl(_In_ ID3D12Device* device, const RenderTargetState&
assert(mRootSignature != nullptr);
// Create pipeline state.
EffectPipelineStateDescription psd(nullptr,
const EffectPipelineStateDescription psd(nullptr,
CommonStates::Opaque,
CommonStates::DepthNone,
CommonStates::CullNone,
@ -394,8 +394,8 @@ void BasicPostProcess::Impl::DownScale2x2()
throw std::logic_error("Call SetSourceTexture before setting post-process effect");
}
float tu = 1.0f / float(texWidth);
float tv = 1.0f / float(texHeight);
const float tu = 1.0f / float(texWidth);
const float tv = 1.0f / float(texHeight);
// Sample from the 4 surrounding points. Since the center point will be in the exact
// center of 4 texels, a 0.5f offset is needed to specify a texel center.
@ -421,8 +421,8 @@ void BasicPostProcess::Impl::DownScale4x4()
throw std::logic_error("Call SetSourceTexture before setting post-process effect");
}
float tu = 1.0f / float(texWidth);
float tv = 1.0f / float(texHeight);
const float tu = 1.0f / float(texWidth);
const float tv = 1.0f / float(texHeight);
// Sample from the 16 surrounding points. Since the center point will be in the
// exact center of 16 texels, a 1.5f offset is needed to specify a texel center.
@ -449,8 +449,8 @@ void BasicPostProcess::Impl::GaussianBlur5x5(float multiplier)
throw std::logic_error("Call SetSourceTexture before setting post-process effect");
}
float tu = 1.0f / float(texWidth);
float tv = 1.0f / float(texHeight);
const float tu = 1.0f / float(texWidth);
const float tv = 1.0f / float(texHeight);
float totalWeight = 0.0f;
size_t index = 0;
@ -473,7 +473,7 @@ void BasicPostProcess::Impl::GaussianBlur5x5(float multiplier)
offsets[index].z = 0.0f;
offsets[index].w = 0.0f;
float g = GaussianDistribution(float(x), float(y), 1.0f);
const float g = GaussianDistribution(float(x), float(y), 1.0f);
weights[index] = XMVectorReplicate(g);
totalWeight += XMVectorGetX(weights[index]);
@ -486,11 +486,11 @@ void BasicPostProcess::Impl::GaussianBlur5x5(float multiplier)
// blur kernels add to 1.0f to ensure that the intensity of the image isn't
// changed when the blur occurs. An optional multiplier variable is used to
// add or remove image intensity during the blur.
XMVECTOR vtw = XMVectorReplicate(totalWeight);
XMVECTOR vm = XMVectorReplicate(multiplier);
const XMVECTOR vtw = XMVectorReplicate(totalWeight);
const XMVECTOR vm = XMVectorReplicate(multiplier);
for (size_t i = 0; i < index; ++i)
{
XMVECTOR w = XMVectorDivide(weights[i], vtw);
const XMVECTOR w = XMVectorDivide(weights[i], vtw);
weights[i] = XMVectorMultiply(w, vm);
}
}

Просмотреть файл

@ -33,10 +33,10 @@ namespace Bezier
{
using namespace DirectX;
XMVECTOR T0 = XMVectorReplicate((1 - t) * (1 - t) * (1 - t));
XMVECTOR T1 = XMVectorReplicate(3 * t * (1 - t) * (1 - t));
XMVECTOR T2 = XMVectorReplicate(3 * t * t * (1 - t));
XMVECTOR T3 = XMVectorReplicate(t * t * t);
const XMVECTOR T0 = XMVectorReplicate((1 - t) * (1 - t) * (1 - t));
const XMVECTOR T1 = XMVectorReplicate(3 * t * (1 - t) * (1 - t));
const XMVECTOR T2 = XMVectorReplicate(3 * t * t * (1 - t));
const XMVECTOR T3 = XMVectorReplicate(t * t * t);
XMVECTOR Result = XMVectorMultiply(p1, T0);
Result = XMVectorMultiplyAdd(p2, T1, Result);
@ -62,10 +62,10 @@ namespace Bezier
{
using namespace DirectX;
XMVECTOR T0 = XMVectorReplicate(-1 + 2 * t - t * t);
XMVECTOR T1 = XMVectorReplicate(1 - 4 * t + 3 * t * t);
XMVECTOR T2 = XMVectorReplicate(2 * t - 3 * t * t);
XMVECTOR T3 = XMVectorReplicate(t * t);
const XMVECTOR T0 = XMVectorReplicate(-1 + 2 * t - t * t);
const XMVECTOR T1 = XMVectorReplicate(1 - 4 * t + 3 * t * t);
const XMVECTOR T2 = XMVectorReplicate(2 * t - 3 * t * t);
const XMVECTOR T3 = XMVectorReplicate(t * t);
XMVECTOR Result = XMVectorMultiply(p1, T0);
Result = XMVectorMultiplyAdd(p2, T1, Result);
@ -80,39 +80,39 @@ namespace Bezier
// Calls the specified outputVertex function for each generated vertex,
// passing the position, normal, and texture coordinate as parameters.
template<typename TOutputFunc>
void CreatePatchVertices(_In_reads_(16) DirectX::XMVECTOR patch[16], size_t tessellation, bool isMirrored, TOutputFunc outputVertex)
void CreatePatchVertices(_In_reads_(16) const DirectX::XMVECTOR patch[16], size_t tessellation, bool isMirrored, TOutputFunc outputVertex)
{
using namespace DirectX;
for (size_t i = 0; i <= tessellation; i++)
{
float u = float(i) / float(tessellation);
const float u = float(i) / float(tessellation);
for (size_t j = 0; j <= tessellation; j++)
{
float v = float(j) / float(tessellation);
const float v = float(j) / float(tessellation);
// Perform four horizontal bezier interpolations
// between the control points of this patch.
XMVECTOR p1 = CubicInterpolate(patch[0], patch[1], patch[2], patch[3], u);
XMVECTOR p2 = CubicInterpolate(patch[4], patch[5], patch[6], patch[7], u);
XMVECTOR p3 = CubicInterpolate(patch[8], patch[9], patch[10], patch[11], u);
XMVECTOR p4 = CubicInterpolate(patch[12], patch[13], patch[14], patch[15], u);
const XMVECTOR p1 = CubicInterpolate(patch[0], patch[1], patch[2], patch[3], u);
const XMVECTOR p2 = CubicInterpolate(patch[4], patch[5], patch[6], patch[7], u);
const XMVECTOR p3 = CubicInterpolate(patch[8], patch[9], patch[10], patch[11], u);
const XMVECTOR p4 = CubicInterpolate(patch[12], patch[13], patch[14], patch[15], u);
// Perform a vertical interpolation between the results of the
// previous horizontal interpolations, to compute the position.
XMVECTOR position = CubicInterpolate(p1, p2, p3, p4, v);
const XMVECTOR position = CubicInterpolate(p1, p2, p3, p4, v);
// Perform another four bezier interpolations between the control
// points, but this time vertically rather than horizontally.
XMVECTOR q1 = CubicInterpolate(patch[0], patch[4], patch[8], patch[12], v);
XMVECTOR q2 = CubicInterpolate(patch[1], patch[5], patch[9], patch[13], v);
XMVECTOR q3 = CubicInterpolate(patch[2], patch[6], patch[10], patch[14], v);
XMVECTOR q4 = CubicInterpolate(patch[3], patch[7], patch[11], patch[15], v);
const XMVECTOR q1 = CubicInterpolate(patch[0], patch[4], patch[8], patch[12], v);
const XMVECTOR q2 = CubicInterpolate(patch[1], patch[5], patch[9], patch[13], v);
const XMVECTOR q3 = CubicInterpolate(patch[2], patch[6], patch[10], patch[14], v);
const XMVECTOR q4 = CubicInterpolate(patch[3], patch[7], patch[11], patch[15], v);
// Compute vertical and horizontal tangent vectors.
XMVECTOR tangent1 = CubicTangent(p1, p2, p3, p4, v);
XMVECTOR tangent2 = CubicTangent(q1, q2, q3, q4, u);
const XMVECTOR tangent1 = CubicTangent(p1, p2, p3, p4, v);
const XMVECTOR tangent2 = CubicTangent(q1, q2, q3, q4, u);
// Cross the two tangent vectors to compute the normal.
XMVECTOR normal = XMVector3Cross(tangent1, tangent2);
@ -145,9 +145,9 @@ namespace Bezier
}
// Compute the texture coordinate.
float mirroredU = isMirrored ? 1 - u : u;
const float mirroredU = isMirrored ? 1 - u : u;
XMVECTOR textureCoordinate = XMVectorSet(mirroredU, v, 0, 0);
const XMVECTOR textureCoordinate = XMVectorSet(mirroredU, v, 0, 0);
// Output this vertex.
outputVertex(position, normal, textureCoordinate);

Просмотреть файл

@ -38,7 +38,7 @@ HRESULT DirectX::CreateStaticBuffer(
if (!device || !ptr || !count || !stride)
return E_INVALIDARG;
uint64_t sizeInbytes = uint64_t(count) * uint64_t(stride);
const uint64_t sizeInbytes = uint64_t(count) * uint64_t(stride);
static constexpr uint64_t c_maxBytes = D3D12_REQ_RESOURCE_SIZE_IN_MEGABYTES_EXPRESSION_A_TERM * 1024u * 1024u;
@ -48,9 +48,9 @@ HRESULT DirectX::CreateStaticBuffer(
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
auto desc = CD3DX12_RESOURCE_DESC::Buffer(sizeInbytes, resFlags);
auto const desc = CD3DX12_RESOURCE_DESC::Buffer(sizeInbytes, resFlags);
CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
ComPtr<ID3D12Resource> res;
HRESULT hr = device->CreateCommittedResource(
@ -114,9 +114,9 @@ HRESULT DirectX::CreateTextureFromMemory(
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
auto desc = CD3DX12_RESOURCE_DESC::Tex1D(format, static_cast<UINT64>(width), 1u, 1u, resFlags);
auto const desc = CD3DX12_RESOURCE_DESC::Tex1D(format, static_cast<UINT64>(width), 1u, 1u, resFlags);
CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
ComPtr<ID3D12Resource> res;
HRESULT hr = device->CreateCommittedResource(
@ -190,10 +190,10 @@ HRESULT DirectX::CreateTextureFromMemory(
}
}
auto desc = CD3DX12_RESOURCE_DESC::Tex2D(format, static_cast<UINT64>(width), static_cast<UINT>(height),
auto const desc = CD3DX12_RESOURCE_DESC::Tex2D(format, static_cast<UINT64>(width), static_cast<UINT>(height),
1u, mipCount, 1u, 0u, resFlags);
CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
ComPtr<ID3D12Resource> res;
HRESULT hr = device->CreateCommittedResource(
@ -262,11 +262,11 @@ HRESULT DirectX::CreateTextureFromMemory(
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
auto desc = CD3DX12_RESOURCE_DESC::Tex3D(format,
auto const desc = CD3DX12_RESOURCE_DESC::Tex3D(format,
static_cast<UINT64>(width), static_cast<UINT>(height), static_cast<UINT16>(depth),
1u, resFlags);
CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
ComPtr<ID3D12Resource> res;
HRESULT hr = device->CreateCommittedResource(

Просмотреть файл

@ -251,7 +251,7 @@ namespace
desc.SampleDesc.Quality = 0;
desc.Dimension = resDim;
CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
hr = d3dDevice->CreateCommittedResource(
&defaultHeapProperties,
@ -285,7 +285,7 @@ namespace
{
HRESULT hr = S_OK;
UINT width = header->width;
const UINT width = header->width;
UINT height = header->height;
UINT depth = header->depth;
@ -473,7 +473,7 @@ namespace
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
UINT numberOfPlanes = D3D12GetFormatPlaneCount(d3dDevice, format);
const UINT numberOfPlanes = D3D12GetFormatPlaneCount(d3dDevice, format);
if (!numberOfPlanes)
return E_INVALIDARG;
@ -845,7 +845,7 @@ HRESULT DirectX::CreateDDSTextureFromMemoryEx(
if (loadFlags & DDS_LOADER_MIP_AUTOGEN)
{
DXGI_FORMAT fmt = GetPixelFormat(header);
const DXGI_FORMAT fmt = GetPixelFormat(header);
if (!resourceUpload.IsSupportedForGenerateMips(fmt))
{
DebugTrace("WARNING: Autogen of mips ignored (device doesn't support this format (%d) or trying to use a copy queue)\n", static_cast<int>(fmt));
@ -963,7 +963,7 @@ HRESULT DirectX::CreateDDSTextureFromFileEx(
if (loadFlags & DDS_LOADER_MIP_AUTOGEN)
{
DXGI_FORMAT fmt = GetPixelFormat(header);
const DXGI_FORMAT fmt = GetPixelFormat(header);
if (!resourceUpload.IsSupportedForGenerateMips(fmt))
{
DebugTrace("WARNING: Autogen of mips ignored (device doesn't support this format (%d) or trying to use a copy queue)\n", static_cast<int>(fmt));

Просмотреть файл

@ -272,11 +272,11 @@ DebugEffect::Impl::Impl(
// Create root signature.
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
// Create root parameters and initialize first (constants)
CD3DX12_ROOT_PARAMETER rootParameters[RootParameterIndex::RootParameterCount] = {};
@ -293,14 +293,14 @@ DebugEffect::Impl::Impl(
assert(mRootSignature != nullptr);
// Create pipeline state.
int sp = GetPipelineStatePermutation(debugMode, effectFlags);
const int sp = GetPipelineStatePermutation(debugMode, effectFlags);
assert(sp >= 0 && sp < DebugEffectTraits::ShaderPermutationCount);
_Analysis_assume_(sp >= 0 && sp < DebugEffectTraits::ShaderPermutationCount);
int vi = EffectBase<DebugEffectTraits>::VertexShaderIndices[sp];
const int vi = EffectBase<DebugEffectTraits>::VertexShaderIndices[sp];
assert(vi >= 0 && vi < DebugEffectTraits::VertexShaderCount);
_Analysis_assume_(vi >= 0 && vi < DebugEffectTraits::VertexShaderCount);
int pi = EffectBase<DebugEffectTraits>::PixelShaderIndices[sp];
const int pi = EffectBase<DebugEffectTraits>::PixelShaderIndices[sp];
assert(pi >= 0 && pi < DebugEffectTraits::PixelShaderCount);
_Analysis_assume_(pi >= 0 && pi < DebugEffectTraits::PixelShaderCount);
@ -352,7 +352,7 @@ void DebugEffect::Impl::Apply(_In_ ID3D12GraphicsCommandList* commandList)
{
constants.world = XMMatrixTranspose(matrices.world);
XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
const XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
constants.worldInverseTranspose[0] = worldInverse.r[0];
constants.worldInverseTranspose[1] = worldInverse.r[1];

Просмотреть файл

@ -91,7 +91,7 @@ D3D12_GPU_DESCRIPTOR_HANDLE DescriptorHeap::WriteDescriptors(
{
assert((size_t(offsetIntoHeap) + size_t(totalDescriptorCount)) <= size_t(m_desc.NumDescriptors));
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = GetCpuHandle(offsetIntoHeap);
const D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = GetCpuHandle(offsetIntoHeap);
device->CopyDescriptors(
1,

Просмотреть файл

@ -180,14 +180,14 @@ DualPostProcess::Impl::Impl(_In_ ID3D12Device* device, const RenderTargetState&
// Create root signature.
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
// Same as CommonStates::StaticLinearClamp
CD3DX12_STATIC_SAMPLER_DESC sampler(
const CD3DX12_STATIC_SAMPLER_DESC sampler(
0, // register
D3D12_FILTER_MIN_MAG_MIP_LINEAR,
D3D12_TEXTURE_ADDRESS_MODE_CLAMP,
@ -203,10 +203,10 @@ DualPostProcess::Impl::Impl(_In_ ID3D12Device* device, const RenderTargetState&
CD3DX12_ROOT_PARAMETER rootParameters[RootParameterIndex::RootParameterCount] = {};
CD3DX12_DESCRIPTOR_RANGE texture1Range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE texture1Range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
rootParameters[RootParameterIndex::TextureSRV].InitAsDescriptorTable(1, &texture1Range, D3D12_SHADER_VISIBILITY_PIXEL);
CD3DX12_DESCRIPTOR_RANGE texture2Range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1);
const CD3DX12_DESCRIPTOR_RANGE texture2Range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1);
rootParameters[RootParameterIndex::TextureSRV2].InitAsDescriptorTable(1, &texture2Range, D3D12_SHADER_VISIBILITY_PIXEL);
// Root parameter descriptor
@ -223,7 +223,7 @@ DualPostProcess::Impl::Impl(_In_ ID3D12Device* device, const RenderTargetState&
assert(mRootSignature != nullptr);
// Create pipeline state.
EffectPipelineStateDescription psd(nullptr,
const EffectPipelineStateDescription psd(nullptr,
CommonStates::Opaque,
CommonStates::DepthNone,
CommonStates::CullNone,

Просмотреть файл

@ -170,24 +170,24 @@ DualTextureEffect::Impl::Impl(
// Create root signature.
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
CD3DX12_ROOT_PARAMETER rootParameters[RootParameterIndex::RootParameterCount] = {};
rootParameters[RootParameterIndex::ConstantBuffer].InitAsConstantBufferView(0, 0, D3D12_SHADER_VISIBILITY_ALL);
// Texture 1
CD3DX12_DESCRIPTOR_RANGE texture1Range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
CD3DX12_DESCRIPTOR_RANGE texture1SamplerRange(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE texture1Range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE texture1SamplerRange(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
rootParameters[RootParameterIndex::Texture1SRV].InitAsDescriptorTable(1, &texture1Range, D3D12_SHADER_VISIBILITY_PIXEL);
rootParameters[RootParameterIndex::Texture1Sampler].InitAsDescriptorTable(1, &texture1SamplerRange, D3D12_SHADER_VISIBILITY_PIXEL);
// Texture 2
CD3DX12_DESCRIPTOR_RANGE texture2Range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1);
CD3DX12_DESCRIPTOR_RANGE texture2SamplerRange(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 1);
const CD3DX12_DESCRIPTOR_RANGE texture2Range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1);
const CD3DX12_DESCRIPTOR_RANGE texture2SamplerRange(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 1);
rootParameters[RootParameterIndex::Texture2SRV].InitAsDescriptorTable(1, &texture2Range, D3D12_SHADER_VISIBILITY_PIXEL);
rootParameters[RootParameterIndex::Texture2Sampler].InitAsDescriptorTable(1, &texture2SamplerRange, D3D12_SHADER_VISIBILITY_PIXEL);
@ -220,14 +220,14 @@ DualTextureEffect::Impl::Impl(
}
// Create pipeline state.
int sp = GetPipelineStatePermutation(effectFlags);
const int sp = GetPipelineStatePermutation(effectFlags);
assert(sp >= 0 && sp < DualTextureEffectTraits::ShaderPermutationCount);
_Analysis_assume_(sp >= 0 && sp < DualTextureEffectTraits::ShaderPermutationCount);
int vi = EffectBase<DualTextureEffectTraits>::VertexShaderIndices[sp];
const int vi = EffectBase<DualTextureEffectTraits>::VertexShaderIndices[sp];
assert(vi >= 0 && vi < DualTextureEffectTraits::VertexShaderCount);
_Analysis_assume_(vi >= 0 && vi < DualTextureEffectTraits::VertexShaderCount);
int pi = EffectBase<DualTextureEffectTraits>::PixelShaderIndices[sp];
const int pi = EffectBase<DualTextureEffectTraits>::PixelShaderIndices[sp];
assert(pi >= 0 && pi < DualTextureEffectTraits::PixelShaderCount);
_Analysis_assume_(pi >= 0 && pi < DualTextureEffectTraits::PixelShaderCount);

Просмотреть файл

@ -28,7 +28,7 @@ void XM_CALLCONV IEffectMatrices::SetMatrices(FXMMATRIX world, CXMMATRIX view, C
// Constructor initializes default matrix values.
EffectMatrices::EffectMatrices() noexcept
{
XMMATRIX id = XMMatrixIdentity();
const XMMATRIX id = XMMatrixIdentity();
world = id;
view = id;
projection = id;
@ -83,11 +83,12 @@ void XM_CALLCONV EffectFog::SetConstants(int& dirtyFlags, FXMMATRIX worldView, X
// with a single dot product, using only the Z row of the world+view matrix.
// _13, _23, _33, _43
XMVECTOR worldViewZ = XMVectorMergeXY(XMVectorMergeZW(worldView.r[0], worldView.r[2]),
XMVectorMergeZW(worldView.r[1], worldView.r[3]));
const XMVECTOR worldViewZ = XMVectorMergeXY(
XMVectorMergeZW(worldView.r[0], worldView.r[2]),
XMVectorMergeZW(worldView.r[1], worldView.r[3]));
// 0, 0, 0, fogStart
XMVECTOR wOffset = XMVectorSwizzle<1, 2, 3, 0>(XMLoadFloat(&start));
const XMVECTOR wOffset = XMVectorSwizzle<1, 2, 3, 0>(XMLoadFloat(&start));
// (worldViewZ + wOffset) / (start - end);
fogVectorConstant = XMVectorDivide(XMVectorAdd(worldViewZ, wOffset), XMVectorReplicate(start - end));
@ -124,7 +125,7 @@ void EffectColor::SetConstants(_Inout_ int& dirtyFlags, _Inout_ XMVECTOR& diffus
{
if (dirtyFlags & EffectDirtyFlags::MaterialColor)
{
XMVECTOR alphaVector = XMVectorReplicate(alpha);
const XMVECTOR alphaVector = XMVectorReplicate(alpha);
// xyz = diffuse * alpha, w = alpha.
diffuseColorConstant = XMVectorSelect(alphaVector, XMVectorMultiply(diffuseColor, alphaVector), g_XMSelect1110);
@ -189,7 +190,7 @@ void EffectLights::SetConstants(int& dirtyFlags, EffectMatrices const& matrices,
{
worldConstant = XMMatrixTranspose(matrices.world);
XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
const XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
worldInverseTransposeConstant[0] = worldInverse.r[0];
worldInverseTransposeConstant[1] = worldInverse.r[1];
@ -235,7 +236,7 @@ void EffectLights::SetConstants(int& dirtyFlags, EffectMatrices const& matrices,
if (dirtyFlags & EffectDirtyFlags::MaterialColor)
{
XMVECTOR diffuse = diffuseColor;
XMVECTOR alphaVector = XMVectorReplicate(alpha);
const XMVECTOR alphaVector = XMVectorReplicate(alpha);
if (lightingEnabled)
{

Просмотреть файл

@ -144,12 +144,12 @@ std::shared_ptr<IEffect> EffectFactory::Impl::CreateEffect(
throw std::runtime_error("EffectFactory");
}
int diffuseTextureIndex = (info.diffuseTextureIndex != -1 && mTextureDescriptors != nullptr) ? info.diffuseTextureIndex + textureDescriptorOffset : -1;
int specularTextureIndex = (info.specularTextureIndex != -1 && mTextureDescriptors != nullptr) ? info.specularTextureIndex + textureDescriptorOffset : -1;
int emissiveTextureIndex = (info.emissiveTextureIndex != -1 && mTextureDescriptors != nullptr) ? info.emissiveTextureIndex + textureDescriptorOffset : -1;
int normalTextureIndex = (info.normalTextureIndex != -1 && mTextureDescriptors != nullptr) ? info.normalTextureIndex + textureDescriptorOffset : -1;
int samplerIndex = (info.samplerIndex != -1 && mSamplerDescriptors != nullptr) ? info.samplerIndex + samplerDescriptorOffset : -1;
int samplerIndex2 = (info.samplerIndex2 != -1 && mSamplerDescriptors != nullptr) ? info.samplerIndex2 + samplerDescriptorOffset : -1;
const int diffuseTextureIndex = (info.diffuseTextureIndex != -1 && mTextureDescriptors != nullptr) ? info.diffuseTextureIndex + textureDescriptorOffset : -1;
const int specularTextureIndex = (info.specularTextureIndex != -1 && mTextureDescriptors != nullptr) ? info.specularTextureIndex + textureDescriptorOffset : -1;
const int emissiveTextureIndex = (info.emissiveTextureIndex != -1 && mTextureDescriptors != nullptr) ? info.emissiveTextureIndex + textureDescriptorOffset : -1;
const int normalTextureIndex = (info.normalTextureIndex != -1 && mTextureDescriptors != nullptr) ? info.normalTextureIndex + textureDescriptorOffset : -1;
const int samplerIndex = (info.samplerIndex != -1 && mSamplerDescriptors != nullptr) ? info.samplerIndex + samplerDescriptorOffset : -1;
const int samplerIndex2 = (info.samplerIndex2 != -1 && mSamplerDescriptors != nullptr) ? info.samplerIndex2 + samplerDescriptorOffset : -1;
// Modify base pipeline state
EffectPipelineStateDescription derivedPSD = (info.alphaValue < 1.0f) ? alphaPipelineState : opaquePipelineState;
@ -180,7 +180,7 @@ std::shared_ptr<IEffect> EffectFactory::Impl::CreateEffect(
if (mSharing && !info.name.empty())
{
uint32_t hash = derivedPSD.ComputeHash();
const uint32_t hash = derivedPSD.ComputeHash();
cacheName = std::to_wstring(effectflags) + info.name + std::to_wstring(hash);
auto it = mEffectCacheNormalMapSkinned.find(cacheName);
@ -225,7 +225,7 @@ std::shared_ptr<IEffect> EffectFactory::Impl::CreateEffect(
// SkinnedEffect
if (mSharing && !info.name.empty())
{
uint32_t hash = derivedPSD.ComputeHash();
const uint32_t hash = derivedPSD.ComputeHash();
cacheName = std::to_wstring(effectflags) + info.name + std::to_wstring(hash);
auto it = mEffectCacheSkinning.find(cacheName);
@ -268,7 +268,7 @@ std::shared_ptr<IEffect> EffectFactory::Impl::CreateEffect(
if (mSharing && !info.name.empty())
{
uint32_t hash = derivedPSD.ComputeHash();
const uint32_t hash = derivedPSD.ComputeHash();
cacheName = std::to_wstring(effectflags) + info.name + std::to_wstring(hash);
auto it = mEffectCacheDualTexture.find(cacheName);
@ -288,7 +288,7 @@ std::shared_ptr<IEffect> EffectFactory::Impl::CreateEffect(
// Dual texture effect doesn't support lighting (usually it's lightmaps)
effect->SetAlpha(info.alphaValue);
XMVECTOR color = XMLoadFloat3(&info.diffuseColor);
const XMVECTOR color = XMLoadFloat3(&info.diffuseColor);
effect->SetDiffuseColor(color);
if (diffuseTextureIndex != -1)
@ -365,7 +365,7 @@ std::shared_ptr<IEffect> EffectFactory::Impl::CreateEffect(
if (mSharing && !info.name.empty())
{
uint32_t hash = derivedPSD.ComputeHash();
const uint32_t hash = derivedPSD.ComputeHash();
cacheName = std::to_wstring(effectflags) + info.name + std::to_wstring(hash);
auto it = mEffectCacheNormalMap.find(cacheName);
@ -433,7 +433,7 @@ std::shared_ptr<IEffect> EffectFactory::Impl::CreateEffect(
// BasicEffect
if (mSharing && !info.name.empty())
{
uint32_t hash = derivedPSD.ComputeHash();
const uint32_t hash = derivedPSD.ComputeHash();
cacheName = std::to_wstring(effectflags) + info.name + std::to_wstring(hash);
auto it = mEffectCache.find(cacheName);
@ -510,11 +510,8 @@ EffectFactory::EffectFactory(_In_ ID3D12DescriptorHeap* textureDescriptors, _In_
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
textureDescriptors->GetDevice(IID_GRAPHICS_PPV_ARGS(device.GetAddressOf()));
#else
HRESULT hresult = textureDescriptors->GetDevice(IID_PPV_ARGS(device.GetAddressOf()));
if (FAILED(hresult))
{
throw com_exception(hresult);
}
HRESULT hr = textureDescriptors->GetDevice(IID_PPV_ARGS(device.GetAddressOf()));
ThrowIfFailed(hr);
#endif
pImpl = std::make_shared<Impl>(device.Get(), textureDescriptors, samplerDescriptors);

Просмотреть файл

@ -129,7 +129,7 @@ size_t EffectTextureFactory::Impl::CreateTexture(_In_z_ const wchar_t* name, int
wchar_t ext[_MAX_EXT] = {};
_wsplitpath_s(name, nullptr, 0, nullptr, 0, nullptr, 0, ext, _MAX_EXT);
bool isdds = _wcsicmp(ext, L".dds") == 0;
const bool isdds = _wcsicmp(ext, L".dds") == 0;
DDS_LOADER_FLAGS loadFlags = DDS_LOADER_DEFAULT;
if (mForceSRGB)
@ -194,7 +194,7 @@ size_t EffectTextureFactory::Impl::CreateTexture(_In_z_ const wchar_t* name, int
assert(textureEntry.mResource != nullptr);
// bind a new descriptor in slot
auto textureDescriptor = mTextureDescriptorHeap.GetCpuHandle(static_cast<size_t>(descriptorSlot));
auto const textureDescriptor = mTextureDescriptorHeap.GetCpuHandle(static_cast<size_t>(descriptorSlot));
DirectX::CreateShaderResourceView(mDevice.Get(), textureEntry.mResource.Get(), textureDescriptor, textureEntry.mIsCubeMap);
return textureEntry.slot;

Просмотреть файл

@ -368,24 +368,24 @@ EnvironmentMapEffect::Impl::Impl(
// Create root signature.
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
CD3DX12_ROOT_PARAMETER rootParameters[RootParameterIndex::RootParameterCount] = {};
rootParameters[RootParameterIndex::ConstantBuffer].InitAsConstantBufferView(0, 0, D3D12_SHADER_VISIBILITY_ALL);
// Texture 1
CD3DX12_DESCRIPTOR_RANGE textureDescriptor(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
CD3DX12_DESCRIPTOR_RANGE textureSamplerDescriptor(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureDescriptor(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSamplerDescriptor(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
rootParameters[RootParameterIndex::TextureSRV].InitAsDescriptorTable(1, &textureDescriptor, D3D12_SHADER_VISIBILITY_PIXEL);
rootParameters[RootParameterIndex::TextureSampler].InitAsDescriptorTable(1, &textureSamplerDescriptor, D3D12_SHADER_VISIBILITY_PIXEL);
// Texture 2
CD3DX12_DESCRIPTOR_RANGE cubemapDescriptor(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1);
CD3DX12_DESCRIPTOR_RANGE cubemapSamplerDescriptor(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 1);
const CD3DX12_DESCRIPTOR_RANGE cubemapDescriptor(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1);
const CD3DX12_DESCRIPTOR_RANGE cubemapSamplerDescriptor(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 1);
rootParameters[RootParameterIndex::CubemapSRV].InitAsDescriptorTable(1, &cubemapDescriptor, D3D12_SHADER_VISIBILITY_PIXEL);
rootParameters[RootParameterIndex::CubemapSampler].InitAsDescriptorTable(1, &cubemapSamplerDescriptor, D3D12_SHADER_VISIBILITY_PIXEL);
@ -419,14 +419,14 @@ EnvironmentMapEffect::Impl::Impl(
lights.InitializeConstants(unwantedOutput[0], constants.lightDirection, constants.lightDiffuseColor, unwantedOutput);
// Create pipeline state.
int sp = GetPipelineStatePermutation(mapping, effectFlags);
const int sp = GetPipelineStatePermutation(mapping, effectFlags);
assert(sp >= 0 && sp < EnvironmentMapEffectTraits::ShaderPermutationCount);
_Analysis_assume_(sp >= 0 && sp < EnvironmentMapEffectTraits::ShaderPermutationCount);
int vi = EffectBase<EnvironmentMapEffectTraits>::VertexShaderIndices[sp];
const int vi = EffectBase<EnvironmentMapEffectTraits>::VertexShaderIndices[sp];
assert(vi >= 0 && vi < EnvironmentMapEffectTraits::VertexShaderCount);
_Analysis_assume_(vi >= 0 && vi < EnvironmentMapEffectTraits::VertexShaderCount);
int pi = EffectBase<EnvironmentMapEffectTraits>::PixelShaderIndices[sp];
const int pi = EffectBase<EnvironmentMapEffectTraits>::PixelShaderIndices[sp];
assert(pi >= 0 && pi < EnvironmentMapEffectTraits::PixelShaderCount);
_Analysis_assume_(pi >= 0 && pi < EnvironmentMapEffectTraits::PixelShaderCount);
@ -445,7 +445,7 @@ int EnvironmentMapEffect::Impl::GetPipelineStatePermutation(
EnvironmentMapEffect::Mapping mapping,
uint32_t effectFlags) const noexcept
{
bool biasedVertexNormals = (effectFlags & EffectFlags::BiasedVertexNormals) != 0;
const bool biasedVertexNormals = (effectFlags & EffectFlags::BiasedVertexNormals) != 0;
int permutation = 0;

Просмотреть файл

@ -40,7 +40,7 @@ namespace
}
// Scale into 0-1 range.
float scaledValue = value / (maxValue - deadZoneSize);
const float scaledValue = value / (maxValue - deadZoneSize);
return std::max(-1.f, std::min(scaledValue, 1.f));
}
@ -62,10 +62,10 @@ namespace
case GamePad::DEAD_ZONE_CIRCULAR:
{
float dist = sqrtf(x*x + y * y);
float wanted = ApplyLinearDeadZone(dist, maxValue, deadZoneSize);
const float dist = sqrtf(x*x + y * y);
const float wanted = ApplyLinearDeadZone(dist, maxValue, deadZoneSize);
float scale = (wanted > 0.f) ? (wanted / dist) : 0.f;
const float scale = (wanted > 0.f) ? (wanted / dist) : 0.f;
resultX = std::max(-1.f, std::min(x * scale, 1.f));
resultY = std::max(-1.f, std::min(y * scale, 1.f));
@ -1273,7 +1273,7 @@ public:
if (player == c_MostRecent)
player = GetMostRecent();
ULONGLONG time = GetTickCount64();
const ULONGLONG time = GetTickCount64();
if (!ThrottleRetry(player, time))
{
@ -1287,7 +1287,7 @@ public:
#endif
XINPUT_STATE xstate;
DWORD result = XInputGetState(DWORD(player), &xstate);
const DWORD result = XInputGetState(DWORD(player), &xstate);
if (result == ERROR_DEVICE_NOT_CONNECTED)
{
ClearSlot(player, time);
@ -1302,7 +1302,7 @@ public:
state.connected = true;
state.packet = xstate.dwPacketNumber;
WORD xbuttons = xstate.Gamepad.wButtons;
const WORD xbuttons = xstate.Gamepad.wButtons;
state.buttons.a = (xbuttons & XINPUT_GAMEPAD_A) != 0;
state.buttons.b = (xbuttons & XINPUT_GAMEPAD_B) != 0;
state.buttons.x = (xbuttons & XINPUT_GAMEPAD_X) != 0;
@ -1350,12 +1350,12 @@ public:
if (player == c_MostRecent)
player = GetMostRecent();
ULONGLONG time = GetTickCount64();
const ULONGLONG time = GetTickCount64();
if (!ThrottleRetry(player, time))
{
XINPUT_CAPABILITIES xcaps;
DWORD result = XInputGetCapabilities(DWORD(player), 0, &xcaps);
const DWORD result = XInputGetCapabilities(DWORD(player), 0, &xcaps);
if (result == ERROR_DEVICE_NOT_CONNECTED)
{
ClearSlot(player, time);
@ -1407,7 +1407,7 @@ public:
if (player == c_MostRecent)
player = GetMostRecent();
ULONGLONG time = GetTickCount64();
const ULONGLONG time = GetTickCount64();
if (ThrottleRetry(player, time))
{
@ -1430,7 +1430,7 @@ public:
XINPUT_VIBRATION xvibration;
xvibration.wLeftMotorSpeed = WORD(leftMotor * 0xFFFF);
xvibration.wRightMotorSpeed = WORD(rightMotor * 0xFFFF);
DWORD result = XInputSetState(DWORD(player), &xvibration);
const DWORD result = XInputSetState(DWORD(player), &xvibration);
if (result == ERROR_DEVICE_NOT_CONNECTED)
{
ClearSlot(player, time);
@ -1481,7 +1481,7 @@ public:
// For XInput 9.1.0, we have to emulate the behavior of XInputEnable( TRUE )
if (mSuspended)
{
ULONGLONG time = GetTickCount64();
const ULONGLONG time = GetTickCount64();
for (int j = 0; j < XUSER_MAX_COUNT; ++j)
{
@ -1490,7 +1490,7 @@ public:
XINPUT_VIBRATION xvibration;
xvibration.wLeftMotorSpeed = WORD(mLeftMotor[j] * 0xFFFF);
xvibration.wRightMotorSpeed = WORD(mRightMotor[j] * 0xFFFF);
DWORD result = XInputSetState(DWORD(j), &xvibration);
const DWORD result = XInputSetState(DWORD(j), &xvibration);
if (result == ERROR_DEVICE_NOT_CONNECTED)
{
ClearSlot(j, time);
@ -1534,7 +1534,7 @@ private:
{
if (!mConnected[j])
{
LONGLONG delta = LONGLONG(time) - LONGLONG(mLastReadTime[j]);
const LONGLONG delta = LONGLONG(time) - LONGLONG(mLastReadTime[j]);
LONGLONG interval = 1000;
if (j != player)

Просмотреть файл

@ -69,7 +69,7 @@ void GeometricPrimitive::Impl::Initialize(
if (sizeInBytes > uint64_t(D3D12_REQ_RESOURCE_SIZE_IN_MEGABYTES_EXPRESSION_A_TERM * 1024u * 1024u))
throw std::invalid_argument("VB too large for DirectX 12");
auto vertSizeBytes = static_cast<size_t>(sizeInBytes);
auto const vertSizeBytes = static_cast<size_t>(sizeInBytes);
mVertexBuffer = GraphicsMemory::Get(device).Allocate(vertSizeBytes);
@ -81,7 +81,7 @@ void GeometricPrimitive::Impl::Initialize(
if (sizeInBytes > uint64_t(D3D12_REQ_RESOURCE_SIZE_IN_MEGABYTES_EXPRESSION_A_TERM * 1024u * 1024u))
throw std::invalid_argument("IB too large for DirectX 12");
auto indSizeBytes = static_cast<size_t>(sizeInBytes);
auto const indSizeBytes = static_cast<size_t>(sizeInBytes);
mIndexBuffer = GraphicsMemory::Get(device).Allocate(indSizeBytes);
@ -108,14 +108,14 @@ void GeometricPrimitive::Impl::LoadStaticBuffers(
ID3D12Device* device,
ResourceUploadBatch& resourceUploadBatch)
{
CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
// Convert dynamic VB to static VB
if (!mStaticVertexBuffer)
{
assert(mVertexBuffer);
auto desc = CD3DX12_RESOURCE_DESC::Buffer(mVertexBuffer.Size());
auto const desc = CD3DX12_RESOURCE_DESC::Buffer(mVertexBuffer.Size());
ThrowIfFailed(device->CreateCommittedResource(
&heapProperties,
@ -144,7 +144,7 @@ void GeometricPrimitive::Impl::LoadStaticBuffers(
{
assert(mIndexBuffer);
auto desc = CD3DX12_RESOURCE_DESC::Buffer(mIndexBuffer.Size());
auto const desc = CD3DX12_RESOURCE_DESC::Buffer(mIndexBuffer.Size());
ThrowIfFailed(device->CreateCommittedResource(
&heapProperties,
@ -685,7 +685,7 @@ std::unique_ptr<GeometricPrimitive> GeometricPrimitive::CreateCustom(
if (indices.size() % 3)
throw std::invalid_argument("Expected triangular faces");
size_t nVerts = vertices.size();
const size_t nVerts = vertices.size();
if (nVerts >= USHRT_MAX)
throw std::invalid_argument("Too many vertices for 16-bit index buffer");

Просмотреть файл

@ -100,16 +100,16 @@ void DirectX::ComputeBox(VertexCollection& vertices, IndexCollection& indices, c
// Create each face in turn.
for (int i = 0; i < FaceCount; i++)
{
XMVECTOR normal = faceNormals[i];
const XMVECTOR normal = faceNormals[i];
// Get two vectors perpendicular both to the face normal and to each other.
XMVECTOR basis = (i >= 4) ? g_XMIdentityR2 : g_XMIdentityR1;
const XMVECTOR basis = (i >= 4) ? g_XMIdentityR2 : g_XMIdentityR1;
XMVECTOR side1 = XMVector3Cross(normal, basis);
XMVECTOR side2 = XMVector3Cross(normal, side1);
const XMVECTOR side1 = XMVector3Cross(normal, basis);
const XMVECTOR side2 = XMVector3Cross(normal, side1);
// Six indices (two triangles) per face.
size_t vbase = vertices.size();
const size_t vbase = vertices.size();
index_push_back(indices, vbase + 0);
index_push_back(indices, vbase + 1);
index_push_back(indices, vbase + 2);
@ -152,17 +152,17 @@ void DirectX::ComputeSphere(VertexCollection& vertices, IndexCollection& indices
if (tessellation < 3)
throw std::invalid_argument("tesselation parameter must be at least 3");
size_t verticalSegments = tessellation;
size_t horizontalSegments = tessellation * 2;
const size_t verticalSegments = tessellation;
const size_t horizontalSegments = tessellation * 2;
float radius = diameter / 2;
const float radius = diameter / 2;
// Create rings of vertices at progressively higher latitudes.
for (size_t i = 0; i <= verticalSegments; i++)
{
float v = 1 - float(i) / float(verticalSegments);
const float v = 1 - float(i) / float(verticalSegments);
float latitude = (float(i) * XM_PI / float(verticalSegments)) - XM_PIDIV2;
const float latitude = (float(i) * XM_PI / float(verticalSegments)) - XM_PIDIV2;
float dy, dxz;
XMScalarSinCos(&dy, &dxz, latitude);
@ -170,9 +170,9 @@ void DirectX::ComputeSphere(VertexCollection& vertices, IndexCollection& indices
// Create a single ring of vertices at this latitude.
for (size_t j = 0; j <= horizontalSegments; j++)
{
float u = float(j) / float(horizontalSegments);
const float u = float(j) / float(horizontalSegments);
float longitude = float(j) * XM_2PI / float(horizontalSegments);
const float longitude = float(j) * XM_2PI / float(horizontalSegments);
float dx, dz;
XMScalarSinCos(&dx, &dz, longitude);
@ -180,22 +180,22 @@ void DirectX::ComputeSphere(VertexCollection& vertices, IndexCollection& indices
dx *= dxz;
dz *= dxz;
XMVECTOR normal = XMVectorSet(dx, dy, dz, 0);
XMVECTOR textureCoordinate = XMVectorSet(u, v, 0, 0);
const XMVECTOR normal = XMVectorSet(dx, dy, dz, 0);
const XMVECTOR textureCoordinate = XMVectorSet(u, v, 0, 0);
vertices.push_back(VertexPositionNormalTexture(XMVectorScale(normal, radius), normal, textureCoordinate));
}
}
// Fill the index buffer with triangles joining each pair of latitude rings.
size_t stride = horizontalSegments + 1;
const size_t stride = horizontalSegments + 1;
for (size_t i = 0; i < verticalSegments; i++)
{
for (size_t j = 0; j <= horizontalSegments; j++)
{
size_t nextI = i + 1;
size_t nextJ = (j + 1) % stride;
const size_t nextI = i + 1;
const size_t nextJ = (j + 1) % stride;
index_push_back(indices, i * stride + j);
index_push_back(indices, nextI * stride + j);
@ -274,8 +274,8 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
// We know these values by looking at the above index list for the octahedron. Despite the subdivisions that are
// about to go on, these values aren't ever going to change because the vertices don't move around in the array.
// We'll need these values later on to fix the singularities that show up at the poles.
const uint16_t northPoleIndex = 0;
const uint16_t southPoleIndex = 5;
constexpr uint16_t northPoleIndex = 0;
constexpr uint16_t southPoleIndex = 5;
for (size_t iSubdivision = 0; iSubdivision < tessellation; ++iSubdivision)
{
@ -294,9 +294,9 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
// The winding order of the triangles we output are the same as the winding order of the inputs.
// Indices of the vertices making up this triangle
uint16_t iv0 = indices[iTriangle * 3 + 0];
uint16_t iv1 = indices[iTriangle * 3 + 1];
uint16_t iv2 = indices[iTriangle * 3 + 2];
const uint16_t iv0 = indices[iTriangle * 3 + 0];
const uint16_t iv1 = indices[iTriangle * 3 + 1];
const uint16_t iv2 = indices[iTriangle * 3 + 2];
// Get the new vertices
XMFLOAT3 v01; // vertex on the midpoint of v0 and v1
@ -307,7 +307,7 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
uint16_t iv20; // index of v20
// Function that, when given the index of two vertices, creates a new vertex at the midpoint of those vertices.
auto divideEdge = [&](uint16_t i0, uint16_t i1, XMFLOAT3& outVertex, uint16_t& outIndex)
auto const divideEdge = [&](uint16_t i0, uint16_t i1, XMFLOAT3& outVertex, uint16_t& outIndex)
{
const UndirectedEdge edge = makeUndirectedEdge(i0, i1);
@ -372,20 +372,20 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
vertices.reserve(vertexPositions.size());
for (const auto& it : vertexPositions)
{
auto normal = XMVector3Normalize(XMLoadFloat3(&it));
auto pos = XMVectorScale(normal, radius);
auto const normal = XMVector3Normalize(XMLoadFloat3(&it));
auto const pos = XMVectorScale(normal, radius);
XMFLOAT3 normalFloat3;
XMStoreFloat3(&normalFloat3, normal);
// calculate texture coordinates for this vertex
float longitude = atan2f(normalFloat3.x, -normalFloat3.z);
float latitude = acosf(normalFloat3.y);
const float longitude = atan2f(normalFloat3.x, -normalFloat3.z);
const float latitude = acosf(normalFloat3.y);
float u = longitude / XM_2PI + 0.5f;
float v = latitude / XM_PI;
const float u = longitude / XM_2PI + 0.5f;
const float v = latitude / XM_PI;
auto texcoord = XMVectorSet(1.0f - u, v, 0.0f, 0.0f);
auto const texcoord = XMVectorSet(1.0f - u, v, 0.0f, 0.0f);
vertices.push_back(VertexPositionNormalTexture(pos, normal, texcoord));
}
@ -399,11 +399,11 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
// completed sphere. If you imagine the vertices along that edge, they circumscribe a semicircular arc starting at
// y=1 and ending at y=-1, and sweeping across the range of z=0 to z=1. x stays zero. It's along this edge that we
// need to duplicate our vertices - and provide the correct texture coordinates.
size_t preFixupVertexCount = vertices.size();
const size_t preFixupVertexCount = vertices.size();
for (size_t i = 0; i < preFixupVertexCount; ++i)
{
// This vertex is on the prime meridian if position.x and texcoord.u are both zero (allowing for small epsilon).
bool isOnPrimeMeridian = XMVector2NearEqual(
const bool isOnPrimeMeridian = XMVector2NearEqual(
XMVectorSet(vertices[i].position.x, vertices[i].textureCoordinate.x, 0.0f, 0.0f),
XMVectorZero(),
XMVectorSplatEpsilon());
@ -468,7 +468,7 @@ void DirectX::ComputeGeoSphere(VertexCollection& vertices, IndexCollection& indi
// onto a single point. In general there's no real way to do that right. But to match the behavior of non-geodesic
// spheres, we need to duplicate the pole vertex for every triangle that uses it. This will introduce seams near the
// poles, but reduce stretching.
auto fixPole = [&](size_t poleIndex)
auto const fixPole = [&](size_t poleIndex)
{
const auto& poleVertex = vertices[poleIndex];
bool overwrittenPoleVertex = false; // overwriting the original pole vertex saves us one vertex
@ -544,23 +544,23 @@ namespace
// Helper computes a point on a unit circle, aligned to the x/z plane and centered on the origin.
inline XMVECTOR GetCircleVector(size_t i, size_t tessellation) noexcept
{
float angle = float(i) * XM_2PI / float(tessellation);
const float angle = float(i) * XM_2PI / float(tessellation);
float dx, dz;
XMScalarSinCos(&dx, &dz, angle);
XMVECTORF32 v = { { { dx, 0, dz, 0 } } };
const XMVECTORF32 v = { { { dx, 0, dz, 0 } } };
return v;
}
inline XMVECTOR GetCircleTangent(size_t i, size_t tessellation) noexcept
{
float angle = (float(i) * XM_2PI / float(tessellation)) + XM_PIDIV2;
const float angle = (float(i) * XM_2PI / float(tessellation)) + XM_PIDIV2;
float dx, dz;
XMScalarSinCos(&dx, &dz, angle);
XMVECTORF32 v = { { { dx, 0, dz, 0 } } };
const XMVECTORF32 v = { { { dx, 0, dz, 0 } } };
return v;
}
@ -579,7 +579,7 @@ namespace
std::swap(i1, i2);
}
size_t vbase = vertices.size();
const size_t vbase = vertices.size();
index_push_back(indices, vbase);
index_push_back(indices, vbase + i1);
index_push_back(indices, vbase + i2);
@ -598,11 +598,11 @@ namespace
// Create cap vertices.
for (size_t i = 0; i < tessellation; i++)
{
XMVECTOR circleVector = GetCircleVector(i, tessellation);
const XMVECTOR circleVector = GetCircleVector(i, tessellation);
XMVECTOR position = XMVectorAdd(XMVectorScale(circleVector, radius), XMVectorScale(normal, height));
const XMVECTOR position = XMVectorAdd(XMVectorScale(circleVector, radius), XMVectorScale(normal, height));
XMVECTOR textureCoordinate = XMVectorMultiplyAdd(XMVectorSwizzle<0, 2, 3, 3>(circleVector), textureScale, g_XMOneHalf);
const XMVECTOR textureCoordinate = XMVectorMultiplyAdd(XMVectorSwizzle<0, 2, 3, 3>(circleVector), textureScale, g_XMOneHalf);
vertices.push_back(VertexPositionNormalTexture(position, normal, textureCoordinate));
}
@ -619,21 +619,21 @@ void DirectX::ComputeCylinder(VertexCollection& vertices, IndexCollection& indic
height /= 2;
XMVECTOR topOffset = XMVectorScale(g_XMIdentityR1, height);
const XMVECTOR topOffset = XMVectorScale(g_XMIdentityR1, height);
float radius = diameter / 2;
size_t stride = tessellation + 1;
const float radius = diameter / 2;
const size_t stride = tessellation + 1;
// Create a ring of triangles around the outside of the cylinder.
for (size_t i = 0; i <= tessellation; i++)
{
XMVECTOR normal = GetCircleVector(i, tessellation);
const XMVECTOR normal = GetCircleVector(i, tessellation);
XMVECTOR sideOffset = XMVectorScale(normal, radius);
const XMVECTOR sideOffset = XMVectorScale(normal, radius);
float u = float(i) / float(tessellation);
const float u = float(i) / float(tessellation);
XMVECTOR textureCoordinate = XMLoadFloat(&u);
const XMVECTOR textureCoordinate = XMLoadFloat(&u);
vertices.push_back(VertexPositionNormalTexture(XMVectorAdd(sideOffset, topOffset), normal, textureCoordinate));
vertices.push_back(VertexPositionNormalTexture(XMVectorSubtract(sideOffset, topOffset), normal, XMVectorAdd(textureCoordinate, g_XMIdentityR1)));
@ -668,23 +668,23 @@ void DirectX::ComputeCone(VertexCollection& vertices, IndexCollection& indices,
height /= 2;
XMVECTOR topOffset = XMVectorScale(g_XMIdentityR1, height);
const XMVECTOR topOffset = XMVectorScale(g_XMIdentityR1, height);
float radius = diameter / 2;
size_t stride = tessellation + 1;
const float radius = diameter / 2;
const size_t stride = tessellation + 1;
// Create a ring of triangles around the outside of the cone.
for (size_t i = 0; i <= tessellation; i++)
{
XMVECTOR circlevec = GetCircleVector(i, tessellation);
const XMVECTOR circlevec = GetCircleVector(i, tessellation);
XMVECTOR sideOffset = XMVectorScale(circlevec, radius);
const XMVECTOR sideOffset = XMVectorScale(circlevec, radius);
float u = float(i) / float(tessellation);
const float u = float(i) / float(tessellation);
XMVECTOR textureCoordinate = XMLoadFloat(&u);
const XMVECTOR textureCoordinate = XMLoadFloat(&u);
XMVECTOR pt = XMVectorSubtract(sideOffset, topOffset);
const XMVECTOR pt = XMVectorSubtract(sideOffset, topOffset);
XMVECTOR normal = XMVector3Cross(
GetCircleTangent(i, tessellation),
@ -720,25 +720,25 @@ void DirectX::ComputeTorus(VertexCollection& vertices, IndexCollection& indices,
if (tessellation < 3)
throw std::invalid_argument("tesselation parameter must be at least 3");
size_t stride = tessellation + 1;
const size_t stride = tessellation + 1;
// First we loop around the main ring of the torus.
for (size_t i = 0; i <= tessellation; i++)
{
float u = float(i) / float(tessellation);
const float u = float(i) / float(tessellation);
float outerAngle = float(i) * XM_2PI / float(tessellation) - XM_PIDIV2;
const float outerAngle = float(i) * XM_2PI / float(tessellation) - XM_PIDIV2;
// Create a transform matrix that will align geometry to
// slice perpendicularly though the current ring position.
XMMATRIX transform = XMMatrixTranslation(diameter / 2, 0, 0) * XMMatrixRotationY(outerAngle);
const XMMATRIX transform = XMMatrixTranslation(diameter / 2, 0, 0) * XMMatrixRotationY(outerAngle);
// Now we loop along the other axis, around the side of the tube.
for (size_t j = 0; j <= tessellation; j++)
{
float v = 1 - float(j) / float(tessellation);
const float v = 1 - float(j) / float(tessellation);
float innerAngle = float(j) * XM_2PI / float(tessellation) + XM_PI;
const float innerAngle = float(j) * XM_2PI / float(tessellation) + XM_PI;
float dx, dy;
XMScalarSinCos(&dy, &dx, innerAngle);
@ -746,7 +746,7 @@ void DirectX::ComputeTorus(VertexCollection& vertices, IndexCollection& indices,
// Create a vertex.
XMVECTOR normal = XMVectorSet(dx, dy, 0, 0);
XMVECTOR position = XMVectorScale(normal, thickness / 2);
XMVECTOR textureCoordinate = XMVectorSet(u, v, 0, 0);
const XMVECTOR textureCoordinate = XMVectorSet(u, v, 0, 0);
position = XMVector3Transform(position, transform);
normal = XMVector3TransformNormal(normal, transform);
@ -754,8 +754,8 @@ void DirectX::ComputeTorus(VertexCollection& vertices, IndexCollection& indices,
vertices.push_back(VertexPositionNormalTexture(position, normal, textureCoordinate));
// And create indices for two triangles.
size_t nextI = (i + 1) % stride;
size_t nextJ = (j + 1) % stride;
const size_t nextI = (i + 1) % stride;
const size_t nextJ = (j + 1) % stride;
index_push_back(indices, i * stride + j);
index_push_back(indices, i * stride + nextJ);
@ -799,16 +799,16 @@ void DirectX::ComputeTetrahedron(VertexCollection& vertices, IndexCollection& in
for (size_t j = 0; j < std::size(faces); j += 3)
{
uint32_t v0 = faces[j];
uint32_t v1 = faces[j + 1];
uint32_t v2 = faces[j + 2];
const uint32_t v0 = faces[j];
const uint32_t v1 = faces[j + 1];
const uint32_t v2 = faces[j + 2];
XMVECTOR normal = XMVector3Cross(
XMVectorSubtract(verts[v1].v, verts[v0].v),
XMVectorSubtract(verts[v2].v, verts[v0].v));
normal = XMVector3Normalize(normal);
size_t base = vertices.size();
const size_t base = vertices.size();
index_push_back(indices, base);
index_push_back(indices, base + 1);
index_push_back(indices, base + 2);
@ -865,16 +865,16 @@ void DirectX::ComputeOctahedron(VertexCollection& vertices, IndexCollection& ind
for (size_t j = 0; j < std::size(faces); j += 3)
{
uint32_t v0 = faces[j];
uint32_t v1 = faces[j + 1];
uint32_t v2 = faces[j + 2];
const uint32_t v0 = faces[j];
const uint32_t v1 = faces[j + 1];
const uint32_t v2 = faces[j + 2];
XMVECTOR normal = XMVector3Cross(
XMVectorSubtract(verts[v1].v, verts[v0].v),
XMVectorSubtract(verts[v2].v, verts[v0].v));
normal = XMVector3Normalize(normal);
size_t base = vertices.size();
const size_t base = vertices.size();
index_push_back(indices, base);
index_push_back(indices, base + 1);
index_push_back(indices, base + 2);
@ -979,18 +979,18 @@ void DirectX::ComputeDodecahedron(VertexCollection& vertices, IndexCollection& i
size_t t = 0;
for (size_t j = 0; j < std::size(faces); j += 5, ++t)
{
uint32_t v0 = faces[j];
uint32_t v1 = faces[j + 1];
uint32_t v2 = faces[j + 2];
uint32_t v3 = faces[j + 3];
uint32_t v4 = faces[j + 4];
const uint32_t v0 = faces[j];
const uint32_t v1 = faces[j + 1];
const uint32_t v2 = faces[j + 2];
const uint32_t v3 = faces[j + 3];
const uint32_t v4 = faces[j + 4];
XMVECTOR normal = XMVector3Cross(
XMVectorSubtract(verts[v1].v, verts[v0].v),
XMVectorSubtract(verts[v2].v, verts[v0].v));
normal = XMVector3Normalize(normal);
size_t base = vertices.size();
const size_t base = vertices.size();
index_push_back(indices, base);
index_push_back(indices, base + 1);
@ -1083,16 +1083,16 @@ void DirectX::ComputeIcosahedron(VertexCollection& vertices, IndexCollection& in
for (size_t j = 0; j < std::size(faces); j += 3)
{
uint32_t v0 = faces[j];
uint32_t v1 = faces[j + 1];
uint32_t v2 = faces[j + 2];
const uint32_t v0 = faces[j];
const uint32_t v1 = faces[j + 1];
const uint32_t v2 = faces[j + 2];
XMVECTOR normal = XMVector3Cross(
XMVectorSubtract(verts[v1].v, verts[v0].v),
XMVectorSubtract(verts[v2].v, verts[v0].v));
normal = XMVector3Normalize(normal);
size_t base = vertices.size();
const size_t base = vertices.size();
index_push_back(indices, base);
index_push_back(indices, base + 1);
index_push_back(indices, base + 2);
@ -1162,11 +1162,11 @@ void DirectX::ComputeTeapot(VertexCollection& vertices, IndexCollection& indices
if (tessellation < 1)
throw std::invalid_argument("tesselation parameter must be non-zero");
XMVECTOR scaleVector = XMVectorReplicate(size);
const XMVECTOR scaleVector = XMVectorReplicate(size);
XMVECTOR scaleNegateX = XMVectorMultiply(scaleVector, g_XMNegateX);
XMVECTOR scaleNegateZ = XMVectorMultiply(scaleVector, g_XMNegateZ);
XMVECTOR scaleNegateXZ = XMVectorMultiply(scaleVector, XMVectorMultiply(g_XMNegateX, g_XMNegateZ));
const XMVECTOR scaleNegateX = XMVectorMultiply(scaleVector, g_XMNegateX);
const XMVECTOR scaleNegateZ = XMVectorMultiply(scaleVector, g_XMNegateZ);
const XMVECTOR scaleNegateXZ = XMVectorMultiply(scaleVector, XMVectorMultiply(g_XMNegateX, g_XMNegateZ));
for (size_t i = 0; i < std::size(TeapotPatches); i++)
{

Просмотреть файл

@ -29,7 +29,7 @@ namespace
static_assert((MinAllocSize & (MinAllocSize - 1)) == 0, "MinAllocSize size must be a power of 2");
static_assert(MinAllocSize >= (4 * 1024), "MinAllocSize size must be greater than 4K");
inline size_t NextPow2(size_t x) noexcept
constexpr size_t NextPow2(size_t x) noexcept
{
x--;
x |= x >> 1;
@ -45,7 +45,7 @@ namespace
inline size_t GetPoolIndexFromSize(size_t x) noexcept
{
size_t allocatorPageSize = x >> AllocatorIndexShift;
const size_t allocatorPageSize = x >> AllocatorIndexShift;
// gives a value from range:
// 0 - sub-4k allocator
// 1 - 4k allocator
@ -112,7 +112,7 @@ namespace
// Explicitly destroy LinearAllocators inside a critical section
~DeviceAllocator()
{
ScopedLock lock(mMutex);
const ScopedLock lock(mMutex);
for (auto& allocator : mPools)
{
@ -125,8 +125,8 @@ namespace
ScopedLock lock(mMutex);
// Which memory pool does it live in?
size_t poolSize = NextPow2((alignment + size) * PoolIndexScale);
size_t poolIndex = GetPoolIndexFromSize(poolSize);
const size_t poolSize = NextPow2((alignment + size) * PoolIndexScale);
const size_t poolIndex = GetPoolIndexFromSize(poolSize);
assert(poolIndex < mPools.size());
// If the allocator isn't initialized yet, do so now

Просмотреть файл

@ -31,7 +31,7 @@ namespace
auto ptr = reinterpret_cast<uint32_t*>(&state);
unsigned int bf = 1u << (key & 0x1f);
const unsigned int bf = 1u << (key & 0x1f);
ptr[(key >> 5)] |= bf;
}
@ -42,7 +42,7 @@ namespace
auto ptr = reinterpret_cast<uint32_t*>(&state);
unsigned int bf = 1u << (key & 0x1f);
const unsigned int bf = 1u << (key & 0x1f);
ptr[(key >> 5)] &= ~bf;
}
}

Просмотреть файл

@ -36,7 +36,7 @@ LinearAllocatorPage::LinearAllocatorPage() noexcept
size_t LinearAllocatorPage::Suballocate(_In_ size_t size, _In_ size_t alignment)
{
size_t offset = AlignUp(mOffset, alignment);
const size_t offset = AlignUp(mOffset, alignment);
if (offset + size > mSize)
{
// Use of suballocate should be limited to pages with free space,
@ -78,7 +78,7 @@ LinearAllocator::LinearAllocator(
m_debugName = L"LinearAllocator";
#endif
size_t preallocatePageCount = ((preallocateBytes + pageSize - 1) / pageSize);
const size_t preallocatePageCount = ((preallocateBytes + pageSize - 1) / pageSize);
for (size_t preallocatePages = 0; preallocateBytes != 0 && preallocatePages < preallocatePageCount; ++preallocatePages)
{
if (GetNewPage() == nullptr)
@ -195,7 +195,7 @@ void LinearAllocator::FenceCommittedPages(_In_ ID3D12CommandQueue* commandQueue)
// (immediately before or after Present-time)
void LinearAllocator::RetirePendingPages() noexcept
{
uint64_t fenceValue = m_fence->GetCompletedValue();
const uint64_t fenceValue = m_fence->GetCompletedValue();
// For each page that we know has a fence pending, check it. If the fence has passed,
// we can mark the page for re-use.
@ -276,7 +276,7 @@ LinearAllocatorPage* LinearAllocator::FindPageForAlloc(
{
for (auto page = list; page != nullptr; page = page->pNextPage)
{
size_t offset = AlignUp(page->mOffset, alignment);
const size_t offset = AlignUp(page->mOffset, alignment);
if (offset + sizeBytes <= m_increment)
return page;
}
@ -285,8 +285,8 @@ LinearAllocatorPage* LinearAllocator::FindPageForAlloc(
LinearAllocatorPage* LinearAllocator::GetNewPage()
{
CD3DX12_HEAP_PROPERTIES uploadHeapProperties(D3D12_HEAP_TYPE_UPLOAD);
CD3DX12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(m_increment);
const CD3DX12_HEAP_PROPERTIES uploadHeapProperties(D3D12_HEAP_TYPE_UPLOAD);
const CD3DX12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(m_increment);
// Allocate the upload heap
ComPtr<ID3D12Resource> spResource;
@ -470,7 +470,7 @@ void LinearAllocator::ValidatePageLists()
void LinearAllocator::SetDebugName(const char* name)
{
wchar_t wname[MAX_PATH] = {};
int result = MultiByteToWideChar(CP_UTF8, 0, name, static_cast<int>(strlen(name)), wname, MAX_PATH);
const int result = MultiByteToWideChar(CP_UTF8, 0, name, static_cast<int>(strlen(name)), wname, MAX_PATH);
if (result > 0)
{
SetDebugName(wname);

Просмотреть файл

@ -309,7 +309,7 @@ namespace DirectX
}
// DDS files always start with the same magic number ("DDS ")
auto dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData);
auto const dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData);
if (dwMagicNumber != DDS_MAGIC)
{
return E_FAIL;
@ -430,7 +430,7 @@ namespace DirectX
}
// DDS files always start with the same magic number ("DDS ")
auto dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData.get());
auto const dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData.get());
if (dwMagicNumber != DDS_MAGIC)
{
ddsData.reset();
@ -601,7 +601,7 @@ namespace DirectX
}
else
{
size_t bpp = BitsPerPixel(fmt);
const size_t bpp = BitsPerPixel(fmt);
if (!bpp)
return E_INVALIDARG;
@ -912,7 +912,7 @@ namespace DirectX
if (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)
{
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>(reinterpret_cast<const uint8_t*>(header) + sizeof(DDS_HEADER));
auto mode = static_cast<DDS_ALPHA_MODE>(d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK);
auto const mode = static_cast<DDS_ALPHA_MODE>(d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK);
switch (mode)
{
case DDS_ALPHA_MODE_STRAIGHT:
@ -1008,7 +1008,7 @@ namespace DirectX
inline void FitPowerOf2(UINT origx, UINT origy, _Inout_ UINT& targetx, _Inout_ UINT& targety, size_t maxsize)
{
float origAR = float(origx) / float(origy);
const float origAR = float(origx) / float(origy);
if (origx > origy)
{
@ -1019,7 +1019,7 @@ namespace DirectX
float bestScore = FLT_MAX;
for (size_t y = maxsize; y > 0; y >>= 1)
{
float score = fabsf((float(x) / float(y)) - origAR);
const float score = fabsf((float(x) / float(y)) - origAR);
if (score < bestScore)
{
bestScore = score;
@ -1036,7 +1036,7 @@ namespace DirectX
float bestScore = FLT_MAX;
for (size_t x = maxsize; x > 0; x >>= 1)
{
float score = fabsf((float(x) / float(y)) - origAR);
const float score = fabsf((float(x) / float(y)) - origAR);
if (score < bestScore)
{
bestScore = score;

Просмотреть файл

@ -335,7 +335,7 @@ void Model::LoadStaticBuffers(
}
}
CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
for (auto it = uniqueParts.cbegin(); it != uniqueParts.cend(); ++it)
{
@ -352,7 +352,7 @@ void Model::LoadStaticBuffers(
part->vertexBufferSize = static_cast<uint32_t>(part->vertexBuffer.Size());
auto desc = CD3DX12_RESOURCE_DESC::Buffer(part->vertexBuffer.Size());
auto const desc = CD3DX12_RESOURCE_DESC::Buffer(part->vertexBuffer.Size());
ThrowIfFailed(device->CreateCommittedResource(
&heapProperties,
@ -408,7 +408,7 @@ void Model::LoadStaticBuffers(
part->indexBufferSize = static_cast<uint32_t>(part->indexBuffer.Size());
auto desc = CD3DX12_RESOURCE_DESC::Buffer(part->indexBuffer.Size());
auto const desc = CD3DX12_RESOURCE_DESC::Buffer(part->indexBuffer.Size());
ThrowIfFailed(device->CreateCommittedResource(
&heapProperties,
@ -590,7 +590,7 @@ void Model::CopyAbsoluteBoneTransformsTo(
memset(boneTransforms, 0, sizeof(XMMATRIX) * nbones);
XMMATRIX id = XMMatrixIdentity();
const XMMATRIX id = XMMatrixIdentity();
size_t visited = 0;
ComputeAbsolute(0, id, bones.size(), boneMatrices.get(), boneTransforms, visited);
}
@ -620,7 +620,7 @@ void Model::CopyAbsoluteBoneTransforms(
memset(outBoneTransforms, 0, sizeof(XMMATRIX) * nbones);
XMMATRIX id = XMMatrixIdentity();
const XMMATRIX id = XMMatrixIdentity();
size_t visited = 0;
ComputeAbsolute(0, id, bones.size(), inBoneTransforms, outBoneTransforms, visited);
}

Просмотреть файл

@ -392,7 +392,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
std::vector<MaterialRecordCMO> materials;
materials.reserve(*nMats);
size_t baseMaterialIndex = modelmats.size();
const size_t baseMaterialIndex = modelmats.size();
for (size_t j = 0; j < *nMats; ++j)
{
MaterialRecordCMO m;
@ -527,7 +527,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
throw std::runtime_error("IB too large for DirectX 12");
}
auto ibBytes = static_cast<size_t>(sizeInBytes);
auto const ibBytes = static_cast<size_t>(sizeInBytes);
auto indexes = reinterpret_cast<const uint16_t*>(meshData + usedSize);
usedSize += ibBytes;
@ -636,8 +636,8 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
mesh->boundingSphere.Center.z = extents->CenterZ;
mesh->boundingSphere.Radius = extents->Radius;
XMVECTOR min = XMVectorSet(extents->MinX, extents->MinY, extents->MinZ, 0.f);
XMVECTOR max = XMVectorSet(extents->MaxX, extents->MaxY, extents->MaxZ, 0.f);
const XMVECTOR min = XMVectorSet(extents->MinX, extents->MinY, extents->MinZ, 0.f);
const XMVECTOR max = XMVectorSet(extents->MaxX, extents->MaxY, extents->MaxZ, 0.f);
BoundingBox::CreateFromPoints(mesh->boundingBox, min, max);
// Load model bones (if present and requested)
@ -694,7 +694,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
if (visited >= *nBones)
throw std::runtime_error("Skeleton bones form an invalid graph");
uint32_t sibling = bones[index].siblingIndex;
const uint32_t sibling = bones[index].siblingIndex;
if (sibling == ModelBone::c_Invalid)
{
bones[index].siblingIndex = j;
@ -734,7 +734,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
if (visited >= *nBones)
throw std::runtime_error("Skeleton bones form an invalid graph");
uint32_t sibling = bones[index].siblingIndex;
const uint32_t sibling = bones[index].siblingIndex;
if (sibling == ModelBone::c_Invalid)
{
bones[index].siblingIndex = j;
@ -773,7 +773,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
}
}
bool enableSkinning = (*nSkinVBs) != 0 && !(flags & ModelLoader_DisableSkinning);
const bool enableSkinning = (*nSkinVBs) != 0 && !(flags & ModelLoader_DisableSkinning);
// Build vertex buffers
std::vector<SharedGraphicsResource> vbs;
@ -846,7 +846,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
|| (sm.MaterialIndex >= materials.size()))
throw std::out_of_range("Invalid submesh found\n");
XMMATRIX uvTransform = XMLoadFloat4x4(&materials[sm.MaterialIndex].pMaterial->UVTransform);
const XMMATRIX uvTransform = XMLoadFloat4x4(&materials[sm.MaterialIndex].pMaterial->UVTransform);
auto ib = ibData[sm.IndexBufferIndex].ptr;
@ -875,7 +875,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
else if (visited[v] != sm.MaterialIndex)
{
#ifdef _DEBUG
XMMATRIX uv2 = XMLoadFloat4x4(&materials[visited[v]].pMaterial->UVTransform);
const XMMATRIX uv2 = XMLoadFloat4x4(&materials[visited[v]].pMaterial->UVTransform);
if (XMVector4NotEqual(uvTransform.r[0], uv2.r[0])
|| XMVector4NotEqual(uvTransform.r[1], uv2.r[1])
@ -898,7 +898,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
assert(vbs.size() == *nVBs);
// Create model materials
bool srgb = (flags & ModelLoader_MaterialColorsSRGB) != 0;
const bool srgb = (flags & ModelLoader_MaterialColorsSRGB) != 0;
for (size_t j = 0; j < materials.size(); ++j)
{

Просмотреть файл

@ -385,14 +385,14 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
if (!meshData)
throw std::invalid_argument("meshData cannot be null");
uint64_t dataSize = idataSize;
const uint64_t dataSize = idataSize;
// File Headers
if (dataSize < sizeof(DXUT::SDKMESH_HEADER))
throw std::runtime_error("End of file");
auto header = reinterpret_cast<const DXUT::SDKMESH_HEADER*>(meshData);
size_t headerSize = sizeof(DXUT::SDKMESH_HEADER)
const size_t headerSize = sizeof(DXUT::SDKMESH_HEADER)
+ header->NumVertexBuffers * sizeof(DXUT::SDKMESH_VERTEX_BUFFER_HEADER)
+ header->NumIndexBuffers * sizeof(DXUT::SDKMESH_INDEX_BUFFER_HEADER);
if (header->HeaderSize != headerSize)
@ -472,7 +472,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
}
// Buffer data
uint64_t bufferDataOffset = header->HeaderSize + header->NonBufferDataSize;
const uint64_t bufferDataOffset = header->HeaderSize + header->NonBufferDataSize;
if ((dataSize < bufferDataOffset)
|| (dataSize < bufferDataOffset + header->BufferDataSize))
throw std::runtime_error("End of file");
@ -613,7 +613,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
// Create subsets
for (size_t j = 0; j < mh.NumSubsets; ++j)
{
auto sIndex = subsets[j];
auto const sIndex = subsets[j];
if (sIndex >= header->NumTotalSubsets)
throw std::out_of_range("Invalid mesh found");
@ -679,14 +679,14 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
// Vertex data
auto verts = bufferData + (vh.DataOffset - bufferDataOffset);
auto vbytes = static_cast<size_t>(vh.SizeBytes);
auto const vbytes = static_cast<size_t>(vh.SizeBytes);
part->vertexBufferSize = static_cast<uint32_t>(vh.SizeBytes);
part->vertexBuffer = GraphicsMemory::Get(device).Allocate(vbytes);
memcpy(part->vertexBuffer.Memory(), verts, vbytes);
// Index data
auto indices = bufferData + (ih.DataOffset - bufferDataOffset);
auto ibytes = static_cast<size_t>(ih.SizeBytes);
auto const ibytes = static_cast<size_t>(ih.SizeBytes);
part->indexBufferSize = static_cast<uint32_t>(ih.SizeBytes);
part->indexBuffer = GraphicsMemory::Get(device).Allocate(ibytes);
memcpy(part->indexBuffer.Memory(), indices, ibytes);
@ -734,7 +734,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
transforms[j] = XMLoadFloat4x4(&frameArray[j].Matrix);
uint32_t index = frameArray[j].Mesh;
const uint32_t index = frameArray[j].Mesh;
if (index != DXUT::INVALID_MESH)
{
if (index >= model->meshes.size())

Просмотреть файл

@ -76,7 +76,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromVBO(
throw std::runtime_error("VB too large for DirectX 12");
}
auto vertSize = static_cast<size_t>(sizeInBytes);
auto const vertSize = static_cast<size_t>(sizeInBytes);
if (dataSize < (vertSize + sizeof(VBO::header_t)))
throw std::runtime_error("End of file");
@ -92,7 +92,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromVBO(
throw std::runtime_error("IB too large for DirectX 12");
}
auto indexSize = static_cast<size_t>(sizeInBytes);
auto const indexSize = static_cast<size_t>(sizeInBytes);
if (dataSize < (sizeof(VBO::header_t) + vertSize + indexSize))
throw std::runtime_error("End of file");

Просмотреть файл

@ -554,7 +554,7 @@ public:
throw std::system_error(std::error_code(static_cast<int>(GetLastError()), std::system_category()), "GetCursorInfo");
}
bool isvisible = (info.flags & CURSOR_SHOWING) != 0;
const bool isvisible = (info.flags & CURSOR_SHOWING) != 0;
if (isvisible != visible)
{
ShowCursor(visible);
@ -721,7 +721,7 @@ void Mouse::ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam)
}
else
{
int scrollWheel = pImpl->mState.scrollWheelValue;
const int scrollWheel = pImpl->mState.scrollWheelValue;
memset(&pImpl->mState, 0, sizeof(State));
pImpl->mState.scrollWheelValue = scrollWheel;
@ -740,7 +740,7 @@ void Mouse::ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam)
RAWINPUT raw;
UINT rawSize = sizeof(raw);
UINT resultData = GetRawInputData(reinterpret_cast<HRAWINPUT>(lParam), RID_INPUT, &raw, &rawSize, sizeof(RAWINPUTHEADER));
const UINT resultData = GetRawInputData(reinterpret_cast<HRAWINPUT>(lParam), RID_INPUT, &raw, &rawSize, sizeof(RAWINPUTHEADER));
if (resultData == UINT(-1))
{
throw std::runtime_error("GetRawInputData");
@ -761,8 +761,8 @@ void Mouse::ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam)
const int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
const int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
int x = static_cast<int>((float(raw.data.mouse.lLastX) / 65535.0f) * float(width));
int y = static_cast<int>((float(raw.data.mouse.lLastY) / 65535.0f) * float(height));
auto const x = static_cast<int>((float(raw.data.mouse.lLastX) / 65535.0f) * float(width));
auto const y = static_cast<int>((float(raw.data.mouse.lLastY) / 65535.0f) * float(height));
if (pImpl->mRelativeX == INT32_MAX)
{
@ -851,8 +851,8 @@ void Mouse::ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam)
if (pImpl->mMode == MODE_ABSOLUTE)
{
// All mouse messages provide a new pointer position
int xPos = static_cast<short>(LOWORD(lParam)); // GET_X_LPARAM(lParam);
int yPos = static_cast<short>(HIWORD(lParam)); // GET_Y_LPARAM(lParam);
const int xPos = static_cast<short>(LOWORD(lParam)); // GET_X_LPARAM(lParam);
const int yPos = static_cast<short>(HIWORD(lParam)); // GET_Y_LPARAM(lParam);
pImpl->mState.x = pImpl->mLastX = xPos;
pImpl->mState.y = pImpl->mLastY = yPos;

Просмотреть файл

@ -447,20 +447,20 @@ void NormalMapEffect::Impl::Initialize(
// Create root signature.
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
CD3DX12_ROOT_PARAMETER rootParameters[RootParameterIndex::RootParameterCount] = {};
CD3DX12_DESCRIPTOR_RANGE textureSRV(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSRV(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
rootParameters[RootParameterIndex::TextureSRV].InitAsDescriptorTable(1, &textureSRV, D3D12_SHADER_VISIBILITY_PIXEL);
CD3DX12_DESCRIPTOR_RANGE textureSRV2(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1);
const CD3DX12_DESCRIPTOR_RANGE textureSRV2(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1);
rootParameters[RootParameterIndex::TextureNormalSRV].InitAsDescriptorTable(1, &textureSRV2, D3D12_SHADER_VISIBILITY_PIXEL);
CD3DX12_DESCRIPTOR_RANGE textureSampler(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSampler(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
rootParameters[RootParameterIndex::TextureSampler].InitAsDescriptorTable(1, &textureSampler, D3D12_SHADER_VISIBILITY_PIXEL);
rootParameters[RootParameterIndex::ConstantBuffer].InitAsConstantBufferView(0, 0, D3D12_SHADER_VISIBILITY_ALL);
rootParameters[RootParameterIndex::ConstantBufferBones].InitAsConstantBufferView(1, 0, D3D12_SHADER_VISIBILITY_VERTEX);
@ -469,7 +469,7 @@ void NormalMapEffect::Impl::Initialize(
if (specularMap)
{
CD3DX12_DESCRIPTOR_RANGE textureSRV3(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 2);
const CD3DX12_DESCRIPTOR_RANGE textureSRV3(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 2);
rootParameters[RootParameterIndex::TextureSpecularSRV].InitAsDescriptorTable(1, &textureSRV3, D3D12_SHADER_VISIBILITY_PIXEL);
rsigDesc.Init(static_cast<UINT>(std::size(rootParameters)), rootParameters, 0, nullptr, rootSignatureFlags);
@ -489,14 +489,14 @@ void NormalMapEffect::Impl::Initialize(
fog.enabled = (effectFlags & EffectFlags::Fog) != 0;
// Create pipeline state.
int sp = GetPipelineStatePermutation(effectFlags);
const int sp = GetPipelineStatePermutation(effectFlags);
assert(sp >= 0 && sp < NormalMapEffectTraits::ShaderPermutationCount);
_Analysis_assume_(sp >= 0 && sp < NormalMapEffectTraits::ShaderPermutationCount);
int vi = EffectBase<NormalMapEffectTraits>::VertexShaderIndices[sp];
const int vi = EffectBase<NormalMapEffectTraits>::VertexShaderIndices[sp];
assert(vi >= 0 && vi < NormalMapEffectTraits::VertexShaderCount);
_Analysis_assume_(vi >= 0 && vi < NormalMapEffectTraits::VertexShaderCount);
int pi = EffectBase<NormalMapEffectTraits>::PixelShaderIndices[sp];
const int pi = EffectBase<NormalMapEffectTraits>::PixelShaderIndices[sp];
assert(pi >= 0 && pi < NormalMapEffectTraits::PixelShaderCount);
_Analysis_assume_(pi >= 0 && pi < NormalMapEffectTraits::PixelShaderCount);
@ -608,7 +608,7 @@ void NormalMapEffect::Impl::Apply(_In_ ID3D12GraphicsCommandList* commandList)
}
// Set constants
auto cbuffer = GetConstantBufferGpuAddress();
auto const cbuffer = GetConstantBufferGpuAddress();
commandList->SetGraphicsRootConstantBufferView(RootParameterIndex::ConstantBuffer, cbuffer);
commandList->SetGraphicsRootConstantBufferView(RootParameterIndex::ConstantBufferBones,
(weightsPerVertex > 0) ? mBones.GpuAddress() : cbuffer);

Просмотреть файл

@ -371,11 +371,11 @@ void PBREffect::Impl::Initialize(
// Create root signature
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | // Only the input assembler stage needs access to the constant buffer.
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
CD3DX12_ROOT_PARAMETER rootParameters[RootParametersCount] = {};
CD3DX12_DESCRIPTOR_RANGE textureSRV[6] = {
@ -430,14 +430,14 @@ void PBREffect::Impl::Initialize(
}
// Create pipeline state.
int sp = GetPipelineStatePermutation(effectFlags);
const int sp = GetPipelineStatePermutation(effectFlags);
assert(sp >= 0 && sp < PBREffectTraits::ShaderPermutationCount);
_Analysis_assume_(sp >= 0 && sp < PBREffectTraits::ShaderPermutationCount);
int vi = EffectBase<PBREffectTraits>::VertexShaderIndices[sp];
const int vi = EffectBase<PBREffectTraits>::VertexShaderIndices[sp];
assert(vi >= 0 && vi < PBREffectTraits::VertexShaderCount);
_Analysis_assume_(vi >= 0 && vi < PBREffectTraits::VertexShaderCount);
int pi = EffectBase<PBREffectTraits>::PixelShaderIndices[sp];
const int pi = EffectBase<PBREffectTraits>::PixelShaderIndices[sp];
assert(pi >= 0 && pi < PBREffectTraits::PixelShaderCount);
_Analysis_assume_(pi >= 0 && pi < PBREffectTraits::PixelShaderCount);
@ -515,7 +515,7 @@ void PBREffect::Impl::Apply(_In_ ID3D12GraphicsCommandList* commandList)
{
constants.world = XMMatrixTranspose(matrices.world);
XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
const XMMATRIX worldInverse = XMMatrixInverse(nullptr, matrices.world);
constants.worldInverseTranspose[0] = worldInverse.r[0];
constants.worldInverseTranspose[1] = worldInverse.r[1];
@ -528,7 +528,7 @@ void PBREffect::Impl::Apply(_In_ ID3D12GraphicsCommandList* commandList)
// Eye position vector.
if (dirtyFlags & EffectDirtyFlags::EyePosition)
{
XMMATRIX viewInverse = XMMatrixInverse(nullptr, matrices.view);
const XMMATRIX viewInverse = XMMatrixInverse(nullptr, matrices.view);
constants.eyePosition = viewInverse.r[3];
@ -628,7 +628,7 @@ void PBREffect::Impl::Apply(_In_ ID3D12GraphicsCommandList* commandList)
}
// Set constants
auto cbuffer = GetConstantBufferGpuAddress();
auto const cbuffer = GetConstantBufferGpuAddress();
commandList->SetGraphicsRootConstantBufferView(RootParameterIndex::ConstantBuffer, cbuffer);
commandList->SetGraphicsRootConstantBufferView(RootParameterIndex::ConstantBufferBones,
(weightsPerVertex > 0) ? mBones.GpuAddress() : cbuffer);

Просмотреть файл

@ -26,9 +26,9 @@ namespace
void SetPBRProperties(
_In_ T* effect,
const EffectFactory::EffectInfo& info,
_In_ DescriptorHeap* textures,
_In_ const DescriptorHeap* textures,
int textureDescriptorOffset,
_In_ DescriptorHeap* samplers,
_In_ const DescriptorHeap* samplers,
int samplerDescriptorOffset)
{
// We don't use EnableDefaultLighting generally for PBR as it uses Image-Based Lighting instead.
@ -59,7 +59,7 @@ namespace
else
{
// Untextured material (for PBR this still requires texture coordinates)
XMVECTOR color = XMLoadFloat3(&info.diffuseColor);
const XMVECTOR color = XMLoadFloat3(&info.diffuseColor);
effect->SetConstantAlbedo(color);
if (info.specularColor.x != 0 || info.specularColor.y != 0 || info.specularColor.z != 0)
@ -67,7 +67,7 @@ namespace
// Derived from specularPower = 2 / roughness ^ 4 - 2
// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
float roughness = powf(2.f / (info.specularPower + 2.f), 1.f / 4.f);
const float roughness = powf(2.f / (info.specularPower + 2.f), 1.f / 4.f);
effect->SetConstantRoughness(roughness);
}
@ -166,7 +166,7 @@ std::shared_ptr<IEffect> PBREffectFactory::Impl::CreateEffect(
std::wstring cacheName;
if (mSharing && !info.name.empty())
{
uint32_t hash = derivedPSD.ComputeHash();
const uint32_t hash = derivedPSD.ComputeHash();
cacheName = std::to_wstring(effectflags) + info.name + std::to_wstring(hash);
auto it = mEffectCacheSkinning.find(cacheName);
@ -202,7 +202,7 @@ std::shared_ptr<IEffect> PBREffectFactory::Impl::CreateEffect(
std::wstring cacheName;
if (mSharing && !info.name.empty())
{
uint32_t hash = derivedPSD.ComputeHash();
const uint32_t hash = derivedPSD.ComputeHash();
cacheName = std::to_wstring(effectflags) + info.name + std::to_wstring(hash);
auto it = mEffectCache.find(cacheName);
@ -270,11 +270,8 @@ PBREffectFactory::PBREffectFactory(_In_ ID3D12DescriptorHeap* textureDescriptors
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
textureDescriptors->GetDevice(IID_GRAPHICS_PPV_ARGS(device.GetAddressOf()));
#else
HRESULT hresult = textureDescriptors->GetDevice(IID_PPV_ARGS(device.GetAddressOf()));
if (FAILED(hresult))
{
throw com_exception(hresult);
}
HRESULT hr = textureDescriptors->GetDevice(IID_PPV_ARGS(device.GetAddressOf()));
ThrowIfFailed(hr);
#endif
pImpl = std::make_shared<Impl>(device.Get(), textureDescriptors, samplerDescriptors);

Просмотреть файл

@ -155,8 +155,8 @@ void PrimitiveBatchBase::Impl::Draw(D3D_PRIMITIVE_TOPOLOGY topology, bool isInde
assert(pMappedVertices != nullptr);
// Can we merge this primitive in with an existing batch, or must we flush first?
bool wrapIndexBuffer = (mIndexCount + indexCount > mMaxIndices);
bool wrapVertexBuffer = (mVertexCount + vertexCount > mMaxVertices);
const bool wrapIndexBuffer = (mIndexCount + indexCount > mMaxIndices);
const bool wrapVertexBuffer = (mVertexCount + vertexCount > mMaxVertices);
if ((topology != mCurrentTopology) ||
(isIndexed != mCurrentlyIndexed) ||

Просмотреть файл

@ -229,22 +229,22 @@ namespace
static ComPtr<ID3D12RootSignature> CreateGenMipsRootSignature(
_In_ ID3D12Device* device)
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS;
CD3DX12_STATIC_SAMPLER_DESC sampler(
const CD3DX12_STATIC_SAMPLER_DESC sampler(
0, // register
D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT,
D3D12_TEXTURE_ADDRESS_MODE_CLAMP,
D3D12_TEXTURE_ADDRESS_MODE_CLAMP,
D3D12_TEXTURE_ADDRESS_MODE_CLAMP);
CD3DX12_DESCRIPTOR_RANGE sourceDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
CD3DX12_DESCRIPTOR_RANGE targetDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE sourceDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE targetDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0);
CD3DX12_ROOT_PARAMETER rootParameters[RootParameterIndex::RootParameterCount] = {};
rootParameters[RootParameterIndex::Constants].InitAsConstants(Num32BitConstants, 0);
@ -347,13 +347,13 @@ public:
if (!mInBeginEndBlock)
throw std::logic_error("Can't call Upload on a closed ResourceUploadBatch.");
UINT64 uploadSize = GetRequiredIntermediateSize(
const UINT64 uploadSize = GetRequiredIntermediateSize(
resource,
subresourceIndexStart,
numSubresources);
CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
CD3DX12_RESOURCE_DESC resDesc = CD3DX12_RESOURCE_DESC::Buffer(uploadSize);
const CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
auto const resDesc = CD3DX12_RESOURCE_DESC::Buffer(uploadSize);
// Create a temporary buffer
ComPtr<ID3D12Resource> scratchResource = nullptr;
@ -433,7 +433,7 @@ public:
throw std::runtime_error("GenerateMips only supports 2D textures of array size 1");
}
bool uavCompat = FormatIsUAVCompatible(mDevice.Get(), mTypedUAVLoadAdditionalFormats, desc.Format);
const bool uavCompat = FormatIsUAVCompatible(mDevice.Get(), mTypedUAVLoadAdditionalFormats, desc.Format);
if (!uavCompat && !FormatIsSRGB(desc.Format) && !FormatIsBGR(desc.Format))
{
@ -556,7 +556,7 @@ public:
std::future<void> future = std::async(std::launch::async, [uploadBatch]()
{
// Wait on the GPU-complete notification
DWORD wr = WaitForSingleObject(uploadBatch->GpuCompleteEvent.get(), INFINITE);
const DWORD wr = WaitForSingleObject(uploadBatch->GpuCompleteEvent.get(), INFINITE);
if (wr != WAIT_OBJECT_0)
{
if (wr == WAIT_FAILED)
@ -624,7 +624,7 @@ private:
const auto desc = resource->GetDesc();
assert(!FormatIsBGR(desc.Format) && !FormatIsSRGB(desc.Format));
CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
assert(mCommandType != D3D12_COMMAND_LIST_TYPE_COPY);
const D3D12_RESOURCE_STATES originalState = (mCommandType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
@ -651,8 +651,8 @@ private:
// Copy the top mip of resource to staging
TransitionResource(mList.Get(), resource, originalState, D3D12_RESOURCE_STATE_COPY_SOURCE);
CD3DX12_TEXTURE_COPY_LOCATION src(resource, 0);
CD3DX12_TEXTURE_COPY_LOCATION dst(staging.Get(), 0);
const CD3DX12_TEXTURE_COPY_LOCATION src(resource, 0);
const CD3DX12_TEXTURE_COPY_LOCATION dst(staging.Get(), 0);
mList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
TransitionResource(mList.Get(), staging.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
@ -675,7 +675,7 @@ private:
SetDebugObjectName(descriptorHeap.Get(), L"ResourceUploadBatch");
auto descriptorSize = static_cast<int>(mDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV));
auto const descriptorSize = static_cast<int>(mDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV));
// Create the top-level SRV
CD3DX12_CPU_DESCRIPTOR_HANDLE handleIt(descriptorHeap->GetCPUDescriptorHandleForHeapStart());
@ -825,7 +825,7 @@ private:
copyDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
copyDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES heapProperties(D3D12_HEAP_TYPE_DEFAULT);
// Create a resource with the same description, but without SRGB, and with UAV flags
ComPtr<ID3D12Resource> resourceCopy;
@ -846,8 +846,8 @@ private:
// Copy the top mip of resource data
TransitionResource(mList.Get(), resource, originalState, D3D12_RESOURCE_STATE_COPY_SOURCE);
CD3DX12_TEXTURE_COPY_LOCATION src(resource, 0);
CD3DX12_TEXTURE_COPY_LOCATION dst(resourceCopy.Get(), 0);
const CD3DX12_TEXTURE_COPY_LOCATION src(resource, 0);
const CD3DX12_TEXTURE_COPY_LOCATION dst(resourceCopy.Get(), 0);
mList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
TransitionResource(mList.Get(), resourceCopy.Get(), D3D12_RESOURCE_STATE_COPY_DEST, originalState);
@ -895,7 +895,7 @@ private:
#endif
D3D12_HEAP_DESC heapDesc = {};
auto allocInfo = mDevice->GetResourceAllocationInfo(0, 1, &copyDesc);
auto const allocInfo = mDevice->GetResourceAllocationInfo(0, 1, &copyDesc);
heapDesc.SizeInBytes = allocInfo.SizeInBytes;
heapDesc.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES;
heapDesc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT;
@ -950,8 +950,8 @@ private:
mList->ResourceBarrier(2, aliasBarrier);
CD3DX12_TEXTURE_COPY_LOCATION src(resource, 0);
CD3DX12_TEXTURE_COPY_LOCATION dst(aliasCopy.Get(), 0);
const CD3DX12_TEXTURE_COPY_LOCATION src(resource, 0);
const CD3DX12_TEXTURE_COPY_LOCATION dst(aliasCopy.Get(), 0);
mList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
// Generate the mips

Просмотреть файл

@ -62,7 +62,7 @@ namespace
if (srcPitch > UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
UINT numberOfPlanes = D3D12GetFormatPlaneCount(device, desc.Format);
const UINT numberOfPlanes = D3D12GetFormatPlaneCount(device, desc.Format);
if (numberOfPlanes != 1)
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
@ -101,8 +101,8 @@ namespace
assert((srcPitch & 0xFF) == 0);
CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
CD3DX12_HEAP_PROPERTIES readBackHeapProperties(D3D12_HEAP_TYPE_READBACK);
const CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES readBackHeapProperties(D3D12_HEAP_TYPE_READBACK);
// Readback resources must be buffers
D3D12_RESOURCE_DESC bufferDesc = {};
@ -140,7 +140,7 @@ namespace
SetDebugObjectName(pTemp.Get(), L"ScreenGrab temporary");
DXGI_FORMAT fmt = EnsureNotTypeless(desc.Format);
const DXGI_FORMAT fmt = EnsureNotTypeless(desc.Format);
D3D12_FEATURE_DATA_FORMAT_SUPPORT formatInfo = { fmt, D3D12_FORMAT_SUPPORT1_NONE, D3D12_FORMAT_SUPPORT2_NONE };
hr = device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &formatInfo, sizeof(formatInfo));
@ -154,7 +154,7 @@ namespace
{
for (UINT level = 0; level < desc.MipLevels; ++level)
{
UINT index = D3D12CalcSubresource(level, item, 0, desc.MipLevels, desc.DepthOrArraySize);
const UINT index = D3D12CalcSubresource(level, item, 0, desc.MipLevels, desc.DepthOrArraySize);
commandList->ResolveSubresource(pTemp.Get(), index, pSource, index, fmt);
}
}
@ -188,8 +188,8 @@ namespace
bufferFootprint.Footprint.RowPitch = static_cast<UINT>(srcPitch);
bufferFootprint.Footprint.Format = desc.Format;
CD3DX12_TEXTURE_COPY_LOCATION copyDest(pStaging.Get(), bufferFootprint);
CD3DX12_TEXTURE_COPY_LOCATION copySrc(copySource.Get(), 0);
const CD3DX12_TEXTURE_COPY_LOCATION copyDest(pStaging.Get(), bufferFootprint);
const CD3DX12_TEXTURE_COPY_LOCATION copySrc(copySource.Get(), 0);
// Copy the texture
commandList->CopyTextureRegion(&copyDest, 0, 0, 0, &copySrc, nullptr);
@ -255,10 +255,10 @@ HRESULT DirectX::SaveDDSTextureToFile(
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
// Round up the srcPitch to multiples of 1024
UINT64 dstRowPitch = (fpRowPitch + static_cast<uint64_t>(D3D12XBOX_TEXTURE_DATA_PITCH_ALIGNMENT) - 1u) & ~(static_cast<uint64_t>(D3D12XBOX_TEXTURE_DATA_PITCH_ALIGNMENT) - 1u);
const UINT64 dstRowPitch = (fpRowPitch + static_cast<uint64_t>(D3D12XBOX_TEXTURE_DATA_PITCH_ALIGNMENT) - 1u) & ~(static_cast<uint64_t>(D3D12XBOX_TEXTURE_DATA_PITCH_ALIGNMENT) - 1u);
#else
// Round up the srcPitch to multiples of 256
UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFFu;
const UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFFu;
#endif
if (dstRowPitch > UINT32_MAX)
@ -280,7 +280,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
auto_delete_file delonfail(hFile.get());
// Setup header
const size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
constexpr size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
uint8_t fileHeader[MAX_HEADER_SIZE] = {};
*reinterpret_cast<uint32_t*>(&fileHeader[0]) = DDS_MAGIC;
@ -378,7 +378,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
assert(fpRowCount == rowCount);
assert(fpRowPitch == rowPitch);
UINT64 imageSize = dstRowPitch * UINT64(rowCount);
const UINT64 imageSize = dstRowPitch * UINT64(rowCount);
if (imageSize > UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
@ -398,7 +398,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
uint8_t* dptr = pixels.get();
size_t msize = std::min<size_t>(rowPitch, size_t(dstRowPitch));
const size_t msize = std::min<size_t>(rowPitch, size_t(dstRowPitch));
for (size_t h = 0; h < rowCount; ++h)
{
memcpy(dptr, sptr, msize);
@ -481,7 +481,7 @@ HRESULT DirectX::SaveWICTextureToFile(
UINT64 dstRowPitch = (fpRowPitch + static_cast<uint64_t>(D3D12XBOX_TEXTURE_DATA_PITCH_ALIGNMENT) - 1u) & ~(static_cast<uint64_t>(D3D12XBOX_TEXTURE_DATA_PITCH_ALIGNMENT) - 1u);
#else
// Round up the srcPitch to multiples of 256
UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFFu;
const UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFFu;
#endif
if (dstRowPitch > UINT32_MAX)
@ -722,7 +722,7 @@ HRESULT DirectX::SaveWICTextureToFile(
#endif
}
UINT64 imageSize = dstRowPitch * UINT64(desc.Height);
const UINT64 imageSize = dstRowPitch * UINT64(desc.Height);
if (imageSize > UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);

Просмотреть файл

@ -89,9 +89,9 @@ namespace DirectX
~WrappedData()
{
std::lock_guard<std::mutex> lock(mResourceMap->mutex);
const std::lock_guard<std::mutex> lock(mResourceMap->mutex);
auto pos = mResourceMap->find(mKey);
auto const pos = mResourceMap->find(mKey);
// Check for weak reference expiry before erasing, in case DemandCreate runs on
// a different thread at the same time as a previous instance is being destroyed.

Просмотреть файл

@ -65,18 +65,18 @@ using namespace DirectX::SimpleMath;
void Quaternion::RotateTowards(const Quaternion& target, float maxAngle, Quaternion& result) const noexcept
{
XMVECTOR T = XMLoadFloat4(this);
const XMVECTOR T = XMLoadFloat4(this);
// We can use the conjugate here instead of inverse assuming q1 & q2 are normalized.
XMVECTOR R = XMQuaternionMultiply(XMQuaternionConjugate(T), target);
const XMVECTOR R = XMQuaternionMultiply(XMQuaternionConjugate(T), target);
float rs = XMVectorGetW(R);
XMVECTOR L = XMVector3Length(R);
float angle = 2.f * atan2f(XMVectorGetX(L), rs);
const float rs = XMVectorGetW(R);
const XMVECTOR L = XMVector3Length(R);
const float angle = 2.f * atan2f(XMVectorGetX(L), rs);
if (angle > maxAngle)
{
XMVECTOR delta = XMQuaternionRotationAxis(R, maxAngle);
XMVECTOR Q = XMQuaternionMultiply(delta, T);
const XMVECTOR delta = XMQuaternionRotationAxis(R, maxAngle);
const XMVECTOR Q = XMQuaternionMultiply(delta, T);
XMStoreFloat4(&result, Q);
}
else
@ -90,10 +90,10 @@ void Quaternion::FromToRotation(const Vector3& fromDir, const Vector3& toDir, Qu
{
// Melax, "The Shortest Arc Quaternion", Game Programming Gems, Charles River Media (2000).
XMVECTOR F = XMVector3Normalize(fromDir);
XMVECTOR T = XMVector3Normalize(toDir);
const XMVECTOR F = XMVector3Normalize(fromDir);
const XMVECTOR T = XMVector3Normalize(toDir);
float dot = XMVectorGetX(XMVector3Dot(F, T));
const float dot = XMVectorGetX(XMVector3Dot(F, T));
if (dot >= 1.f)
{
result = Identity;
@ -106,15 +106,15 @@ void Quaternion::FromToRotation(const Vector3& fromDir, const Vector3& toDir, Qu
axis = XMVector3Cross(F, Vector3::Up);
}
XMVECTOR Q = XMQuaternionRotationAxis(axis, XM_PI);
const XMVECTOR Q = XMQuaternionRotationAxis(axis, XM_PI);
XMStoreFloat4(&result, Q);
}
else
{
XMVECTOR C = XMVector3Cross(F, T);
const XMVECTOR C = XMVector3Cross(F, T);
XMStoreFloat4(&result, C);
float s = sqrtf((1.f + dot) * 2.f);
const float s = sqrtf((1.f + dot) * 2.f);
result.x /= s;
result.y /= s;
result.z /= s;
@ -127,7 +127,7 @@ void Quaternion::LookRotation(const Vector3& forward, const Vector3& up, Quatern
Quaternion q1;
FromToRotation(Vector3::Forward, forward, q1);
XMVECTOR C = XMVector3Cross(forward, up);
const XMVECTOR C = XMVector3Cross(forward, up);
if (XMVector3NearEqual(XMVector3LengthSq(C), g_XMZero, g_XMEpsilon))
{
// forward and up are co-linear
@ -135,7 +135,7 @@ void Quaternion::LookRotation(const Vector3& forward, const Vector3& up, Quatern
return;
}
XMVECTOR U = XMQuaternionMultiply(q1, Vector3::Up);
const XMVECTOR U = XMQuaternionMultiply(q1, Vector3::Up);
Quaternion q2;
FromToRotation(U, up, q2);
@ -190,7 +190,7 @@ RECT Viewport::ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UI
// Note: This scaling option is not supported for legacy Win32 windows swap chains
{
assert(backBufferHeight > 0);
float aspectRatio = float(backBufferWidth) / float(backBufferHeight);
const float aspectRatio = float(backBufferWidth) / float(backBufferHeight);
// Horizontal fill
float scaledWidth = float(outputWidth);
@ -202,8 +202,8 @@ RECT Viewport::ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UI
scaledHeight = float(outputHeight);
}
float offsetX = (float(outputWidth) - scaledWidth) * 0.5f;
float offsetY = (float(outputHeight) - scaledHeight) * 0.5f;
const float offsetX = (float(outputWidth) - scaledWidth) * 0.5f;
const float offsetY = (float(outputHeight) - scaledHeight) * 0.5f;
rct.left = static_cast<LONG>(offsetX);
rct.top = static_cast<LONG>(offsetY);
@ -234,8 +234,8 @@ RECT Viewport::ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UI
RECT Viewport::ComputeTitleSafeArea(UINT backBufferWidth, UINT backBufferHeight) noexcept
{
float safew = (float(backBufferWidth) + 19.f) / 20.f;
float safeh = (float(backBufferHeight) + 19.f) / 20.f;
const float safew = (float(backBufferWidth) + 19.f) / 20.f;
const float safeh = (float(backBufferHeight) + 19.f) / 20.f;
RECT rct;
rct.left = static_cast<LONG>(safew);

Просмотреть файл

@ -203,14 +203,14 @@ SkinnedEffect::Impl::Impl(
// Create root signature.
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
CD3DX12_DESCRIPTOR_RANGE textureSrvDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
CD3DX12_DESCRIPTOR_RANGE textureSamplerDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSrvDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSamplerDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
CD3DX12_ROOT_PARAMETER rootParameters[RootParameterIndex::RootParameterCount] = {};
rootParameters[RootParameterIndex::TextureSRV].InitAsDescriptorTable(1, &textureSrvDescriptorRange, D3D12_SHADER_VISIBILITY_PIXEL);
@ -239,14 +239,14 @@ SkinnedEffect::Impl::Impl(
}
// Create pipeline state.
int sp = GetPipelineStatePermutation(effectFlags);
const int sp = GetPipelineStatePermutation(effectFlags);
assert(sp >= 0 && sp < SkinnedEffectTraits::ShaderPermutationCount);
_Analysis_assume_(sp >= 0 && sp < SkinnedEffectTraits::ShaderPermutationCount);
int vi = EffectBase<SkinnedEffectTraits>::VertexShaderIndices[sp];
const int vi = EffectBase<SkinnedEffectTraits>::VertexShaderIndices[sp];
assert(vi >= 0 && vi < SkinnedEffectTraits::VertexShaderCount);
_Analysis_assume_(vi >= 0 && vi < SkinnedEffectTraits::VertexShaderCount);
int pi = EffectBase<SkinnedEffectTraits>::PixelShaderIndices[sp];
const int pi = EffectBase<SkinnedEffectTraits>::PixelShaderIndices[sp];
assert(pi >= 0 && pi < SkinnedEffectTraits::PixelShaderCount);
_Analysis_assume_(pi >= 0 && pi < SkinnedEffectTraits::PixelShaderCount);

Просмотреть файл

@ -304,8 +304,8 @@ void SpriteBatch::Impl::DeviceResources::CreateIndexBuffer(_In_ ID3D12Device* de
{
static_assert((MaxBatchSize * VerticesPerSprite) < USHRT_MAX, "MaxBatchSize too large for 16-bit indices");
CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_DEFAULT);
CD3DX12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(sizeof(short) * MaxBatchSize * IndicesPerSprite);
const CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_DEFAULT);
auto const bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(sizeof(short) * MaxBatchSize * IndicesPerSprite);
// Create the constant buffer.
ThrowIfFailed(device->CreateCommittedResource(
@ -338,17 +338,17 @@ void SpriteBatch::Impl::DeviceResources::CreateIndexBuffer(_In_ ID3D12Device* de
void SpriteBatch::Impl::DeviceResources::CreateRootSignatures(_In_ ID3D12Device* device)
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
CD3DX12_DESCRIPTOR_RANGE textureSRV(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSRV(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
{
// Same as CommonStates::StaticLinearClamp
CD3DX12_STATIC_SAMPLER_DESC sampler(
const CD3DX12_STATIC_SAMPLER_DESC sampler(
0, // register
D3D12_FILTER_MIN_MAG_MIP_LINEAR,
D3D12_TEXTURE_ADDRESS_MODE_CLAMP,
@ -375,7 +375,7 @@ void SpriteBatch::Impl::DeviceResources::CreateRootSignatures(_In_ ID3D12Device*
}
{
CD3DX12_DESCRIPTOR_RANGE textureSampler(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSampler(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
CD3DX12_ROOT_PARAMETER rootParameters[RootParameterIndex::RootParameterCount] = {};
rootParameters[RootParameterIndex::TextureSRV].InitAsDescriptorTable(1, &textureSRV, D3D12_SHADER_VISIBILITY_PIXEL);
@ -400,7 +400,7 @@ std::vector<short> SpriteBatch::Impl::DeviceResources::CreateIndexValues()
for (size_t j = 0; j < MaxBatchSize * VerticesPerSprite; j += VerticesPerSprite)
{
short i = static_cast<short>(j);
auto const i = static_cast<short>(j);
indices.push_back(i);
indices.push_back(i + 1);
@ -575,7 +575,7 @@ void XM_CALLCONV SpriteBatch::Impl::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture,
if (sourceRectangle)
{
// User specified an explicit source region.
XMVECTOR source = LoadRect(sourceRectangle);
const XMVECTOR source = LoadRect(sourceRectangle);
XMStoreFloat4A(&sprite->source, source);
@ -596,7 +596,7 @@ void XM_CALLCONV SpriteBatch::Impl::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture,
}
// Convert texture size
XMVECTOR textureSizeV = XMLoadUInt2(&textureSize);
const XMVECTOR textureSizeV = XMLoadUInt2(&textureSize);
// Store sprite parameters.
XMStoreFloat4A(&sprite->destination, dest);
@ -624,7 +624,7 @@ void XM_CALLCONV SpriteBatch::Impl::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture,
void SpriteBatch::Impl::GrowSpriteQueue()
{
// Grow by a factor of 2.
size_t newSize = std::max(InitialQueueSize, mSpriteQueueArraySize * 2);
const size_t newSize = std::max(InitialQueueSize, mSpriteQueueArraySize * 2);
// Allocate the new array.
auto newArray = std::make_unique<SpriteInfo[]>(newSize);
@ -660,7 +660,7 @@ void SpriteBatch::Impl::PrepareForRendering()
commandList->IASetIndexBuffer(&mDeviceResources->indexBufferView);
// Set the transform matrix.
XMMATRIX transformMatrix = (mRotation == DXGI_MODE_ROTATION_UNSPECIFIED)
const XMMATRIX transformMatrix = (mRotation == DXGI_MODE_ROTATION_UNSPECIFIED)
? mTransformMatrix
: (mTransformMatrix * GetViewportTransform(mRotation));
@ -684,9 +684,9 @@ void SpriteBatch::Impl::FlushBatch()
for (size_t pos = 0; pos < mSpriteQueueCount; pos++)
{
D3D12_GPU_DESCRIPTOR_HANDLE texture = mSortedSprites[pos]->texture;
const D3D12_GPU_DESCRIPTOR_HANDLE texture = mSortedSprites[pos]->texture;
assert(texture.ptr != 0);
XMVECTOR textureSize = mSortedSprites[pos]->textureSize;
const XMVECTOR textureSize = mSortedSprites[pos]->textureSize;
// Flush whenever the texture changes.
if (texture != batchTexture)
@ -768,7 +768,7 @@ void SpriteBatch::Impl::SortSprites()
// Populates the mSortedSprites vector with pointers to individual elements of the mSpriteQueue array.
void SpriteBatch::Impl::GrowSortedSprites()
{
size_t previousSize = mSortedSprites.size();
const size_t previousSize = mSortedSprites.size();
mSortedSprites.resize(mSpriteQueueCount);
@ -795,7 +795,7 @@ void SpriteBatch::Impl::RenderBatch(D3D12_GPU_DESCRIPTOR_HANDLE texture, XMVECTO
}
// Convert to vector format.
XMVECTOR inverseTextureSize = XMVectorReciprocal(textureSize);
const XMVECTOR inverseTextureSize = XMVectorReciprocal(textureSize);
while (count > 0)
{
@ -803,7 +803,7 @@ void SpriteBatch::Impl::RenderBatch(D3D12_GPU_DESCRIPTOR_HANDLE texture, XMVECTO
size_t batchSize = count;
// How many sprites does the D3D vertex buffer have room for?
size_t remainingSpace = MaxBatchSize - mSpriteCount;
const size_t remainingSpace = MaxBatchSize - mSpriteCount;
if (batchSize > remainingSpace)
{
@ -841,14 +841,14 @@ void SpriteBatch::Impl::RenderBatch(D3D12_GPU_DESCRIPTOR_HANDLE texture, XMVECTO
// Set the vertex buffer view
D3D12_VERTEX_BUFFER_VIEW vbv;
size_t spriteVertexTotalSize = sizeof(VertexPositionColorTexture) * VerticesPerSprite;
constexpr size_t spriteVertexTotalSize = sizeof(VertexPositionColorTexture) * VerticesPerSprite;
vbv.BufferLocation = mVertexSegment.GpuAddress() + (UINT64(mSpriteCount) * UINT64(spriteVertexTotalSize));
vbv.StrideInBytes = sizeof(VertexPositionColorTexture);
vbv.SizeInBytes = static_cast<UINT>(batchSize * spriteVertexTotalSize);
commandList->IASetVertexBuffers(0, 1, &vbv);
// Ok lads, the time has come for us draw ourselves some sprites!
UINT indexCount = static_cast<UINT>(batchSize * IndicesPerSprite);
const UINT indexCount = static_cast<UINT>(batchSize * IndicesPerSprite);
commandList->DrawIndexedInstanced(indexCount, 1, 0, 0, 0);
@ -867,20 +867,20 @@ void XM_CALLCONV SpriteBatch::Impl::RenderSprite(SpriteInfo const* sprite, Verte
{
// Load sprite parameters into SIMD registers.
XMVECTOR source = XMLoadFloat4A(&sprite->source);
XMVECTOR destination = XMLoadFloat4A(&sprite->destination);
XMVECTOR color = XMLoadFloat4A(&sprite->color);
XMVECTOR originRotationDepth = XMLoadFloat4A(&sprite->originRotationDepth);
const XMVECTOR destination = XMLoadFloat4A(&sprite->destination);
const XMVECTOR color = XMLoadFloat4A(&sprite->color);
const XMVECTOR originRotationDepth = XMLoadFloat4A(&sprite->originRotationDepth);
float rotation = sprite->originRotationDepth.z;
unsigned int flags = sprite->flags;
const float rotation = sprite->originRotationDepth.z;
const unsigned int flags = sprite->flags;
// Extract the source and destination sizes into separate vectors.
XMVECTOR sourceSize = XMVectorSwizzle<2, 3, 2, 3>(source);
XMVECTOR destinationSize = XMVectorSwizzle<2, 3, 2, 3>(destination);
// Scale the origin offset by source size, taking care to avoid overflow if the source region is zero.
XMVECTOR isZeroMask = XMVectorEqual(sourceSize, XMVectorZero());
XMVECTOR nonZeroSourceSize = XMVectorSelect(sourceSize, g_XMEpsilon, isZeroMask);
const XMVECTOR isZeroMask = XMVectorEqual(sourceSize, XMVectorZero());
const XMVECTOR nonZeroSourceSize = XMVectorSelect(sourceSize, g_XMEpsilon, isZeroMask);
XMVECTOR origin = XMVectorDivide(originRotationDepth, nonZeroSourceSize);
@ -911,8 +911,8 @@ void XM_CALLCONV SpriteBatch::Impl::RenderSprite(SpriteInfo const* sprite, Verte
XMScalarSinCos(&sin, &cos, rotation);
XMVECTOR sinV = XMLoadFloat(&sin);
XMVECTOR cosV = XMLoadFloat(&cos);
const XMVECTOR sinV = XMLoadFloat(&sin);
const XMVECTOR cosV = XMLoadFloat(&cos);
rotationMatrix1 = XMVectorMergeXY(cosV, sinV);
rotationMatrix2 = XMVectorMergeXY(XMVectorNegate(sinV), cosV);
@ -948,14 +948,14 @@ void XM_CALLCONV SpriteBatch::Impl::RenderSprite(SpriteInfo const* sprite, Verte
for (size_t i = 0; i < VerticesPerSprite; i++)
{
// Calculate position.
XMVECTOR cornerOffset = XMVectorMultiply(XMVectorSubtract(cornerOffsets[i], origin), destinationSize);
const XMVECTOR cornerOffset = XMVectorMultiply(XMVectorSubtract(cornerOffsets[i], origin), destinationSize);
// Apply 2x2 rotation matrix.
XMVECTOR position1 = XMVectorMultiplyAdd(XMVectorSplatX(cornerOffset), rotationMatrix1, destination);
XMVECTOR position2 = XMVectorMultiplyAdd(XMVectorSplatY(cornerOffset), rotationMatrix2, position1);
const XMVECTOR position1 = XMVectorMultiplyAdd(XMVectorSplatX(cornerOffset), rotationMatrix1, destination);
const XMVECTOR position2 = XMVectorMultiplyAdd(XMVectorSplatY(cornerOffset), rotationMatrix2, position1);
// Set z = depth.
XMVECTOR position = XMVectorPermute<0, 1, 7, 6>(position2, originRotationDepth);
const XMVECTOR position = XMVectorPermute<0, 1, 7, 6>(position2, originRotationDepth);
// Write position as a Float4, even though VertexPositionColor::position is an XMFLOAT3.
// This is faster, and harmless as we are just clobbering the first element of the
@ -966,7 +966,7 @@ void XM_CALLCONV SpriteBatch::Impl::RenderSprite(SpriteInfo const* sprite, Verte
XMStoreFloat4(&vertices[i].color, color);
// Compute and write the texture coordinate.
XMVECTOR textureCoordinate = XMVectorMultiplyAdd(cornerOffsets[static_cast<unsigned int>(i) ^ mirrorBits], sourceSize, source);
const XMVECTOR textureCoordinate = XMVectorMultiplyAdd(cornerOffsets[static_cast<unsigned int>(i) ^ mirrorBits], sourceSize, source);
XMStoreFloat2(&vertices[i].textureCoordinate, textureCoordinate);
}
@ -983,8 +983,8 @@ XMMATRIX SpriteBatch::Impl::GetViewportTransform(_In_ DXGI_MODE_ROTATION rotatio
}
// Compute the matrix.
float xScale = (mViewPort.Width > 0) ? 2.0f / mViewPort.Width : 0.0f;
float yScale = (mViewPort.Height > 0) ? 2.0f / mViewPort.Height : 0.0f;
const float xScale = (mViewPort.Width > 0) ? 2.0f / mViewPort.Width : 0.0f;
const float yScale = (mViewPort.Height > 0) ? 2.0f / mViewPort.Height : 0.0f;
switch (rotation)
{
@ -1086,7 +1086,7 @@ void XM_CALLCONV SpriteBatch::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture,
XMFLOAT2 const& position,
FXMVECTOR color)
{
XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(XMLoadFloat2(&position), g_XMOne); // x, y, 1, 1
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(XMLoadFloat2(&position), g_XMOne); // x, y, 1, 1
pImpl->Draw(texture, textureSize, destination, nullptr, color, g_XMZero, 0);
}
@ -1104,9 +1104,9 @@ void XM_CALLCONV SpriteBatch::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture,
SpriteEffects effects,
float layerDepth)
{
XMVECTOR destination = XMVectorPermute<0, 1, 4, 4>(XMLoadFloat2(&position), XMLoadFloat(&scale)); // x, y, scale, scale
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 4>(XMLoadFloat2(&position), XMLoadFloat(&scale)); // x, y, scale, scale
XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
const XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
pImpl->Draw(texture, textureSize, destination, sourceRectangle, color, originRotationDepth, static_cast<unsigned int>(effects));
}
@ -1124,9 +1124,9 @@ void XM_CALLCONV SpriteBatch::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture,
SpriteEffects effects,
float layerDepth)
{
XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(XMLoadFloat2(&position), XMLoadFloat2(&scale)); // x, y, scale.x, scale.y
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(XMLoadFloat2(&position), XMLoadFloat2(&scale)); // x, y, scale.x, scale.y
XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
const XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
pImpl->Draw(texture, textureSize, destination, sourceRectangle, color, originRotationDepth, static_cast<unsigned int>(effects));
}
@ -1134,7 +1134,7 @@ void XM_CALLCONV SpriteBatch::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture,
void XM_CALLCONV SpriteBatch::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture, XMUINT2 const& textureSize, FXMVECTOR position, FXMVECTOR color)
{
XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(position, g_XMOne); // x, y, 1, 1
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(position, g_XMOne); // x, y, 1, 1
pImpl->Draw(texture, textureSize, destination, nullptr, color, g_XMZero, 0);
}
@ -1152,11 +1152,13 @@ void XM_CALLCONV SpriteBatch::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture,
SpriteEffects effects,
float layerDepth)
{
XMVECTOR destination = XMVectorPermute<0, 1, 4, 4>(position, XMLoadFloat(&scale)); // x, y, scale, scale
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 4>(position, XMLoadFloat(&scale)); // x, y, scale, scale
XMVECTOR rotationDepth = XMVectorMergeXY(XMVectorReplicate(rotation), XMVectorReplicate(layerDepth));
const XMVECTOR rotationDepth = XMVectorMergeXY(
XMVectorReplicate(rotation),
XMVectorReplicate(layerDepth));
XMVECTOR originRotationDepth = XMVectorPermute<0, 1, 4, 5>(origin, rotationDepth);
const XMVECTOR originRotationDepth = XMVectorPermute<0, 1, 4, 5>(origin, rotationDepth);
pImpl->Draw(texture, textureSize, destination, sourceRectangle, color, originRotationDepth, static_cast<unsigned int>(effects));
}
@ -1174,11 +1176,13 @@ void XM_CALLCONV SpriteBatch::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture,
SpriteEffects effects,
float layerDepth)
{
XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(position, scale); // x, y, scale.x, scale.y
const XMVECTOR destination = XMVectorPermute<0, 1, 4, 5>(position, scale); // x, y, scale.x, scale.y
XMVECTOR rotationDepth = XMVectorMergeXY(XMVectorReplicate(rotation), XMVectorReplicate(layerDepth));
const XMVECTOR rotationDepth = XMVectorMergeXY(
XMVectorReplicate(rotation),
XMVectorReplicate(layerDepth));
XMVECTOR originRotationDepth = XMVectorPermute<0, 1, 4, 5>(origin, rotationDepth);
const XMVECTOR originRotationDepth = XMVectorPermute<0, 1, 4, 5>(origin, rotationDepth);
pImpl->Draw(texture, textureSize, destination, sourceRectangle, color, originRotationDepth, static_cast<unsigned int>(effects));
}
@ -1189,7 +1193,7 @@ void XM_CALLCONV SpriteBatch::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture,
RECT const& destinationRectangle,
FXMVECTOR color)
{
XMVECTOR destination = LoadRect(&destinationRectangle); // x, y, w, h
const XMVECTOR destination = LoadRect(&destinationRectangle); // x, y, w, h
pImpl->Draw(texture, textureSize, destination, nullptr, color, g_XMZero, Impl::SpriteInfo::DestSizeInPixels);
}
@ -1206,9 +1210,9 @@ void XM_CALLCONV SpriteBatch::Draw(D3D12_GPU_DESCRIPTOR_HANDLE texture,
SpriteEffects effects,
float layerDepth)
{
XMVECTOR destination = LoadRect(&destinationRectangle); // x, y, w, h
const XMVECTOR destination = LoadRect(&destinationRectangle); // x, y, w, h
XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
const XMVECTOR originRotationDepth = XMVectorSet(origin.x, origin.y, rotation, layerDepth);
pImpl->Draw(texture, textureSize, destination, sourceRectangle, color, originRotationDepth, static_cast<unsigned int>(effects) | Impl::SpriteInfo::DestSizeInPixels);
}

Просмотреть файл

@ -145,7 +145,7 @@ SpriteFont::Impl::Impl(
auto textureStride = reader->Read<uint32_t>();
auto textureRows = reader->Read<uint32_t>();
uint64_t dataSize = uint64_t(textureStride) * uint64_t(textureRows);
const uint64_t dataSize = uint64_t(textureStride) * uint64_t(textureRows);
if (dataSize > UINT32_MAX)
{
DebugTrace("ERROR: SpriteFont provided with an invalid .spritefont file\n");
@ -277,7 +277,7 @@ void SpriteFont::Impl::ForEachGlyph(_In_z_ wchar_t const* text, TAction action,
for (; *text; text++)
{
wchar_t character = *text;
const wchar_t character = *text;
switch (character)
{
@ -300,7 +300,7 @@ void SpriteFont::Impl::ForEachGlyph(_In_z_ wchar_t const* text, TAction action,
if (x < 0)
x = 0;
float advance = float(glyph->Subrect.right) - float(glyph->Subrect.left) + glyph->XAdvance;
const float advance = float(glyph->Subrect.right) - float(glyph->Subrect.left) + glyph->XAdvance;
if (!ignoreWhitespace
|| !iswspace(character)
@ -326,7 +326,7 @@ void SpriteFont::Impl::CreateTextureResource(
uint32_t stride, uint32_t rows,
const uint8_t* data) noexcept(false)
{
uint64_t sliceBytes = uint64_t(stride) * uint64_t(rows);
const uint64_t sliceBytes = uint64_t(stride) * uint64_t(rows);
if (sliceBytes > UINT32_MAX)
{
DebugTrace("ERROR: SpriteFont provided with an invalid .spritefont file\n");
@ -342,7 +342,7 @@ void SpriteFont::Impl::CreateTextureResource(
desc.Format = format;
desc.SampleDesc.Count = 1;
CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
ThrowIfFailed(device->CreateCommittedResource(
&defaultHeapProperties,
@ -515,7 +515,7 @@ XMVECTOR XM_CALLCONV SpriteFont::MeasureString(_In_z_ wchar_t const* text, bool
{
UNREFERENCED_PARAMETER(advance);
auto w = static_cast<float>(glyph->Subrect.right - glyph->Subrect.left);
auto const w = static_cast<float>(glyph->Subrect.right - glyph->Subrect.left);
auto h = static_cast<float>(glyph->Subrect.bottom - glyph->Subrect.top) + glyph->YOffset;
h = iswspace(wchar_t(glyph->Character)) ?
@ -535,17 +535,17 @@ RECT SpriteFont::MeasureDrawBounds(_In_z_ wchar_t const* text, XMFLOAT2 const& p
pImpl->ForEachGlyph(text, [&](Glyph const* glyph, float x, float y, float advance) noexcept
{
auto isWhitespace = iswspace(wchar_t(glyph->Character));
auto w = static_cast<float>(glyph->Subrect.right - glyph->Subrect.left);
auto h = isWhitespace ?
auto const isWhitespace = iswspace(wchar_t(glyph->Character));
auto const w = static_cast<float>(glyph->Subrect.right - glyph->Subrect.left);
auto const h = isWhitespace ?
pImpl->lineSpacing :
static_cast<float>(glyph->Subrect.bottom - glyph->Subrect.top);
float minX = position.x + x;
float minY = position.y + y + (isWhitespace ? 0.0f : glyph->YOffset);
const float minX = position.x + x;
const float minY = position.y + y + (isWhitespace ? 0.0f : glyph->YOffset);
float maxX = std::max(minX + advance, minX + w);
float maxY = minY + h;
const float maxX = std::max(minX + advance, minX + w);
const float maxY = minY + h;
if (minX < float(result.left))
result.left = long(minX);

Просмотреть файл

@ -308,16 +308,16 @@ ToneMapPostProcess::Impl::Impl(_In_ ID3D12Device* device, const RenderTargetStat
// Create root signature.
{
D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
constexpr D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS
| D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
CD3DX12_DESCRIPTOR_RANGE textureSRVs(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE textureSRVs(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
// Same as CommonStates::StaticPointClamp
CD3DX12_STATIC_SAMPLER_DESC sampler(
const CD3DX12_STATIC_SAMPLER_DESC sampler(
0, // register
D3D12_FILTER_MIN_MAG_MIP_POINT,
D3D12_TEXTURE_ADDRESS_MODE_CLAMP,
@ -333,7 +333,7 @@ ToneMapPostProcess::Impl::Impl(_In_ ID3D12Device* device, const RenderTargetStat
CD3DX12_ROOT_PARAMETER rootParameters[RootParameterIndex::RootParameterCount] = {};
CD3DX12_DESCRIPTOR_RANGE texture1Range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
const CD3DX12_DESCRIPTOR_RANGE texture1Range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
rootParameters[RootParameterIndex::TextureSRV].InitAsDescriptorTable(1, &textureSRVs, D3D12_SHADER_VISIBILITY_PIXEL);
// Root parameter descriptor
@ -355,18 +355,18 @@ ToneMapPostProcess::Impl::Impl(_In_ ID3D12Device* device, const RenderTargetStat
permutation += (static_cast<int>(func) * static_cast<int>(Operator_Max)) + static_cast<int>(op);
#else
UNREFERENCED_PARAMETER(mrt);
int permutation = (static_cast<int>(func) * static_cast<int>(Operator_Max)) + static_cast<int>(op);
const int permutation = (static_cast<int>(func) * static_cast<int>(Operator_Max)) + static_cast<int>(op);
#endif
assert(permutation >= 0 && permutation < ShaderPermutationCount);
_Analysis_assume_(permutation >= 0 && permutation < ShaderPermutationCount);
int shaderIndex = pixelShaderIndices[permutation];
const int shaderIndex = pixelShaderIndices[permutation];
assert(shaderIndex >= 0 && shaderIndex < PixelShaderCount);
_Analysis_assume_(shaderIndex >= 0 && shaderIndex < PixelShaderCount);
// Create pipeline state.
EffectPipelineStateDescription psd(nullptr,
const EffectPipelineStateDescription psd(nullptr,
CommonStates::Opaque,
CommonStates::DepthNone,
CommonStates::CullNone,
@ -472,7 +472,7 @@ void ToneMapPostProcess::SetColorRotation(ColorPrimaryRotation value)
void ToneMapPostProcess::SetColorRotation(CXMMATRIX value)
{
XMMATRIX transpose = XMMatrixTranspose(value);
const XMMATRIX transpose = XMMatrixTranspose(value);
pImpl->constants.colorRotation[0] = transpose.r[0];
pImpl->constants.colorRotation[1] = transpose.r[1];
pImpl->constants.colorRotation[2] = transpose.r[2];

Просмотреть файл

@ -256,7 +256,7 @@ namespace
}
else if (width > maxsize || height > maxsize)
{
float ar = static_cast<float>(height) / static_cast<float>(width);
const float ar = static_cast<float>(height) / static_cast<float>(width);
if (width > height)
{
twidth = static_cast<UINT>(maxsize);
@ -405,14 +405,14 @@ namespace
}
// Allocate memory for decoded image
uint64_t rowBytes = (uint64_t(twidth) * uint64_t(bpp) + 7u) / 8u;
uint64_t numBytes = rowBytes * uint64_t(theight);
const uint64_t rowBytes = (uint64_t(twidth) * uint64_t(bpp) + 7u) / 8u;
const uint64_t numBytes = rowBytes * uint64_t(theight);
if (rowBytes > UINT32_MAX || numBytes > UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
auto rowPitch = static_cast<size_t>(rowBytes);
auto imageSize = static_cast<size_t>(numBytes);
auto const rowPitch = static_cast<size_t>(rowBytes);
auto const imageSize = static_cast<size_t>(numBytes);
decodedData.reset(new (std::nothrow) uint8_t[imageSize]);
if (!decodedData)
@ -508,7 +508,7 @@ namespace
}
// Count the number of mips
uint32_t mipCount = (loadFlags & (WIC_LOADER_MIP_AUTOGEN | WIC_LOADER_MIP_RESERVE))
const uint32_t mipCount = (loadFlags & (WIC_LOADER_MIP_AUTOGEN | WIC_LOADER_MIP_RESERVE))
? LoaderHelpers::CountMips(twidth, theight) : 1u;
// Create texture
@ -523,7 +523,7 @@ namespace
desc.Flags = resFlags;
desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
const CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
ID3D12Resource* tex = nullptr;
hr = d3dDevice->CreateCommittedResource(
@ -582,7 +582,7 @@ namespace
if (FAILED(frame->GetPixelFormat(&pixelFormat)))
return DXGI_FORMAT_UNKNOWN;
DXGI_FORMAT format = WICToDXGI(pixelFormat);
const DXGI_FORMAT format = WICToDXGI(pixelFormat);
if (format == DXGI_FORMAT_UNKNOWN)
{
for (size_t i = 0; i < std::size(g_WICConvert); ++i)
@ -761,7 +761,7 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx(
if (loadFlags & WIC_LOADER_MIP_AUTOGEN)
{
DXGI_FORMAT fmt = GetPixelFormat(frame.Get());
const DXGI_FORMAT fmt = GetPixelFormat(frame.Get());
if (!resourceUpload.IsSupportedForGenerateMips(fmt))
{
DebugTrace("WARNING: Autogen of mips ignored (device doesn't support this format (%d) or trying to use a copy queue)\n", static_cast<int>(fmt));
@ -935,7 +935,7 @@ HRESULT DirectX::CreateWICTextureFromFileEx(
if (loadFlags & WIC_LOADER_MIP_AUTOGEN)
{
DXGI_FORMAT fmt = GetPixelFormat(frame.Get());
const DXGI_FORMAT fmt = GetPixelFormat(frame.Get());
if (!resourceUpload.IsSupportedForGenerateMips(fmt))
{
DebugTrace("WARNING: Autogen of mips ignored (device doesn't support this format (%d) or trying to use a copy queue)\n", static_cast<int>(fmt));

Просмотреть файл

@ -2101,8 +2101,8 @@ inline UINT64 UpdateSubresources(
{
for (UINT i = 0; i < NumSubresources; ++i)
{
CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);
CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
const CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);
const CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
}
}
@ -2160,8 +2160,8 @@ inline UINT64 UpdateSubresources(
{
for (UINT i = 0; i < NumSubresources; ++i)
{
CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);
CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
const CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);
const CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
}
}
@ -2404,7 +2404,7 @@ inline HRESULT D3DX12SerializeVersionedRootSignature(
if (SUCCEEDED(hr))
{
CD3DX12_ROOT_SIGNATURE_DESC desc_1_0(desc_1_1.NumParameters, pParameters_1_0, desc_1_1.NumStaticSamplers, desc_1_1.pStaticSamplers, desc_1_1.Flags);
const CD3DX12_ROOT_SIGNATURE_DESC desc_1_0(desc_1_1.NumParameters, pParameters_1_0, desc_1_1.NumStaticSamplers, desc_1_1.pStaticSamplers, desc_1_1.Flags);
hr = D3D12SerializeRootSignature(&desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob);
}