ID3D11DeviceCoNtext1::P SSetConstantBuffers1 方法 (d3d11_1.h)

設定圖元著色器管線階段使用的常數緩衝區,並讓著色器存取緩衝區的其他部分。

語法

void PSSetConstantBuffers1(
  [in]           UINT         StartSlot,
  [in]           UINT         NumBuffers,
  [in, optional] ID3D11Buffer * const *ppConstantBuffers,
  [in, optional] const UINT   *pFirstConstant,
  [in, optional] const UINT   *pNumConstants
);

參數

[in] StartSlot

類型: UINT

索引到裝置的以零起始的陣列,開始將常數緩衝區設定為 (從 0 到 D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - 1) 的範圍。

[in] NumBuffers

類型: UINT

要設定 (範圍從 0 到 D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT 的緩衝區數目 - StartSlot) 。

[in, optional] ppConstantBuffers

類型: ID3D11Buffer*

提供給裝置的常數緩衝區陣列。

[in, optional] pFirstConstant

類型:const UINT*

陣列,保存 ppConstantBuffers 所指定之緩衝區中的位移。 每個位移都會指定從著色器的觀點開始每個常數緩衝區的位置。 每個位移都是以著色器常數測量,這些常數是 16 個位元組, (4*32 位元件) 。 因此,位移為 16 表示相關聯常數緩衝區的開頭是常數緩衝區的 256 個位元組。 每個位移都必須是 16 個常數的倍數。

[in, optional] pNumConstants

類型:const UINT*

陣列,保存 ppConstantBuffers 所指定之緩衝區中的常數數目。 每個數位都會指定著色器使用之常數緩衝區中包含的常數數目。 每個常數數目都會從 pFirstConstant 陣列中指定的個別位移開始。 每個常數數目都必須是範圍 [0..4096] 中 16 個常數的倍數。

傳回值

備註

若要讓著色器存取緩衝區的其他部分,請呼叫 PSSetConstantBuffers1 ,而不是 PSSetConstantBuffersPSSetConstantBuffers1 具有其他參數 pFirstConstantpNumConstants

如果pNumConstants點的常數數目大於著色器所支援的最大常數緩衝區大小,執行時間就會卸載對 PSSetConstantBuffers1的呼叫。 著色器支援的常數緩衝區大小上限會保留 4096 個常數,其中每個常數都有四個 32 位元件。

pFirstConstConstantpFirstConstant + pNumConstants陣列元素中的值可能超過每個緩衝區的長度;從著色器的觀點來看,常數緩衝區是緩衝區的實際記憶體配置交集,而下列視窗 (範圍) :

[ pFirstConstant元素中的 value, value in an element of pFirstConstant + value in an element of pNumConstants]

也就是說,視窗是從pFirstConstant元素中的 (值) 到pNumConstants 元素中 pFirstConstant + value 元素中的 (值) 。

執行時間也會在不支援此位移的現有驅動程式上卸載 對 PSSetConstantBuffers1 的呼叫。

執行時間會針對 功能層級 9.1、9.2 和 9.3 模擬此功能;因此,此功能支援功能層級 9.1、9.2 和 9.3。 此功能一律適用于功能層級 10 和更新版本的新驅動程式。

從著色器的觀點來看,常數緩衝區陣列中的元素 [0] 是 pFirstConstant的常數。

從著色器到 pFirstConstant 所定義的範圍,而 pNumConstants 會傳回 0 的界限外存取常數緩衝區。

如果 pFirstConstantpNumConstants 陣列是 Null,您會收到與將整個緩衝區系結至檢視時相同的結果。 如果您呼叫 PSSetConstantBuffers 方法,就會得到相同的結果。 如果緩衝區大於著色器所支援的常數緩衝區大小上限, (4096 個元素) ,著色器只能存取前 4096 個常數。

如果 pFirstConstantpNumConstantsNull,則另一個參數也必須是 Null

使用命令清單模擬呼叫 PSSetConstantBuffers1

執行時間的PSSetConstantBuffers1命令清單模擬有時不會實際變更常數緩衝區陣列的位移或大小。 當 PSSetConstantBuffers1 不會有效地變更您設定為更新之位置範圍的開頭和結尾的常數緩衝區時,就會發生此行為。 本節說明如何解決此行為。

以下是用來檢查執行時間模擬命令清單或驅動程式是否支援命令清單的程式碼:


     HRESULT hr = S_OK;
     bool needWorkaround = false;
     D3D11_DEVICE_CONTEXT_TYPE contextType = pDeviceContext->GetType();

     if( D3D11_DEVICE_CONTEXT_DEFERRED == contextType)
     {
          D3D11_FEATURE_DATA_THREADING threadingCaps = { FALSE, FALSE };

          hr = pDevice->CheckFeatureSupport( D3D11_FEATURE_THREADING, &threadingCaps, sizeof(threadingCaps) );
          if( SUCCEEDED(hr) && !threadingCaps.DriverCommandLists )
          {
               needWorkaround = true; // the runtime emulates command lists.
          }
     }

如果執行時間模擬命令清單,您必須使用下列其中一個程式碼片段:

如果您只變更單一常數緩衝區上的位移和大小,請先將常數緩衝區設定為 Null


     pDeviceContext->PSSetConstantBuffers1(0, 1, &CBuf, &Offset, &Count);
     if( needWorkaround )
     {
          // Workaround for command list emulation
          pDeviceContext->PSSetConstantBuffers(0, 1, &NullCBuf);
     }
     pDeviceContext->PSSetConstantBuffers1(0, 1, &CBuf, &Offset, &Count);

如果您變更多個常數緩衝區,請先將範圍的第一個和最後一個常數緩衝區設定為 Null


     pDeviceContext->PSSetConstantBuffers1(0, 4, &CBufs, &Offsets, &Counts);
     if( needWorkaround )
     {
          // Workaround for command list emulation
          pDeviceContext->PSSetConstantBuffers(0, 1, &NullCBuf);
          pDeviceContext->PSSetConstantBuffers(3, 1, &NullCBuf);
     }
     pDeviceContext->PSSetConstantBuffers1(0, 4, &CBufs, &Offsets, &Counts);

規格需求

   
最低支援的用戶端 適用于 Windows 7 的 Windows 8 和平臺更新 [傳統型應用程式 |UWP 應用程式]
最低支援的伺服器 適用于 Windows Server 2008 R2 的 Windows Server 2012 和平臺更新 [傳統型應用程式 |UWP 應用程式]
目標平台 Windows
標頭 d3d11_1.h
程式庫 D3D11.lib

另請參閱

ID3D11DeviceContext1