2015-08-17 16:17:07 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2015 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
#include "anv_private.h"
|
|
|
|
|
|
2016-02-20 09:08:27 -08:00
|
|
|
#include "genxml/gen_macros.h"
|
|
|
|
|
#include "genxml/genX_pack.h"
|
2019-06-19 16:04:54 -05:00
|
|
|
#include "common/gen_guardband.h"
|
2015-11-16 12:29:07 -08:00
|
|
|
|
2016-02-20 09:08:27 -08:00
|
|
|
#if GEN_GEN == 8
|
2016-03-30 17:13:01 -07:00
|
|
|
void
|
|
|
|
|
gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer)
|
2015-11-16 12:10:11 -08:00
|
|
|
{
|
2019-06-19 16:04:54 -05:00
|
|
|
struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;
|
2017-12-15 16:48:53 -08:00
|
|
|
uint32_t count = cmd_buffer->state.gfx.dynamic.viewport.count;
|
|
|
|
|
const VkViewport *viewports =
|
|
|
|
|
cmd_buffer->state.gfx.dynamic.viewport.viewports;
|
2015-11-16 12:10:11 -08:00
|
|
|
struct anv_state sf_clip_state =
|
|
|
|
|
anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, count * 64, 64);
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
|
|
|
const VkViewport *vp = &viewports[i];
|
|
|
|
|
|
|
|
|
|
/* The gen7 state struct has just the matrix and guardband fields, the
|
|
|
|
|
* gen8 struct adds the min/max viewport fields. */
|
2019-06-19 16:04:54 -05:00
|
|
|
struct GENX(SF_CLIP_VIEWPORT) sfv = {
|
2015-11-16 12:10:11 -08:00
|
|
|
.ViewportMatrixElementm00 = vp->width / 2,
|
|
|
|
|
.ViewportMatrixElementm11 = vp->height / 2,
|
2017-09-15 10:05:03 +02:00
|
|
|
.ViewportMatrixElementm22 = vp->maxDepth - vp->minDepth,
|
2015-11-30 17:26:32 -08:00
|
|
|
.ViewportMatrixElementm30 = vp->x + vp->width / 2,
|
|
|
|
|
.ViewportMatrixElementm31 = vp->y + vp->height / 2,
|
2017-09-15 10:05:03 +02:00
|
|
|
.ViewportMatrixElementm32 = vp->minDepth,
|
2015-11-16 12:10:11 -08:00
|
|
|
.XMinClipGuardband = -1.0f,
|
|
|
|
|
.XMaxClipGuardband = 1.0f,
|
|
|
|
|
.YMinClipGuardband = -1.0f,
|
|
|
|
|
.YMaxClipGuardband = 1.0f,
|
2015-11-30 17:26:32 -08:00
|
|
|
.XMinViewPort = vp->x,
|
|
|
|
|
.XMaxViewPort = vp->x + vp->width - 1,
|
2017-01-20 17:30:51 -08:00
|
|
|
.YMinViewPort = MIN2(vp->y, vp->y + vp->height),
|
|
|
|
|
.YMaxViewPort = MAX2(vp->y, vp->y + vp->height) - 1,
|
2015-11-16 12:10:11 -08:00
|
|
|
};
|
|
|
|
|
|
2019-06-19 16:04:54 -05:00
|
|
|
if (fb) {
|
|
|
|
|
/* We can only calculate a "real" guardband clip if we know the
|
|
|
|
|
* framebuffer at the time we emit the packet. Otherwise, we have
|
|
|
|
|
* fall back to a worst-case guardband of [-1, 1].
|
|
|
|
|
*/
|
|
|
|
|
gen_calculate_guardband_size(fb->width, fb->height,
|
|
|
|
|
sfv.ViewportMatrixElementm00,
|
|
|
|
|
sfv.ViewportMatrixElementm11,
|
|
|
|
|
sfv.ViewportMatrixElementm30,
|
|
|
|
|
sfv.ViewportMatrixElementm31,
|
|
|
|
|
&sfv.XMinClipGuardband,
|
|
|
|
|
&sfv.XMaxClipGuardband,
|
|
|
|
|
&sfv.YMinClipGuardband,
|
|
|
|
|
&sfv.YMaxClipGuardband);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GENX(SF_CLIP_VIEWPORT_pack)(NULL, sf_clip_state.map + i * 64, &sfv);
|
2016-06-14 08:15:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
anv_batch_emit(&cmd_buffer->batch,
|
|
|
|
|
GENX(3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP), clip) {
|
|
|
|
|
clip.SFClipViewportPointer = sf_clip_state.offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2016-06-14 08:40:49 -07:00
|
|
|
gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer *cmd_buffer,
|
|
|
|
|
bool depth_clamp_enable)
|
2016-06-14 08:15:34 -07:00
|
|
|
{
|
2017-12-15 16:48:53 -08:00
|
|
|
uint32_t count = cmd_buffer->state.gfx.dynamic.viewport.count;
|
|
|
|
|
const VkViewport *viewports =
|
|
|
|
|
cmd_buffer->state.gfx.dynamic.viewport.viewports;
|
2016-06-14 08:15:34 -07:00
|
|
|
struct anv_state cc_state =
|
|
|
|
|
anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, count * 8, 32);
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
|
|
|
const VkViewport *vp = &viewports[i];
|
|
|
|
|
|
2020-07-07 11:08:31 -05:00
|
|
|
/* From the Vulkan spec:
|
|
|
|
|
*
|
|
|
|
|
* "It is valid for minDepth to be greater than or equal to
|
|
|
|
|
* maxDepth."
|
|
|
|
|
*/
|
|
|
|
|
float min_depth = MIN2(vp->minDepth, vp->maxDepth);
|
|
|
|
|
float max_depth = MAX2(vp->minDepth, vp->maxDepth);
|
|
|
|
|
|
2015-11-25 22:27:01 -08:00
|
|
|
struct GENX(CC_VIEWPORT) cc_viewport = {
|
2020-07-07 11:08:31 -05:00
|
|
|
.MinimumDepth = depth_clamp_enable ? min_depth : 0.0f,
|
|
|
|
|
.MaximumDepth = depth_clamp_enable ? max_depth : 1.0f,
|
2015-11-16 12:10:11 -08:00
|
|
|
};
|
|
|
|
|
|
2016-01-11 12:27:51 -08:00
|
|
|
GENX(CC_VIEWPORT_pack)(NULL, cc_state.map + i * 8, &cc_viewport);
|
2015-11-16 12:10:11 -08:00
|
|
|
}
|
|
|
|
|
|
2016-04-18 17:03:00 -07:00
|
|
|
anv_batch_emit(&cmd_buffer->batch,
|
|
|
|
|
GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC), cc) {
|
2016-04-18 16:08:49 -07:00
|
|
|
cc.CCViewportPointer = cc_state.offset;
|
|
|
|
|
}
|
2015-11-16 12:10:11 -08:00
|
|
|
}
|
2015-11-25 22:27:01 -08:00
|
|
|
#endif
|
2015-11-16 12:10:11 -08:00
|
|
|
|
2016-12-06 17:52:14 -08:00
|
|
|
void
|
|
|
|
|
genX(cmd_buffer_enable_pma_fix)(struct anv_cmd_buffer *cmd_buffer, bool enable)
|
|
|
|
|
{
|
|
|
|
|
if (cmd_buffer->state.pma_fix_enabled == enable)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-02-01 16:41:04 -08:00
|
|
|
cmd_buffer->state.pma_fix_enabled = enable;
|
|
|
|
|
|
|
|
|
|
/* According to the Broadwell PIPE_CONTROL documentation, software should
|
|
|
|
|
* emit a PIPE_CONTROL with the CS Stall and Depth Cache Flush bits set
|
|
|
|
|
* prior to the LRI. If stencil buffer writes are enabled, then a Render
|
|
|
|
|
* Cache Flush is also necessary.
|
|
|
|
|
*
|
|
|
|
|
* The Skylake docs say to use a depth stall rather than a command
|
|
|
|
|
* streamer stall. However, the hardware seems to violently disagree.
|
|
|
|
|
* A full command streamer stall seems to be needed in both cases.
|
|
|
|
|
*/
|
2016-12-06 17:52:14 -08:00
|
|
|
anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
|
|
|
|
|
pc.DepthCacheFlushEnable = true;
|
|
|
|
|
pc.CommandStreamerStallEnable = true;
|
|
|
|
|
pc.RenderTargetCacheFlushEnable = true;
|
2019-04-30 13:34:20 -07:00
|
|
|
#if GEN_GEN >= 12
|
|
|
|
|
pc.TileCacheFlushEnable = true;
|
2020-01-14 10:03:21 +02:00
|
|
|
|
|
|
|
|
/* GEN:BUG:1409600907: "PIPE_CONTROL with Depth Stall Enable bit must
|
|
|
|
|
* be set with any PIPE_CONTROL with Depth Flush Enable bit set.
|
|
|
|
|
*/
|
|
|
|
|
pc.DepthStallEnable = true;
|
2019-04-30 13:34:20 -07:00
|
|
|
#endif
|
2016-12-06 17:52:14 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-01 16:41:04 -08:00
|
|
|
#if GEN_GEN == 9
|
|
|
|
|
|
|
|
|
|
uint32_t cache_mode;
|
|
|
|
|
anv_pack_struct(&cache_mode, GENX(CACHE_MODE_0),
|
|
|
|
|
.STCPMAOptimizationEnable = enable,
|
|
|
|
|
.STCPMAOptimizationEnableMask = true);
|
|
|
|
|
anv_batch_emit(&cmd_buffer->batch, GENX(MI_LOAD_REGISTER_IMM), lri) {
|
|
|
|
|
lri.RegisterOffset = GENX(CACHE_MODE_0_num);
|
|
|
|
|
lri.DataDWord = cache_mode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#elif GEN_GEN == 8
|
|
|
|
|
|
2016-12-06 17:52:14 -08:00
|
|
|
uint32_t cache_mode;
|
|
|
|
|
anv_pack_struct(&cache_mode, GENX(CACHE_MODE_1),
|
|
|
|
|
.NPPMAFixEnable = enable,
|
|
|
|
|
.NPEarlyZFailsDisable = enable,
|
|
|
|
|
.NPPMAFixEnableMask = true,
|
|
|
|
|
.NPEarlyZFailsDisableMask = true);
|
|
|
|
|
anv_batch_emit(&cmd_buffer->batch, GENX(MI_LOAD_REGISTER_IMM), lri) {
|
|
|
|
|
lri.RegisterOffset = GENX(CACHE_MODE_1_num);
|
|
|
|
|
lri.DataDWord = cache_mode;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 16:41:04 -08:00
|
|
|
#endif /* GEN_GEN == 8 */
|
|
|
|
|
|
2016-12-06 17:52:14 -08:00
|
|
|
/* After the LRI, a PIPE_CONTROL with both the Depth Stall and Depth Cache
|
|
|
|
|
* Flush bits is often necessary. We do it regardless because it's easier.
|
|
|
|
|
* The render cache flush is also necessary if stencil writes are enabled.
|
2017-02-01 16:41:04 -08:00
|
|
|
*
|
|
|
|
|
* Again, the Skylake docs give a different set of flushes but the BDW
|
|
|
|
|
* flushes seem to work just as well.
|
2016-12-06 17:52:14 -08:00
|
|
|
*/
|
|
|
|
|
anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), pc) {
|
|
|
|
|
pc.DepthStallEnable = true;
|
|
|
|
|
pc.DepthCacheFlushEnable = true;
|
|
|
|
|
pc.RenderTargetCacheFlushEnable = true;
|
2019-04-30 13:34:20 -07:00
|
|
|
#if GEN_GEN >= 12
|
|
|
|
|
pc.TileCacheFlushEnable = true;
|
|
|
|
|
#endif
|
2016-12-06 17:52:14 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-25 20:40:01 -07:00
|
|
|
UNUSED static bool
|
2016-12-06 17:52:14 -08:00
|
|
|
want_depth_pma_fix(struct anv_cmd_buffer *cmd_buffer)
|
|
|
|
|
{
|
|
|
|
|
assert(GEN_GEN == 8);
|
|
|
|
|
|
|
|
|
|
/* From the Broadwell PRM Vol. 2c CACHE_MODE_1::NP_PMA_FIX_ENABLE:
|
|
|
|
|
*
|
|
|
|
|
* SW must set this bit in order to enable this fix when following
|
|
|
|
|
* expression is TRUE.
|
|
|
|
|
*
|
|
|
|
|
* 3DSTATE_WM::ForceThreadDispatch != 1 &&
|
|
|
|
|
* !(3DSTATE_RASTER::ForceSampleCount != NUMRASTSAMPLES_0) &&
|
|
|
|
|
* (3DSTATE_DEPTH_BUFFER::SURFACE_TYPE != NULL) &&
|
|
|
|
|
* (3DSTATE_DEPTH_BUFFER::HIZ Enable) &&
|
|
|
|
|
* !(3DSTATE_WM::EDSC_Mode == EDSC_PREPS) &&
|
|
|
|
|
* (3DSTATE_PS_EXTRA::PixelShaderValid) &&
|
|
|
|
|
* !(3DSTATE_WM_HZ_OP::DepthBufferClear ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::DepthBufferResolve ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::Hierarchical Depth Buffer Resolve Enable ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::StencilBufferClear) &&
|
|
|
|
|
* (3DSTATE_WM_DEPTH_STENCIL::DepthTestEnable) &&
|
|
|
|
|
* (((3DSTATE_PS_EXTRA::PixelShaderKillsPixels ||
|
|
|
|
|
* 3DSTATE_PS_EXTRA::oMask Present to RenderTarget ||
|
|
|
|
|
* 3DSTATE_PS_BLEND::AlphaToCoverageEnable ||
|
|
|
|
|
* 3DSTATE_PS_BLEND::AlphaTestEnable ||
|
|
|
|
|
* 3DSTATE_WM_CHROMAKEY::ChromaKeyKillEnable) &&
|
|
|
|
|
* 3DSTATE_WM::ForceKillPix != ForceOff &&
|
|
|
|
|
* ((3DSTATE_WM_DEPTH_STENCIL::DepthWriteEnable &&
|
|
|
|
|
* 3DSTATE_DEPTH_BUFFER::DEPTH_WRITE_ENABLE) ||
|
|
|
|
|
* (3DSTATE_WM_DEPTH_STENCIL::Stencil Buffer Write Enable &&
|
|
|
|
|
* 3DSTATE_DEPTH_BUFFER::STENCIL_WRITE_ENABLE &&
|
|
|
|
|
* 3DSTATE_STENCIL_BUFFER::STENCIL_BUFFER_ENABLE))) ||
|
|
|
|
|
* (3DSTATE_PS_EXTRA:: Pixel Shader Computed Depth mode != PSCDEPTH_OFF))
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* These are always true:
|
|
|
|
|
* 3DSTATE_WM::ForceThreadDispatch != 1 &&
|
|
|
|
|
* !(3DSTATE_RASTER::ForceSampleCount != NUMRASTSAMPLES_0)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* We only enable the PMA fix if we know for certain that HiZ is enabled.
|
|
|
|
|
* If we don't know whether HiZ is enabled or not, we disable the PMA fix
|
|
|
|
|
* and there is no harm.
|
|
|
|
|
*
|
|
|
|
|
* (3DSTATE_DEPTH_BUFFER::SURFACE_TYPE != NULL) &&
|
|
|
|
|
* 3DSTATE_DEPTH_BUFFER::HIZ Enable
|
|
|
|
|
*/
|
|
|
|
|
if (!cmd_buffer->state.hiz_enabled)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* 3DSTATE_PS_EXTRA::PixelShaderValid */
|
2020-03-03 15:31:50 -08:00
|
|
|
struct anv_graphics_pipeline *pipeline = cmd_buffer->state.gfx.pipeline;
|
2016-12-06 17:52:14 -08:00
|
|
|
if (!anv_pipeline_has_stage(pipeline, MESA_SHADER_FRAGMENT))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* !(3DSTATE_WM::EDSC_Mode == EDSC_PREPS) */
|
|
|
|
|
const struct brw_wm_prog_data *wm_prog_data = get_wm_prog_data(pipeline);
|
|
|
|
|
if (wm_prog_data->early_fragment_tests)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* We never use anv_pipeline for HiZ ops so this is trivially true:
|
|
|
|
|
* !(3DSTATE_WM_HZ_OP::DepthBufferClear ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::DepthBufferResolve ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::Hierarchical Depth Buffer Resolve Enable ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::StencilBufferClear)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* 3DSTATE_WM_DEPTH_STENCIL::DepthTestEnable */
|
|
|
|
|
if (!pipeline->depth_test_enable)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* (((3DSTATE_PS_EXTRA::PixelShaderKillsPixels ||
|
|
|
|
|
* 3DSTATE_PS_EXTRA::oMask Present to RenderTarget ||
|
|
|
|
|
* 3DSTATE_PS_BLEND::AlphaToCoverageEnable ||
|
|
|
|
|
* 3DSTATE_PS_BLEND::AlphaTestEnable ||
|
|
|
|
|
* 3DSTATE_WM_CHROMAKEY::ChromaKeyKillEnable) &&
|
|
|
|
|
* 3DSTATE_WM::ForceKillPix != ForceOff &&
|
|
|
|
|
* ((3DSTATE_WM_DEPTH_STENCIL::DepthWriteEnable &&
|
|
|
|
|
* 3DSTATE_DEPTH_BUFFER::DEPTH_WRITE_ENABLE) ||
|
|
|
|
|
* (3DSTATE_WM_DEPTH_STENCIL::Stencil Buffer Write Enable &&
|
|
|
|
|
* 3DSTATE_DEPTH_BUFFER::STENCIL_WRITE_ENABLE &&
|
|
|
|
|
* 3DSTATE_STENCIL_BUFFER::STENCIL_BUFFER_ENABLE))) ||
|
|
|
|
|
* (3DSTATE_PS_EXTRA:: Pixel Shader Computed Depth mode != PSCDEPTH_OFF))
|
|
|
|
|
*/
|
|
|
|
|
return (pipeline->kill_pixel && (pipeline->writes_depth ||
|
|
|
|
|
pipeline->writes_stencil)) ||
|
|
|
|
|
wm_prog_data->computed_depth_mode != PSCDEPTH_OFF;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-25 20:40:01 -07:00
|
|
|
UNUSED static bool
|
2017-02-01 16:41:04 -08:00
|
|
|
want_stencil_pma_fix(struct anv_cmd_buffer *cmd_buffer)
|
|
|
|
|
{
|
2017-10-20 18:28:48 +01:00
|
|
|
if (GEN_GEN > 9)
|
|
|
|
|
return false;
|
2017-02-01 16:41:04 -08:00
|
|
|
assert(GEN_GEN == 9);
|
|
|
|
|
|
|
|
|
|
/* From the Skylake PRM Vol. 2c CACHE_MODE_1::STC PMA Optimization Enable:
|
|
|
|
|
*
|
|
|
|
|
* Clearing this bit will force the STC cache to wait for pending
|
|
|
|
|
* retirement of pixels at the HZ-read stage and do the STC-test for
|
|
|
|
|
* Non-promoted, R-computed and Computed depth modes instead of
|
|
|
|
|
* postponing the STC-test to RCPFE.
|
|
|
|
|
*
|
|
|
|
|
* STC_TEST_EN = 3DSTATE_STENCIL_BUFFER::STENCIL_BUFFER_ENABLE &&
|
|
|
|
|
* 3DSTATE_WM_DEPTH_STENCIL::StencilTestEnable
|
|
|
|
|
*
|
|
|
|
|
* STC_WRITE_EN = 3DSTATE_STENCIL_BUFFER::STENCIL_BUFFER_ENABLE &&
|
|
|
|
|
* (3DSTATE_WM_DEPTH_STENCIL::Stencil Buffer Write Enable &&
|
|
|
|
|
* 3DSTATE_DEPTH_BUFFER::STENCIL_WRITE_ENABLE)
|
|
|
|
|
*
|
|
|
|
|
* COMP_STC_EN = STC_TEST_EN &&
|
|
|
|
|
* 3DSTATE_PS_EXTRA::PixelShaderComputesStencil
|
|
|
|
|
*
|
|
|
|
|
* SW parses the pipeline states to generate the following logical
|
|
|
|
|
* signal indicating if PMA FIX can be enabled.
|
|
|
|
|
*
|
|
|
|
|
* STC_PMA_OPT =
|
|
|
|
|
* 3DSTATE_WM::ForceThreadDispatch != 1 &&
|
|
|
|
|
* !(3DSTATE_RASTER::ForceSampleCount != NUMRASTSAMPLES_0) &&
|
|
|
|
|
* 3DSTATE_DEPTH_BUFFER::SURFACE_TYPE != NULL &&
|
|
|
|
|
* 3DSTATE_DEPTH_BUFFER::HIZ Enable &&
|
|
|
|
|
* !(3DSTATE_WM::EDSC_Mode == 2) &&
|
|
|
|
|
* 3DSTATE_PS_EXTRA::PixelShaderValid &&
|
|
|
|
|
* !(3DSTATE_WM_HZ_OP::DepthBufferClear ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::DepthBufferResolve ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::Hierarchical Depth Buffer Resolve Enable ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::StencilBufferClear) &&
|
|
|
|
|
* (COMP_STC_EN || STC_WRITE_EN) &&
|
|
|
|
|
* ((3DSTATE_PS_EXTRA::PixelShaderKillsPixels ||
|
|
|
|
|
* 3DSTATE_WM::ForceKillPix == ON ||
|
|
|
|
|
* 3DSTATE_PS_EXTRA::oMask Present to RenderTarget ||
|
|
|
|
|
* 3DSTATE_PS_BLEND::AlphaToCoverageEnable ||
|
|
|
|
|
* 3DSTATE_PS_BLEND::AlphaTestEnable ||
|
|
|
|
|
* 3DSTATE_WM_CHROMAKEY::ChromaKeyKillEnable) ||
|
|
|
|
|
* (3DSTATE_PS_EXTRA::Pixel Shader Computed Depth mode != PSCDEPTH_OFF))
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* These are always true:
|
|
|
|
|
* 3DSTATE_WM::ForceThreadDispatch != 1 &&
|
|
|
|
|
* !(3DSTATE_RASTER::ForceSampleCount != NUMRASTSAMPLES_0)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* We only enable the PMA fix if we know for certain that HiZ is enabled.
|
|
|
|
|
* If we don't know whether HiZ is enabled or not, we disable the PMA fix
|
|
|
|
|
* and there is no harm.
|
|
|
|
|
*
|
|
|
|
|
* (3DSTATE_DEPTH_BUFFER::SURFACE_TYPE != NULL) &&
|
|
|
|
|
* 3DSTATE_DEPTH_BUFFER::HIZ Enable
|
|
|
|
|
*/
|
|
|
|
|
if (!cmd_buffer->state.hiz_enabled)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* We can't possibly know if HiZ is enabled without the framebuffer */
|
|
|
|
|
assert(cmd_buffer->state.framebuffer);
|
|
|
|
|
|
|
|
|
|
/* HiZ is enabled so we had better have a depth buffer with HiZ */
|
|
|
|
|
const struct anv_image_view *ds_iview =
|
|
|
|
|
anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
|
2017-07-19 12:14:19 +01:00
|
|
|
assert(ds_iview && ds_iview->image->planes[0].aux_usage == ISL_AUX_USAGE_HIZ);
|
2017-02-01 16:41:04 -08:00
|
|
|
|
|
|
|
|
/* 3DSTATE_PS_EXTRA::PixelShaderValid */
|
2020-03-03 15:31:50 -08:00
|
|
|
struct anv_graphics_pipeline *pipeline = cmd_buffer->state.gfx.pipeline;
|
2017-02-01 16:41:04 -08:00
|
|
|
if (!anv_pipeline_has_stage(pipeline, MESA_SHADER_FRAGMENT))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* !(3DSTATE_WM::EDSC_Mode == 2) */
|
|
|
|
|
const struct brw_wm_prog_data *wm_prog_data = get_wm_prog_data(pipeline);
|
|
|
|
|
if (wm_prog_data->early_fragment_tests)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* We never use anv_pipeline for HiZ ops so this is trivially true:
|
|
|
|
|
* !(3DSTATE_WM_HZ_OP::DepthBufferClear ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::DepthBufferResolve ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::Hierarchical Depth Buffer Resolve Enable ||
|
|
|
|
|
* 3DSTATE_WM_HZ_OP::StencilBufferClear)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* 3DSTATE_STENCIL_BUFFER::STENCIL_BUFFER_ENABLE &&
|
|
|
|
|
* 3DSTATE_WM_DEPTH_STENCIL::StencilTestEnable
|
|
|
|
|
*/
|
|
|
|
|
const bool stc_test_en =
|
|
|
|
|
(ds_iview->image->aspects & VK_IMAGE_ASPECT_STENCIL_BIT) &&
|
|
|
|
|
pipeline->stencil_test_enable;
|
|
|
|
|
|
|
|
|
|
/* 3DSTATE_STENCIL_BUFFER::STENCIL_BUFFER_ENABLE &&
|
|
|
|
|
* (3DSTATE_WM_DEPTH_STENCIL::Stencil Buffer Write Enable &&
|
|
|
|
|
* 3DSTATE_DEPTH_BUFFER::STENCIL_WRITE_ENABLE)
|
|
|
|
|
*/
|
|
|
|
|
const bool stc_write_en =
|
|
|
|
|
(ds_iview->image->aspects & VK_IMAGE_ASPECT_STENCIL_BIT) &&
|
2019-07-15 17:14:26 -05:00
|
|
|
(cmd_buffer->state.gfx.dynamic.stencil_write_mask.front ||
|
|
|
|
|
cmd_buffer->state.gfx.dynamic.stencil_write_mask.back) &&
|
2017-02-01 16:41:04 -08:00
|
|
|
pipeline->writes_stencil;
|
|
|
|
|
|
|
|
|
|
/* STC_TEST_EN && 3DSTATE_PS_EXTRA::PixelShaderComputesStencil */
|
|
|
|
|
const bool comp_stc_en = stc_test_en && wm_prog_data->computed_stencil;
|
|
|
|
|
|
|
|
|
|
/* COMP_STC_EN || STC_WRITE_EN */
|
|
|
|
|
if (!(comp_stc_en || stc_write_en))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* (3DSTATE_PS_EXTRA::PixelShaderKillsPixels ||
|
|
|
|
|
* 3DSTATE_WM::ForceKillPix == ON ||
|
|
|
|
|
* 3DSTATE_PS_EXTRA::oMask Present to RenderTarget ||
|
|
|
|
|
* 3DSTATE_PS_BLEND::AlphaToCoverageEnable ||
|
|
|
|
|
* 3DSTATE_PS_BLEND::AlphaTestEnable ||
|
|
|
|
|
* 3DSTATE_WM_CHROMAKEY::ChromaKeyKillEnable) ||
|
|
|
|
|
* (3DSTATE_PS_EXTRA::Pixel Shader Computed Depth mode != PSCDEPTH_OFF)
|
|
|
|
|
*/
|
|
|
|
|
return pipeline->kill_pixel ||
|
|
|
|
|
wm_prog_data->computed_depth_mode != PSCDEPTH_OFF;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 16:54:07 -08:00
|
|
|
void
|
|
|
|
|
genX(cmd_buffer_flush_dynamic_state)(struct anv_cmd_buffer *cmd_buffer)
|
|
|
|
|
{
|
2020-03-03 15:31:50 -08:00
|
|
|
struct anv_graphics_pipeline *pipeline = cmd_buffer->state.gfx.pipeline;
|
2017-12-15 16:48:53 -08:00
|
|
|
struct anv_dynamic_state *d = &cmd_buffer->state.gfx.dynamic;
|
2016-03-08 16:54:07 -08:00
|
|
|
|
2017-12-15 16:38:10 -08:00
|
|
|
if (cmd_buffer->state.gfx.dirty & (ANV_CMD_DIRTY_PIPELINE |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH)) {
|
2017-05-04 11:11:44 -07:00
|
|
|
uint32_t sf_dw[GENX(3DSTATE_SF_length)];
|
|
|
|
|
struct GENX(3DSTATE_SF) sf = {
|
|
|
|
|
GENX(3DSTATE_SF_header),
|
|
|
|
|
};
|
|
|
|
|
#if GEN_GEN == 8
|
|
|
|
|
if (cmd_buffer->device->info.is_cherryview) {
|
2017-12-15 16:47:56 -08:00
|
|
|
sf.CHVLineWidth = d->line_width;
|
2017-05-04 11:11:44 -07:00
|
|
|
} else {
|
2017-12-15 16:47:56 -08:00
|
|
|
sf.LineWidth = d->line_width;
|
2017-05-04 11:11:44 -07:00
|
|
|
}
|
|
|
|
|
#else
|
2017-12-15 16:47:56 -08:00
|
|
|
sf.LineWidth = d->line_width,
|
2017-05-04 11:11:44 -07:00
|
|
|
#endif
|
|
|
|
|
GENX(3DSTATE_SF_pack)(NULL, sf_dw, &sf);
|
2017-12-15 09:32:29 -08:00
|
|
|
anv_batch_emit_merge(&cmd_buffer->batch, sf_dw, pipeline->gen8.sf);
|
2015-08-17 16:17:07 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-29 10:20:18 +03:00
|
|
|
static const uint32_t vk_to_gen_cullmode[] = {
|
|
|
|
|
[VK_CULL_MODE_NONE] = CULLMODE_NONE,
|
|
|
|
|
[VK_CULL_MODE_FRONT_BIT] = CULLMODE_FRONT,
|
|
|
|
|
[VK_CULL_MODE_BACK_BIT] = CULLMODE_BACK,
|
|
|
|
|
[VK_CULL_MODE_FRONT_AND_BACK] = CULLMODE_BOTH
|
|
|
|
|
};
|
|
|
|
|
static const uint32_t vk_to_gen_front_face[] = {
|
|
|
|
|
[VK_FRONT_FACE_COUNTER_CLOCKWISE] = 1,
|
|
|
|
|
[VK_FRONT_FACE_CLOCKWISE] = 0
|
|
|
|
|
};
|
2020-06-16 08:37:26 +03:00
|
|
|
static const uint32_t vk_to_gen_primitive_type[] = {
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_POINT_LIST] = _3DPRIM_POINTLIST,
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_LINE_LIST] = _3DPRIM_LINELIST,
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_LINE_STRIP] = _3DPRIM_LINESTRIP,
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST] = _3DPRIM_TRILIST,
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP] = _3DPRIM_TRISTRIP,
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN] = _3DPRIM_TRIFAN,
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY] = _3DPRIM_LINELIST_ADJ,
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY] = _3DPRIM_LINESTRIP_ADJ,
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY] = _3DPRIM_TRILIST_ADJ,
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY] = _3DPRIM_TRISTRIP_ADJ,
|
|
|
|
|
};
|
2020-05-29 10:20:18 +03:00
|
|
|
|
2020-06-01 12:28:30 +03:00
|
|
|
static const uint32_t vk_to_gen_compare_op[] = {
|
|
|
|
|
[VK_COMPARE_OP_NEVER] = PREFILTEROPNEVER,
|
|
|
|
|
[VK_COMPARE_OP_LESS] = PREFILTEROPLESS,
|
|
|
|
|
[VK_COMPARE_OP_EQUAL] = PREFILTEROPEQUAL,
|
|
|
|
|
[VK_COMPARE_OP_LESS_OR_EQUAL] = PREFILTEROPLEQUAL,
|
|
|
|
|
[VK_COMPARE_OP_GREATER] = PREFILTEROPGREATER,
|
|
|
|
|
[VK_COMPARE_OP_NOT_EQUAL] = PREFILTEROPNOTEQUAL,
|
|
|
|
|
[VK_COMPARE_OP_GREATER_OR_EQUAL] = PREFILTEROPGEQUAL,
|
|
|
|
|
[VK_COMPARE_OP_ALWAYS] = PREFILTEROPALWAYS,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const uint32_t vk_to_gen_stencil_op[] = {
|
|
|
|
|
[VK_STENCIL_OP_KEEP] = STENCILOP_KEEP,
|
|
|
|
|
[VK_STENCIL_OP_ZERO] = STENCILOP_ZERO,
|
|
|
|
|
[VK_STENCIL_OP_REPLACE] = STENCILOP_REPLACE,
|
|
|
|
|
[VK_STENCIL_OP_INCREMENT_AND_CLAMP] = STENCILOP_INCRSAT,
|
|
|
|
|
[VK_STENCIL_OP_DECREMENT_AND_CLAMP] = STENCILOP_DECRSAT,
|
|
|
|
|
[VK_STENCIL_OP_INVERT] = STENCILOP_INVERT,
|
|
|
|
|
[VK_STENCIL_OP_INCREMENT_AND_WRAP] = STENCILOP_INCR,
|
|
|
|
|
[VK_STENCIL_OP_DECREMENT_AND_WRAP] = STENCILOP_DECR,
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-15 16:38:10 -08:00
|
|
|
if (cmd_buffer->state.gfx.dirty & (ANV_CMD_DIRTY_PIPELINE |
|
2020-05-29 10:20:18 +03:00
|
|
|
ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_CULL_MODE |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_FRONT_FACE)) {
|
2015-11-25 22:27:01 -08:00
|
|
|
uint32_t raster_dw[GENX(3DSTATE_RASTER_length)];
|
|
|
|
|
struct GENX(3DSTATE_RASTER) raster = {
|
|
|
|
|
GENX(3DSTATE_RASTER_header),
|
2017-12-15 16:47:56 -08:00
|
|
|
.GlobalDepthOffsetConstant = d->depth_bias.bias,
|
|
|
|
|
.GlobalDepthOffsetScale = d->depth_bias.slope,
|
2020-05-29 10:20:18 +03:00
|
|
|
.GlobalDepthOffsetClamp = d->depth_bias.clamp,
|
|
|
|
|
.CullMode = vk_to_gen_cullmode[d->cull_mode],
|
|
|
|
|
.FrontWinding = vk_to_gen_front_face[d->front_face],
|
2015-10-06 17:21:44 -07:00
|
|
|
};
|
2015-11-25 22:27:01 -08:00
|
|
|
GENX(3DSTATE_RASTER_pack)(NULL, raster_dw, &raster);
|
2015-10-06 17:21:44 -07:00
|
|
|
anv_batch_emit_merge(&cmd_buffer->batch, raster_dw,
|
|
|
|
|
pipeline->gen8.raster);
|
2015-08-17 16:17:07 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-26 10:11:52 -08:00
|
|
|
/* Stencil reference values moved from COLOR_CALC_STATE in gen8 to
|
2015-11-25 22:27:01 -08:00
|
|
|
* 3DSTATE_WM_DEPTH_STENCIL in gen9. That means the dirty bits gets split
|
|
|
|
|
* across different state packets for gen8 and gen9. We handle that by
|
|
|
|
|
* using a big old #if switch here.
|
|
|
|
|
*/
|
2016-02-20 09:08:27 -08:00
|
|
|
#if GEN_GEN == 8
|
2017-12-15 16:38:10 -08:00
|
|
|
if (cmd_buffer->state.gfx.dirty & (ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE)) {
|
2015-10-06 17:21:44 -07:00
|
|
|
struct anv_state cc_state =
|
|
|
|
|
anv_cmd_buffer_alloc_dynamic_state(cmd_buffer,
|
2016-02-20 09:08:27 -08:00
|
|
|
GENX(COLOR_CALC_STATE_length) * 4,
|
2015-12-30 10:37:50 -08:00
|
|
|
64);
|
2016-02-20 09:08:27 -08:00
|
|
|
struct GENX(COLOR_CALC_STATE) cc = {
|
2017-12-15 16:47:56 -08:00
|
|
|
.BlendConstantColorRed = d->blend_constants[0],
|
|
|
|
|
.BlendConstantColorGreen = d->blend_constants[1],
|
|
|
|
|
.BlendConstantColorBlue = d->blend_constants[2],
|
|
|
|
|
.BlendConstantColorAlpha = d->blend_constants[3],
|
2016-03-04 12:22:32 -08:00
|
|
|
.StencilReferenceValue = d->stencil_reference.front & 0xff,
|
2017-04-19 16:13:20 -07:00
|
|
|
.BackfaceStencilReferenceValue = d->stencil_reference.back & 0xff,
|
2015-10-06 17:21:44 -07:00
|
|
|
};
|
2016-02-20 09:08:27 -08:00
|
|
|
GENX(COLOR_CALC_STATE_pack)(NULL, cc_state.map, &cc);
|
2015-08-17 16:17:07 -07:00
|
|
|
|
2016-04-18 17:03:00 -07:00
|
|
|
anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_CC_STATE_POINTERS), ccp) {
|
2016-04-18 16:08:49 -07:00
|
|
|
ccp.ColorCalcStatePointer = cc_state.offset;
|
|
|
|
|
ccp.ColorCalcStatePointerValid = true;
|
|
|
|
|
}
|
2015-08-17 16:17:07 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-15 16:38:10 -08:00
|
|
|
if (cmd_buffer->state.gfx.dirty & (ANV_CMD_DIRTY_PIPELINE |
|
|
|
|
|
ANV_CMD_DIRTY_RENDER_TARGETS |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK |
|
2020-06-01 12:28:30 +03:00
|
|
|
ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_DEPTH_TEST_ENABLE |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_DEPTH_WRITE_ENABLE |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_DEPTH_COMPARE_OP |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_STENCIL_TEST_ENABLE |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP)) {
|
2016-02-20 09:08:27 -08:00
|
|
|
uint32_t wm_depth_stencil_dw[GENX(3DSTATE_WM_DEPTH_STENCIL_length)];
|
2015-10-06 17:21:44 -07:00
|
|
|
|
2016-02-20 09:08:27 -08:00
|
|
|
struct GENX(3DSTATE_WM_DEPTH_STENCIL wm_depth_stencil) = {
|
|
|
|
|
GENX(3DSTATE_WM_DEPTH_STENCIL_header),
|
2015-10-06 17:21:44 -07:00
|
|
|
|
2016-03-01 10:56:46 -08:00
|
|
|
.StencilTestMask = d->stencil_compare_mask.front & 0xff,
|
|
|
|
|
.StencilWriteMask = d->stencil_write_mask.front & 0xff,
|
|
|
|
|
|
|
|
|
|
.BackfaceStencilTestMask = d->stencil_compare_mask.back & 0xff,
|
|
|
|
|
.BackfaceStencilWriteMask = d->stencil_write_mask.back & 0xff,
|
2016-12-07 20:31:12 -08:00
|
|
|
|
|
|
|
|
.StencilBufferWriteEnable =
|
|
|
|
|
(d->stencil_write_mask.front || d->stencil_write_mask.back) &&
|
2020-06-01 12:28:30 +03:00
|
|
|
d->stencil_test_enable,
|
|
|
|
|
|
|
|
|
|
.DepthTestEnable = d->depth_test_enable,
|
|
|
|
|
.DepthBufferWriteEnable = d->depth_test_enable && d->depth_write_enable,
|
|
|
|
|
.DepthTestFunction = vk_to_gen_compare_op[d->depth_compare_op],
|
|
|
|
|
.StencilTestEnable = d->stencil_test_enable,
|
|
|
|
|
.StencilFailOp = vk_to_gen_stencil_op[d->stencil_op.front.fail_op],
|
|
|
|
|
.StencilPassDepthPassOp = vk_to_gen_stencil_op[d->stencil_op.front.pass_op],
|
|
|
|
|
.StencilPassDepthFailOp = vk_to_gen_stencil_op[d->stencil_op.front.depth_fail_op],
|
|
|
|
|
.StencilTestFunction = vk_to_gen_compare_op[d->stencil_op.front.compare_op],
|
|
|
|
|
.BackfaceStencilFailOp = vk_to_gen_stencil_op[d->stencil_op.back.fail_op],
|
|
|
|
|
.BackfaceStencilPassDepthPassOp = vk_to_gen_stencil_op[d->stencil_op.back.pass_op],
|
|
|
|
|
.BackfaceStencilPassDepthFailOp = vk_to_gen_stencil_op[d->stencil_op.back.depth_fail_op],
|
|
|
|
|
.BackfaceStencilTestFunction = vk_to_gen_compare_op[d->stencil_op.back.compare_op],
|
2015-10-06 17:21:44 -07:00
|
|
|
};
|
2016-02-20 09:08:27 -08:00
|
|
|
GENX(3DSTATE_WM_DEPTH_STENCIL_pack)(NULL, wm_depth_stencil_dw,
|
|
|
|
|
&wm_depth_stencil);
|
2015-10-06 17:21:44 -07:00
|
|
|
|
|
|
|
|
anv_batch_emit_merge(&cmd_buffer->batch, wm_depth_stencil_dw,
|
|
|
|
|
pipeline->gen8.wm_depth_stencil);
|
2016-12-06 17:52:14 -08:00
|
|
|
|
|
|
|
|
genX(cmd_buffer_enable_pma_fix)(cmd_buffer,
|
|
|
|
|
want_depth_pma_fix(cmd_buffer));
|
2015-10-06 17:21:44 -07:00
|
|
|
}
|
2015-11-25 22:27:01 -08:00
|
|
|
#else
|
2017-12-15 16:38:10 -08:00
|
|
|
if (cmd_buffer->state.gfx.dirty & ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS) {
|
2015-11-25 22:27:01 -08:00
|
|
|
struct anv_state cc_state =
|
|
|
|
|
anv_cmd_buffer_alloc_dynamic_state(cmd_buffer,
|
2017-05-26 09:10:35 -07:00
|
|
|
GENX(COLOR_CALC_STATE_length) * 4,
|
2015-12-30 10:37:50 -08:00
|
|
|
64);
|
2017-05-26 09:10:35 -07:00
|
|
|
struct GENX(COLOR_CALC_STATE) cc = {
|
2017-12-15 16:47:56 -08:00
|
|
|
.BlendConstantColorRed = d->blend_constants[0],
|
|
|
|
|
.BlendConstantColorGreen = d->blend_constants[1],
|
|
|
|
|
.BlendConstantColorBlue = d->blend_constants[2],
|
|
|
|
|
.BlendConstantColorAlpha = d->blend_constants[3],
|
2015-11-25 22:27:01 -08:00
|
|
|
};
|
2017-05-26 09:10:35 -07:00
|
|
|
GENX(COLOR_CALC_STATE_pack)(NULL, cc_state.map, &cc);
|
2015-11-25 22:27:01 -08:00
|
|
|
|
2017-05-26 09:10:35 -07:00
|
|
|
anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_CC_STATE_POINTERS), ccp) {
|
2016-04-18 16:08:49 -07:00
|
|
|
ccp.ColorCalcStatePointer = cc_state.offset;
|
|
|
|
|
ccp.ColorCalcStatePointerValid = true;
|
|
|
|
|
}
|
2015-11-25 22:27:01 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-15 16:38:10 -08:00
|
|
|
if (cmd_buffer->state.gfx.dirty & (ANV_CMD_DIRTY_PIPELINE |
|
|
|
|
|
ANV_CMD_DIRTY_RENDER_TARGETS |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK |
|
2020-06-01 12:28:30 +03:00
|
|
|
ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_DEPTH_TEST_ENABLE |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_DEPTH_WRITE_ENABLE |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_DEPTH_COMPARE_OP |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_STENCIL_TEST_ENABLE |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP)) {
|
2017-05-26 09:10:35 -07:00
|
|
|
uint32_t dwords[GENX(3DSTATE_WM_DEPTH_STENCIL_length)];
|
|
|
|
|
struct GENX(3DSTATE_WM_DEPTH_STENCIL) wm_depth_stencil = {
|
|
|
|
|
GENX(3DSTATE_WM_DEPTH_STENCIL_header),
|
2015-11-25 22:27:01 -08:00
|
|
|
|
|
|
|
|
.StencilTestMask = d->stencil_compare_mask.front & 0xff,
|
|
|
|
|
.StencilWriteMask = d->stencil_write_mask.front & 0xff,
|
|
|
|
|
|
|
|
|
|
.BackfaceStencilTestMask = d->stencil_compare_mask.back & 0xff,
|
|
|
|
|
.BackfaceStencilWriteMask = d->stencil_write_mask.back & 0xff,
|
|
|
|
|
|
2016-03-04 12:22:32 -08:00
|
|
|
.StencilReferenceValue = d->stencil_reference.front & 0xff,
|
|
|
|
|
.BackfaceStencilReferenceValue = d->stencil_reference.back & 0xff,
|
2016-12-07 20:31:12 -08:00
|
|
|
|
|
|
|
|
.StencilBufferWriteEnable =
|
|
|
|
|
(d->stencil_write_mask.front || d->stencil_write_mask.back) &&
|
2020-06-01 12:28:30 +03:00
|
|
|
d->stencil_test_enable,
|
|
|
|
|
|
|
|
|
|
.DepthTestEnable = d->depth_test_enable,
|
|
|
|
|
.DepthBufferWriteEnable = d->depth_test_enable && d->depth_write_enable,
|
|
|
|
|
.DepthTestFunction = vk_to_gen_compare_op[d->depth_compare_op],
|
|
|
|
|
.StencilTestEnable = d->stencil_test_enable,
|
|
|
|
|
.StencilFailOp = vk_to_gen_stencil_op[d->stencil_op.front.fail_op],
|
|
|
|
|
.StencilPassDepthPassOp = vk_to_gen_stencil_op[d->stencil_op.front.pass_op],
|
|
|
|
|
.StencilPassDepthFailOp = vk_to_gen_stencil_op[d->stencil_op.front.depth_fail_op],
|
|
|
|
|
.StencilTestFunction = vk_to_gen_compare_op[d->stencil_op.front.compare_op],
|
|
|
|
|
.BackfaceStencilFailOp = vk_to_gen_stencil_op[d->stencil_op.back.fail_op],
|
|
|
|
|
.BackfaceStencilPassDepthPassOp = vk_to_gen_stencil_op[d->stencil_op.back.pass_op],
|
|
|
|
|
.BackfaceStencilPassDepthFailOp =vk_to_gen_stencil_op[d->stencil_op.back.depth_fail_op],
|
|
|
|
|
.BackfaceStencilTestFunction = vk_to_gen_compare_op[d->stencil_op.back.compare_op],
|
|
|
|
|
|
2015-11-25 22:27:01 -08:00
|
|
|
};
|
2017-05-26 09:10:35 -07:00
|
|
|
GENX(3DSTATE_WM_DEPTH_STENCIL_pack)(NULL, dwords, &wm_depth_stencil);
|
2015-11-25 22:27:01 -08:00
|
|
|
|
|
|
|
|
anv_batch_emit_merge(&cmd_buffer->batch, dwords,
|
2015-11-26 10:11:52 -08:00
|
|
|
pipeline->gen9.wm_depth_stencil);
|
2017-02-01 16:41:04 -08:00
|
|
|
|
|
|
|
|
genX(cmd_buffer_enable_pma_fix)(cmd_buffer,
|
|
|
|
|
want_stencil_pma_fix(cmd_buffer));
|
2015-11-25 22:27:01 -08:00
|
|
|
}
|
|
|
|
|
#endif
|
2015-10-06 17:21:44 -07:00
|
|
|
|
2019-10-24 21:05:11 +01:00
|
|
|
#if GEN_GEN >= 12
|
|
|
|
|
if(cmd_buffer->state.gfx.dirty & (ANV_CMD_DIRTY_PIPELINE |
|
2020-06-01 12:28:30 +03:00
|
|
|
ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS_TEST_ENABLE)) {
|
2019-10-24 21:05:11 +01:00
|
|
|
anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_DEPTH_BOUNDS), db) {
|
|
|
|
|
db.DepthBoundsTestValueModifyDisable = false;
|
|
|
|
|
db.DepthBoundsTestEnableModifyDisable = false;
|
2020-06-01 12:28:30 +03:00
|
|
|
db.DepthBoundsTestEnable = d->depth_bounds_test_enable;
|
2019-10-24 21:05:11 +01:00
|
|
|
db.DepthBoundsTestMinValue = d->depth_bounds.min;
|
|
|
|
|
db.DepthBoundsTestMaxValue = d->depth_bounds.max;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-05-22 22:44:59 -05:00
|
|
|
if (cmd_buffer->state.gfx.dirty & ANV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE) {
|
|
|
|
|
anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_LINE_STIPPLE), ls) {
|
|
|
|
|
ls.LineStipplePattern = d->line_stipple.pattern;
|
|
|
|
|
ls.LineStippleInverseRepeatCount =
|
|
|
|
|
1.0f / MAX2(1, d->line_stipple.factor);
|
|
|
|
|
ls.LineStippleRepeatCount = d->line_stipple.factor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 16:38:10 -08:00
|
|
|
if (cmd_buffer->state.gfx.dirty & (ANV_CMD_DIRTY_PIPELINE |
|
|
|
|
|
ANV_CMD_DIRTY_INDEX_BUFFER)) {
|
2016-04-18 17:03:00 -07:00
|
|
|
anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_VF), vf) {
|
2016-04-18 16:08:49 -07:00
|
|
|
vf.IndexedDrawCutIndexEnable = pipeline->primitive_restart;
|
|
|
|
|
vf.CutIndex = cmd_buffer->state.restart_index;
|
|
|
|
|
}
|
2015-08-17 16:17:07 -07:00
|
|
|
}
|
|
|
|
|
|
2020-06-16 08:37:26 +03:00
|
|
|
if (cmd_buffer->state.gfx.dirty & (ANV_CMD_DIRTY_PIPELINE |
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_PRIMITIVE_TOPOLOGY)) {
|
|
|
|
|
uint32_t topology;
|
|
|
|
|
if (anv_pipeline_has_stage(pipeline, MESA_SHADER_TESS_EVAL))
|
|
|
|
|
topology = d->primitive_topology;
|
|
|
|
|
else
|
|
|
|
|
topology = vk_to_gen_primitive_type[d->primitive_topology];
|
|
|
|
|
|
|
|
|
|
cmd_buffer->state.gfx.primitive_topology = topology;
|
|
|
|
|
|
|
|
|
|
anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_VF_TOPOLOGY), vft) {
|
|
|
|
|
vft.PrimitiveTopologyType = topology;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 16:38:10 -08:00
|
|
|
cmd_buffer->state.gfx.dirty = 0;
|
2015-08-17 16:17:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-05-13 16:33:22 +01:00
|
|
|
static uint32_t vk_to_gen_index_type(VkIndexType type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case VK_INDEX_TYPE_UINT8_EXT:
|
|
|
|
|
return INDEX_BYTE;
|
|
|
|
|
case VK_INDEX_TYPE_UINT16:
|
|
|
|
|
return INDEX_WORD;
|
|
|
|
|
case VK_INDEX_TYPE_UINT32:
|
|
|
|
|
return INDEX_DWORD;
|
|
|
|
|
default:
|
|
|
|
|
unreachable("invalid index type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint32_t restart_index_for_type(VkIndexType type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case VK_INDEX_TYPE_UINT8_EXT:
|
|
|
|
|
return UINT8_MAX;
|
|
|
|
|
case VK_INDEX_TYPE_UINT16:
|
|
|
|
|
return UINT16_MAX;
|
|
|
|
|
case VK_INDEX_TYPE_UINT32:
|
|
|
|
|
return UINT32_MAX;
|
|
|
|
|
default:
|
|
|
|
|
unreachable("invalid index type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-25 22:27:01 -08:00
|
|
|
void genX(CmdBindIndexBuffer)(
|
2015-11-30 11:48:08 -08:00
|
|
|
VkCommandBuffer commandBuffer,
|
2015-08-17 16:17:07 -07:00
|
|
|
VkBuffer _buffer,
|
|
|
|
|
VkDeviceSize offset,
|
|
|
|
|
VkIndexType indexType)
|
|
|
|
|
{
|
2015-11-30 11:48:08 -08:00
|
|
|
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
2015-08-17 16:17:07 -07:00
|
|
|
ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
|
|
|
|
|
|
2019-05-13 16:33:22 +01:00
|
|
|
cmd_buffer->state.restart_index = restart_index_for_type(indexType);
|
2015-08-17 16:17:07 -07:00
|
|
|
|
2016-04-18 17:03:00 -07:00
|
|
|
anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_INDEX_BUFFER), ib) {
|
2019-05-13 16:33:22 +01:00
|
|
|
ib.IndexFormat = vk_to_gen_index_type(indexType);
|
genxml: Consistently use a numeric "MOCS" field
When we first started using genxml, we decided to represent MOCS as an
actual structure, and pack values. However, in many places, it was more
convenient to use a numeric value rather than treating it as a struct,
so we added secondary setters in a bunch of places as well.
We were not entirely consistent, either. Some places only had one.
Gen6 had both kinds of setters for STATE_BASE_ADDRESS, but newer gens
only had the struct-based setters. The names were sometimes "Constant
Buffer Object Control State" instead of "Memory", making it harder to
find. Many had prefixes like "Vertex Buffer MOCS"...in a vertex buffer
packet...which is a bit redundant.
On modern hardware, MOCS is simply an index into a table, but we were
still carrying around the structure with an "Index to MOCS Table" field,
in addition to the direct numeric setters. This is clunky - we really
just want a number on new hardware.
This patch eliminates the struct-based setters, and makes the numeric
setters be consistently called "MOCS". We leave the struct definition
around on Gen7-8 for reference purposes, but it is unused.
v2: Drop bonus "Depth Buffer MOCS" fields on Gen7.5 and Gen9
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
2018-12-11 00:34:11 -08:00
|
|
|
ib.MOCS = anv_mocs_for_bo(cmd_buffer->device,
|
2018-07-09 14:21:33 -07:00
|
|
|
buffer->address.bo);
|
2018-05-30 18:05:54 -07:00
|
|
|
ib.BufferStartingAddress = anv_address_add(buffer->address, offset);
|
2016-04-18 16:08:49 -07:00
|
|
|
ib.BufferSize = buffer->size - offset;
|
|
|
|
|
}
|
2015-11-16 16:29:33 -08:00
|
|
|
|
2017-12-15 16:38:10 -08:00
|
|
|
cmd_buffer->state.gfx.dirty |= ANV_CMD_DIRTY_INDEX_BUFFER;
|
2015-08-17 16:17:07 -07:00
|
|
|
}
|